From 96af6b56efe7344dce6a5b7f129c5f6d847c0590 Mon Sep 17 00:00:00 2001 From: lilia Date: Thu, 12 Feb 2015 18:16:33 -0800 Subject: [PATCH] Handle incoming sync messages Assign them to the correct conversation and mark them outgoing with the correct timestamp. Closes #150 --- js/background.js | 19 ++++++++++++++++++- stylesheets/_conversation.scss | 3 +++ stylesheets/manifest.css | 3 +++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/js/background.js b/js/background.js index edee04688c29..375ec35ff558 100644 --- a/js/background.js +++ b/js/background.js @@ -122,14 +122,29 @@ }); }); + function getConversationId(pushMessageContent) { + if (pushMessageContent.sync) { + return pushMessageContent.sync.destination; + } else if (pushMessageContent.group) { + return pushMessageContent.group.id; + } + } + function handlePushMessageContent(pushMessageContent, message) { // This function can be called from the background script on an // incoming message or from the frontend after the user accepts an // identity key change. var source = message.get('source'); + var timestamp = message.get('sent_at'); + var type = 'incoming'; + if (source === textsecure.storage.getUnencrypted("number_id").split('.')[0] && pushMessageContent.sync) { + type = 'outgoing'; + timestamp = pushMessageContent.sync.timestamp + } return textsecure.processDecrypted(pushMessageContent, source).then(function(pushMessageContent) { var now = new Date().getTime(); - var conversationId = pushMessageContent.group ? pushMessageContent.group.id : source; + + var conversationId = getConversationId(pushMessageContent) || source; var conversation = new Whisper.Conversation({id: conversationId}); var attributes = {}; conversation.fetch().always(function() { @@ -159,6 +174,8 @@ conversationId : conversation.id, attachments : pushMessageContent.attachments, decrypted_at : now, + type : type, + sent_at : timestamp, errors : [] }); diff --git a/stylesheets/_conversation.scss b/stylesheets/_conversation.scss index 14a364c325c4..ab693d9bcd9d 100644 --- a/stylesheets/_conversation.scss +++ b/stylesheets/_conversation.scss @@ -3,6 +3,9 @@ font-size: smaller; } +.outgoing .sender { + display: none; +} .sender { font-size: smaller; opacity: 0.8; diff --git a/stylesheets/manifest.css b/stylesheets/manifest.css index 6e0c824300ff..3030978ff638 100644 --- a/stylesheets/manifest.css +++ b/stylesheets/manifest.css @@ -254,6 +254,9 @@ input.new-message { .group-update { font-size: smaller; } +.outgoing .sender { + display: none; } + .sender { font-size: smaller; opacity: 0.8; }