From adf21985c13536677dc6c46c99860fbe0a044c07 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Fri, 2 Aug 2019 14:07:30 -0700 Subject: [PATCH] Use MessageController whenever we create a new Message --- js/models/conversations.js | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index 1e1c8f069..5c6783b17 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -613,14 +613,15 @@ const id = await window.Signal.Data.saveMessage(message, { Message: Whisper.Message, }); - - this.trigger( - 'newmessage', + const model = MessageController.register( + id, new Whisper.Message({ ...message, id, }) ); + + this.trigger('newmessage', model); }, async addVerifiedChange(verifiedChangeId, verified, providedOptions) { const options = providedOptions || {}; @@ -657,15 +658,16 @@ const id = await window.Signal.Data.saveMessage(message, { Message: Whisper.Message, }); - - this.trigger( - 'newmessage', + const model = MessageController.register( + id, new Whisper.Message({ ...message, id, }) ); + this.trigger('newmessage', model); + if (this.isPrivate()) { ConversationController.getAllGroupsInvolvingId(this.id).then(groups => { _.forEach(groups, group => { @@ -1278,7 +1280,7 @@ Conversation: Whisper.Conversation, }); - const message = this.messageCollection.add({ + const model = new Whisper.Message({ // Even though this isn't reflected to the user, we want to place the last seen // indicator above it. We set it to 'unread' to trigger that placement. unread: 1, @@ -1294,17 +1296,21 @@ fromGroupUpdate: options.fromGroupUpdate, }, }); - if (this.isPrivate()) { - message.set({ destination: this.id }); - } - if (message.isOutgoing()) { - message.set({ recipients: this.getRecipients() }); - } - const id = await window.Signal.Data.saveMessage(message.attributes, { + if (this.isPrivate()) { + model.set({ destination: this.id }); + } + if (model.isOutgoing()) { + model.set({ recipients: this.getRecipients() }); + } + const id = await window.Signal.Data.saveMessage(model.attributes, { Message: Whisper.Message, }); - message.set({ id }); + + model.set({ id }); + + const message = MessageController.register(id, model); + this.messageCollection.add(message); // if change was made remotely, don't send it to the number/group if (receivedAt) {