From 6253269d19c4541cd5803191a7c076bff8fa5714 Mon Sep 17 00:00:00 2001 From: lilia Date: Sun, 22 Jan 2017 20:26:10 -0800 Subject: [PATCH] Tweak key change advisory insertion Let received_at be the current time for keychanges. This avoids them being inserted in the wrong place in the thread. Use the newmessage event to trigger frontend listeners to add them to the conversation view if it is open. --- js/models/conversations.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index 16b0f74b..7e70b4f5 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -51,14 +51,16 @@ }, addKeyChange: function(id) { - var message = this.messageCollection.add({ + var timestamp = Date.now(); + var message = new Whisper.Message({ conversationId : this.id, type : 'keychange', sent_at : this.get('timestamp'), - received_at : this.get('timestamp'), + received_at : timestamp, key_changed : id }); - message.save(); + this.set({ lastMessage: message.getNotificationText() }); + message.save().then(this.trigger.bind(this,'newmessage', message)); }, onReadMessage: function(message) {