From fca67d7b0e2f44c279fa0f6c24be9e815876c458 Mon Sep 17 00:00:00 2001 From: lilia Date: Wed, 24 Dec 2014 15:03:03 -0800 Subject: [PATCH] Simplify pushMessageContent handler slightly New private conversations have their type set in onMessageReceived. New group conversations should be handled the same way as normal group updates. It was pointed out we should never have to handle a group message without a preceding group update, as those would be rejected by textsecure.processDecrypted. An exception would be if you delete the group from indexedDB but not localStorage, but that's not a mode we should be supporting. Also in this change I switched to instantiating a new conversation object on every call to handlePushMessageContent. Originally, I thought to use the local conversation list as a cache, but it's a bit simpler to re-read from the database every time for now. Later on we should revisit and optimize for fewer read/writes per incoming message. --- js/background.js | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/js/background.js b/js/background.js index ecccb3d7..51d9b868 100644 --- a/js/background.js +++ b/js/background.js @@ -127,27 +127,13 @@ return textsecure.processDecrypted(pushMessageContent, source).then(function(pushMessageContent) { var now = new Date().getTime(); var conversationId = pushMessageContent.group ? pushMessageContent.group.id : source; - var conversation = conversations.add({id: conversationId}, {merge: true}); + var conversation = new Whisper.Conversation({id: conversationId}); var attributes = {}; - conversation.fetch().fail(function() { - // this is a new conversation - if (pushMessageContent.group) { - attributes = { - type : 'group', - groupId : pushMessageContent.group.id, - name : pushMessageContent.group.name || '', - avatar : pushMessageContent.group.avatar, - members : pushMessageContent.group.members, - }; - } else { - attributes = { - type : 'private' - }; - } - }).always(function() { + conversation.fetch().always(function() { if (pushMessageContent.group && pushMessageContent.group.type === textsecure.protobuf.PushMessageContent.GroupContext.Type.UPDATE) { attributes = { + type : 'group', groupId : pushMessageContent.group.id, name : pushMessageContent.group.name, avatar : pushMessageContent.group.avatar,