[NEW] Draft message per room (#772)

This commit is contained in:
pranavpandey1998official 2019-04-01 20:15:17 +05:30 committed by Diego Mello
parent 9e107bfdf6
commit 46a36d7764
2 changed files with 19 additions and 2 deletions

View File

@ -108,6 +108,14 @@ export default class MessageBox extends Component {
this.text = '';
}
componentDidMount() {
const { rid } = this.props;
const [room] = database.objects('subscriptions').filtered('rid = $0', rid);
if (room.draftMessage && room.draftMessage !== '') {
this.setInput(room.draftMessage);
}
}
componentWillReceiveProps(nextProps) {
const { message, replyMessage } = this.props;
if (message !== nextProps.message && nextProps.message.msg) {
@ -157,6 +165,14 @@ export default class MessageBox extends Component {
return false;
}
componentWillUnmount() {
const { rid } = this.props;
const [room] = database.objects('subscriptions').filtered('rid = $0', rid);
database.write(() => {
room.draftMessage = this.text;
});
}
onChangeText = (text) => {
const isTextEmpty = text.length === 0;
this.setShowSend(!isTextEmpty);

View File

@ -101,7 +101,8 @@ const subscriptionSchema = {
joinCodeRequired: { type: 'bool', optional: true },
notifications: { type: 'bool', optional: true },
muted: { type: 'list', objectType: 'usersMuted' },
broadcast: { type: 'bool', optional: true }
broadcast: { type: 'bool', optional: true },
draftMessage: { type: 'string', optional: true }
}
};
@ -341,7 +342,7 @@ class DB {
return this.databases.activeDB = new Realm({
path: `${ path }.realm`,
schema,
schemaVersion: 1
schemaVersion: 2
});
}
}