Refactor media uploading step

Move this to its own function which encapsulates the error handling for
it.

// FREEBIE
pull/749/head
lilia 9 years ago
parent 44b1a6451d
commit c3bbdb393f

@ -37519,7 +37519,7 @@ Message.prototype = {
} }
var proto = new textsecure.protobuf.DataMessage(); var proto = new textsecure.protobuf.DataMessage();
proto.body = this.body; proto.body = this.body;
proto.attachments = this.attachments; proto.attachments = this.attachmentPointers;
if (this.flags) { if (this.flags) {
proto.flags = this.flags; proto.flags = this.flags;
} }
@ -37581,12 +37581,23 @@ MessageSender.prototype = {
}.bind(this)); }.bind(this));
}, },
sendMessage: function(attrs) { uploadMedia: function(message) {
var message = new Message(attrs);
return Promise.all( return Promise.all(
message.attachments.map(this.makeAttachmentPointer.bind(this)) message.attachments.map(this.makeAttachmentPointer.bind(this))
).then(function(attachmentPointers) { ).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) { return new Promise(function(resolve, reject) {
this.sendMessageProto( this.sendMessageProto(
message.timestamp, message.timestamp,
@ -37602,13 +37613,7 @@ MessageSender.prototype = {
} }
); );
}.bind(this)); }.bind(this));
}.bind(this)).catch(function(error) { }.bind(this));
if (error instanceof Error && error.name === 'HTTPError') {
throw new textsecure.MessageError(attrs, error);
} else {
throw error;
}
});
}, },
sendMessageProto: function(timestamp, numbers, message, callback) { sendMessageProto: function(timestamp, numbers, message, callback) {
var outgoing = new OutgoingMessage(this.server, timestamp, numbers, message, callback); var outgoing = new OutgoingMessage(this.server, timestamp, numbers, message, callback);

@ -62,7 +62,7 @@ Message.prototype = {
} }
var proto = new textsecure.protobuf.DataMessage(); var proto = new textsecure.protobuf.DataMessage();
proto.body = this.body; proto.body = this.body;
proto.attachments = this.attachments; proto.attachments = this.attachmentPointers;
if (this.flags) { if (this.flags) {
proto.flags = this.flags; proto.flags = this.flags;
} }
@ -124,12 +124,23 @@ MessageSender.prototype = {
}.bind(this)); }.bind(this));
}, },
sendMessage: function(attrs) { uploadMedia: function(message) {
var message = new Message(attrs);
return Promise.all( return Promise.all(
message.attachments.map(this.makeAttachmentPointer.bind(this)) message.attachments.map(this.makeAttachmentPointer.bind(this))
).then(function(attachmentPointers) { ).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) { return new Promise(function(resolve, reject) {
this.sendMessageProto( this.sendMessageProto(
message.timestamp, message.timestamp,
@ -145,13 +156,7 @@ MessageSender.prototype = {
} }
); );
}.bind(this)); }.bind(this));
}.bind(this)).catch(function(error) { }.bind(this));
if (error instanceof Error && error.name === 'HTTPError') {
throw new textsecure.MessageError(attrs, error);
} else {
throw error;
}
});
}, },
sendMessageProto: function(timestamp, numbers, message, callback) { sendMessageProto: function(timestamp, numbers, message, callback) {
var outgoing = new OutgoingMessage(this.server, timestamp, numbers, message, callback); var outgoing = new OutgoingMessage(this.server, timestamp, numbers, message, callback);

Loading…
Cancel
Save