From 46a36d7764ebc2e3d57c5cbc37fb04654ac01af5 Mon Sep 17 00:00:00 2001 From: pranavpandey1998official <44601530+pranavpandey1998official@users.noreply.github.com> Date: Mon, 1 Apr 2019 20:15:17 +0530 Subject: [PATCH] [NEW] Draft message per room (#772) --- app/containers/MessageBox/index.js | 16 ++++++++++++++++ app/lib/realm.js | 5 +++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/containers/MessageBox/index.js b/app/containers/MessageBox/index.js index 20f841fa..6cbf9b3e 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 947f10ba..5de570bc 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 }); } }