Refactor media uploading step

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

// FREEBIE
This commit is contained in:
lilia 2016-02-24 15:22:51 -08:00
parent 44b1a6451d
commit c3bbdb393f
2 changed files with 32 additions and 22 deletions

View file

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

View file

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