From 8fe00f79b22d962b81b847b9e6e3f6ccffc8e203 Mon Sep 17 00:00:00 2001 From: lilia Date: Fri, 25 Mar 2016 14:28:09 -0700 Subject: [PATCH] Fix sorting on incoming key conflicts // FREEBIE --- js/background.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/js/background.js b/js/background.js index 7da22cc3..3935900f 100644 --- a/js/background.js +++ b/js/background.js @@ -217,10 +217,17 @@ var message = initIncomingMessage(envelope.source, envelope.timestamp.toNumber()); message.saveErrors(e).then(function() { ConversationController.findOrCreatePrivateById(message.get('conversationId')).then(function(conversation) { - conversation.save({ + conversation.set({ active_at: Date.now(), unreadCount: conversation.get('unreadCount') + 1 }); + + var conversation_timestamp = conversation.get('timestamp'); + var message_timestamp = message.get('timestamp'); + if (!conversation_timestamp || message_timestamp > conversation_timestamp) { + conversation.set({ timestamp: message.get('sent_at') }); + } + conversation.save(); conversation.trigger('newmessage', message); conversation.notify(message); });