diff --git a/js/libtextsecure.js b/js/libtextsecure.js index e57db3cd..97c3785e 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -39168,10 +39168,15 @@ TextSecureServer = function () { }); }; - self.sendMessages = function(destination, messageArray) { + self.sendMessages = function(destination, messageArray, legacy) { //TODO: Do this conversion somewhere else? - for (var i = 0; i < messageArray.length; i++) - messageArray[i].body = btoa(messageArray[i].body); + for (var i = 0; i < messageArray.length; i++) { + messageArray[i].content = btoa(messageArray[i].content); + if (legacy) { + messageArray[i].body = messageArray[i].content; + delete messageArray[i].content; + } + } var jsonData = { messages: messageArray }; if (messageArray[0].relay !== undefined) jsonData.relay = messageArray[0].relay; @@ -39700,7 +39705,7 @@ window.textsecure.messaging = function() { type: encryptedMsg.type, destinationDeviceId: textsecure.utils.unencodeNumber(deviceObjectList[i].encodedNumber)[1], destinationRegistrationId: registrationId, - body: encryptedMsg.body, + content: encryptedMsg.body, timestamp: timestamp }; @@ -39714,7 +39719,8 @@ window.textsecure.messaging = function() { for (var i = 0; i < deviceObjectList.length; i++) promises[i] = addEncryptionFor(i); return Promise.all(promises).then(function() { - return TextSecureServer.sendMessages(number, jsonData); + var legacy = (message instanceof textsecure.protobuf.DataMessage); + return TextSecureServer.sendMessages(number, jsonData, legacy); }); } diff --git a/libtextsecure/api.js b/libtextsecure/api.js index eb1a8107..67c5dadc 100644 --- a/libtextsecure/api.js +++ b/libtextsecure/api.js @@ -248,10 +248,15 @@ TextSecureServer = function () { }); }; - self.sendMessages = function(destination, messageArray) { + self.sendMessages = function(destination, messageArray, legacy) { //TODO: Do this conversion somewhere else? - for (var i = 0; i < messageArray.length; i++) - messageArray[i].body = btoa(messageArray[i].body); + for (var i = 0; i < messageArray.length; i++) { + messageArray[i].content = btoa(messageArray[i].content); + if (legacy) { + messageArray[i].body = messageArray[i].content; + delete messageArray[i].content; + } + } var jsonData = { messages: messageArray }; if (messageArray[0].relay !== undefined) jsonData.relay = messageArray[0].relay; diff --git a/libtextsecure/sendmessage.js b/libtextsecure/sendmessage.js index 517a20dd..33459e18 100644 --- a/libtextsecure/sendmessage.js +++ b/libtextsecure/sendmessage.js @@ -74,7 +74,7 @@ window.textsecure.messaging = function() { type: encryptedMsg.type, destinationDeviceId: textsecure.utils.unencodeNumber(deviceObjectList[i].encodedNumber)[1], destinationRegistrationId: registrationId, - body: encryptedMsg.body, + content: encryptedMsg.body, timestamp: timestamp }; @@ -88,7 +88,8 @@ window.textsecure.messaging = function() { for (var i = 0; i < deviceObjectList.length; i++) promises[i] = addEncryptionFor(i); return Promise.all(promises).then(function() { - return TextSecureServer.sendMessages(number, jsonData); + var legacy = (message instanceof textsecure.protobuf.DataMessage); + return TextSecureServer.sendMessages(number, jsonData, legacy); }); }