From 40351fcc54bbcf8dbd9587e0f1249e1d5d010b89 Mon Sep 17 00:00:00 2001 From: lilia Date: Mon, 16 Feb 2015 13:51:27 -0800 Subject: [PATCH] Sync outgoing messages When sending an constrct a copy of the PushMessageContent protobuf, add a SyncMessageContext, and send it to ourselves. Do this for all kinds of group messages, and individual text/media messages, but not closeSession messages as the latter are device-specific. Do not sync messages if we are the primary device, which should only be supported in development. Normal web clients must be paired with a android or ios master device, and even in dev, a primary/standalone web client does not support linking additional devices. --- js/libtextsecure.js | 19 ++++++++++++++++++- libtextsecure/sendmessage.js | 19 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index 7a8a29a5729..5511b8e62ff 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -17102,6 +17102,19 @@ window.textsecure.messaging = function() { }); } + var sendSyncMessage = function(message, timestamp, destination) { + var numberDevice = textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id")); + var myNumber = numberDevice[0]; + var myDevice = numberDevice[1]; + if (myDevice != 1) { + var sync_message = textsecure.protobuf.PushMessageContent.decode(message.encode()); + sync_message.sync = new textsecure.protobuf.PushMessageContent.SyncMessageContext(); + sync_message.sync.destination = destination; + sync_message.sync.timestamp = timestamp; + return sendIndividualProto(myNumber, sync_message, Date.now()); + } + } + var sendGroupProto = function(numbers, proto, timestamp) { timestamp = timestamp || Date.now(); var me = textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0]; @@ -17114,6 +17127,8 @@ window.textsecure.messaging = function() { else resolve(); }); + }).then(function() { + return sendSyncMessage(proto, timestamp, getString(proto.group.id)); }); } @@ -17126,7 +17141,9 @@ window.textsecure.messaging = function() { promises.push(makeAttachmentPointer(attachments[i])); return Promise.all(promises).then(function(attachmentsArray) { proto.attachments = attachmentsArray; - return sendIndividualProto(number, proto, timestamp); + return sendIndividualProto(number, proto, timestamp).then(function() { + return sendSyncMessage(proto, timestamp, number); + }); }); } diff --git a/libtextsecure/sendmessage.js b/libtextsecure/sendmessage.js index 25838698546..c4628536e1c 100644 --- a/libtextsecure/sendmessage.js +++ b/libtextsecure/sendmessage.js @@ -261,6 +261,19 @@ window.textsecure.messaging = function() { }); } + var sendSyncMessage = function(message, timestamp, destination) { + var numberDevice = textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id")); + var myNumber = numberDevice[0]; + var myDevice = numberDevice[1]; + if (myDevice != 1) { + var sync_message = textsecure.protobuf.PushMessageContent.decode(message.encode()); + sync_message.sync = new textsecure.protobuf.PushMessageContent.SyncMessageContext(); + sync_message.sync.destination = destination; + sync_message.sync.timestamp = timestamp; + return sendIndividualProto(myNumber, sync_message, Date.now()); + } + } + var sendGroupProto = function(numbers, proto, timestamp) { timestamp = timestamp || Date.now(); var me = textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0]; @@ -273,6 +286,8 @@ window.textsecure.messaging = function() { else resolve(); }); + }).then(function() { + return sendSyncMessage(proto, timestamp, getString(proto.group.id)); }); } @@ -285,7 +300,9 @@ window.textsecure.messaging = function() { promises.push(makeAttachmentPointer(attachments[i])); return Promise.all(promises).then(function(attachmentsArray) { proto.attachments = attachmentsArray; - return sendIndividualProto(number, proto, timestamp); + return sendIndividualProto(number, proto, timestamp).then(function() { + return sendSyncMessage(proto, timestamp, number); + }); }); }