Merge pull request #167 from WhisperSystems/sync

Sync outgoing individual and group messages
This commit is contained in:
Matt Corallo 2015-02-20 12:39:26 -08:00
commit f2853d00e6
2 changed files with 36 additions and 2 deletions

View file

@ -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);
});
});
}

View file

@ -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);
});
});
}