diff --git a/js/libtextsecure.js b/js/libtextsecure.js index f7bac4656..1a5ffaa57 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -37519,7 +37519,7 @@ Message.prototype = { } var proto = new textsecure.protobuf.DataMessage(); proto.body = this.body; - proto.attachments = this.attachments; + proto.attachments = this.attachmentPointers; if (this.flags) { proto.flags = this.flags; } @@ -37581,12 +37581,23 @@ MessageSender.prototype = { }.bind(this)); }, - sendMessage: function(attrs) { - var message = new Message(attrs); + uploadMedia: function(message) { return Promise.all( message.attachments.map(this.makeAttachmentPointer.bind(this)) ).then(function(attachmentPointers) { - message.attachments = attachmentPointers; + message.attachmentPointers = attachmentPointers; + }).catch(function(error) { + if (error instanceof Error && error.name === 'HTTPError') { + throw new textsecure.MessageError(message, error); + } else { + throw error; + } + }); + }, + + sendMessage: function(attrs) { + var message = new Message(attrs); + return this.uploadMedia(message).then(function() { return new Promise(function(resolve, reject) { this.sendMessageProto( message.timestamp, @@ -37602,13 +37613,7 @@ MessageSender.prototype = { } ); }.bind(this)); - }.bind(this)).catch(function(error) { - if (error instanceof Error && error.name === 'HTTPError') { - throw new textsecure.MessageError(attrs, error); - } else { - throw error; - } - }); + }.bind(this)); }, sendMessageProto: function(timestamp, numbers, message, callback) { var outgoing = new OutgoingMessage(this.server, timestamp, numbers, message, callback); diff --git a/libtextsecure/sendmessage.js b/libtextsecure/sendmessage.js index f69f81e53..35b7a70aa 100644 --- a/libtextsecure/sendmessage.js +++ b/libtextsecure/sendmessage.js @@ -62,7 +62,7 @@ Message.prototype = { } var proto = new textsecure.protobuf.DataMessage(); proto.body = this.body; - proto.attachments = this.attachments; + proto.attachments = this.attachmentPointers; if (this.flags) { proto.flags = this.flags; } @@ -124,12 +124,23 @@ MessageSender.prototype = { }.bind(this)); }, - sendMessage: function(attrs) { - var message = new Message(attrs); + uploadMedia: function(message) { return Promise.all( message.attachments.map(this.makeAttachmentPointer.bind(this)) ).then(function(attachmentPointers) { - message.attachments = attachmentPointers; + message.attachmentPointers = attachmentPointers; + }).catch(function(error) { + if (error instanceof Error && error.name === 'HTTPError') { + throw new textsecure.MessageError(message, error); + } else { + throw error; + } + }); + }, + + sendMessage: function(attrs) { + var message = new Message(attrs); + return this.uploadMedia(message).then(function() { return new Promise(function(resolve, reject) { this.sendMessageProto( message.timestamp, @@ -145,13 +156,7 @@ MessageSender.prototype = { } ); }.bind(this)); - }.bind(this)).catch(function(error) { - if (error instanceof Error && error.name === 'HTTPError') { - throw new textsecure.MessageError(attrs, error); - } else { - throw error; - } - }); + }.bind(this)); }, sendMessageProto: function(timestamp, numbers, message, callback) { var outgoing = new OutgoingMessage(this.server, timestamp, numbers, message, callback);