diff --git a/app/containers/MessageBox/index.js b/app/containers/MessageBox/index.js index 20f841fa4..6cbf9b3e5 100644 --- a/app/containers/MessageBox/index.js +++ b/app/containers/MessageBox/index.js @@ -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); diff --git a/app/lib/realm.js b/app/lib/realm.js index 947f10baf..5de570bc7 100644 --- a/app/lib/realm.js +++ b/app/lib/realm.js @@ -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 }); } }