Full pipeline to send quotes, including thumbnail upload
This commit is contained in:
parent
13ce056830
commit
73edabfb17
3 changed files with 63 additions and 7 deletions
|
@ -663,7 +663,7 @@
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
sendMessage(body, attachments) {
|
sendMessage(body, attachments, quote) {
|
||||||
this.queueJob(async () => {
|
this.queueJob(async () => {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
||||||
|
@ -678,6 +678,7 @@
|
||||||
type: 'outgoing',
|
type: 'outgoing',
|
||||||
body,
|
body,
|
||||||
conversationId: this.id,
|
conversationId: this.id,
|
||||||
|
quote,
|
||||||
attachments,
|
attachments,
|
||||||
sent_at: now,
|
sent_at: now,
|
||||||
received_at: now,
|
received_at: now,
|
||||||
|
@ -719,6 +720,7 @@
|
||||||
this.get('id'),
|
this.get('id'),
|
||||||
body,
|
body,
|
||||||
attachmentsWithData,
|
attachmentsWithData,
|
||||||
|
quote,
|
||||||
now,
|
now,
|
||||||
this.get('expireTimer'),
|
this.get('expireTimer'),
|
||||||
profileKey
|
profileKey
|
||||||
|
|
|
@ -1157,13 +1157,13 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const attachments = await this.fileInput.getFiles();
|
const attachments = await this.fileInput.getFiles();
|
||||||
|
|
||||||
const sendDelta = Date.now() - this.sendStart;
|
const sendDelta = Date.now() - this.sendStart;
|
||||||
console.log('Send pre-checks took', sendDelta, 'milliseconds');
|
console.log('Send pre-checks took', sendDelta, 'milliseconds');
|
||||||
|
|
||||||
this.model.sendMessage(message, attachments);
|
this.model.sendMessage(message, attachments, this.quote);
|
||||||
|
|
||||||
input.val('');
|
input.val('');
|
||||||
|
this.setQuoteMessage(null);
|
||||||
this.focusMessageFieldAndClearDisabled();
|
this.focusMessageFieldAndClearDisabled();
|
||||||
this.forceUpdateMessageFieldSize(e);
|
this.forceUpdateMessageFieldSize(e);
|
||||||
this.fileInput.deleteFiles();
|
this.fileInput.deleteFiles();
|
||||||
|
|
|
@ -17,6 +17,7 @@ function stringToArrayBuffer(str) {
|
||||||
function Message(options) {
|
function Message(options) {
|
||||||
this.body = options.body;
|
this.body = options.body;
|
||||||
this.attachments = options.attachments || [];
|
this.attachments = options.attachments || [];
|
||||||
|
this.quote = options.quote;
|
||||||
this.group = options.group;
|
this.group = options.group;
|
||||||
this.flags = options.flags;
|
this.flags = options.flags;
|
||||||
this.recipients = options.recipients;
|
this.recipients = options.recipients;
|
||||||
|
@ -93,6 +94,29 @@ Message.prototype = {
|
||||||
proto.group.id = stringToArrayBuffer(this.group.id);
|
proto.group.id = stringToArrayBuffer(this.group.id);
|
||||||
proto.group.type = this.group.type
|
proto.group.type = this.group.type
|
||||||
}
|
}
|
||||||
|
if (this.quote) {
|
||||||
|
var QuotedAttachment = textsecure.protobuf.DataMessage.Quote.QuotedAttachment;
|
||||||
|
var Quote = textsecure.protobuf.DataMessage.Quote;
|
||||||
|
console.log(this.quote);
|
||||||
|
|
||||||
|
proto.quote = new Quote();
|
||||||
|
|
||||||
|
var quote = proto.quote;
|
||||||
|
quote.id = this.quote.id;
|
||||||
|
quote.author = this.quote.author;
|
||||||
|
quote.text = this.quote.text;
|
||||||
|
quote.attachments = (this.quote.attachments || []).map(function(attachment) {
|
||||||
|
var quotedAttachment = new QuotedAttachment();
|
||||||
|
|
||||||
|
quotedAttachment.contentType = attachment.contentType;
|
||||||
|
quotedAttachment.fileName = attachment.fileName;
|
||||||
|
if (attachment.attachmentPointer) {
|
||||||
|
quotedAttachment.thumbnail = attachment.attachmentPointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
return quotedAttachment;
|
||||||
|
});
|
||||||
|
}
|
||||||
if (this.expireTimer) {
|
if (this.expireTimer) {
|
||||||
proto.expireTimer = this.expireTimer;
|
proto.expireTimer = this.expireTimer;
|
||||||
}
|
}
|
||||||
|
@ -223,7 +247,7 @@ MessageSender.prototype = {
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
uploadMedia: function(message) {
|
uploadAttachments: function(message) {
|
||||||
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) {
|
||||||
|
@ -237,9 +261,37 @@ MessageSender.prototype = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
uploadThumbnails: function(message) {
|
||||||
|
var makePointer = this.makeAttachmentPointer.bind(this);
|
||||||
|
var quote = message.quote;
|
||||||
|
|
||||||
|
if (!quote || !quote.attachments || quote.attachments.length === 0) {
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.all(quote.attachments.map(function(attachment) {
|
||||||
|
const thumbnail = attachment.thumbnail;
|
||||||
|
if (!thumbnail) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return makePointer(thumbnail).then(function(pointer) {
|
||||||
|
attachment.attachmentPointer = pointer;
|
||||||
|
});
|
||||||
|
})).catch(function(error) {
|
||||||
|
if (error instanceof Error && error.name === 'HTTPError') {
|
||||||
|
throw new textsecure.MessageError(message, error);
|
||||||
|
} else {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
sendMessage: function(attrs) {
|
sendMessage: function(attrs) {
|
||||||
var message = new Message(attrs);
|
var message = new Message(attrs);
|
||||||
return this.uploadMedia(message).then(function() {
|
return this.uploadAttachments(message).then(function() {
|
||||||
|
return this.uploadThumbnails(message);
|
||||||
|
}.bind(this)).then(function() {
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
this.sendMessageProto(
|
this.sendMessageProto(
|
||||||
message.timestamp,
|
message.timestamp,
|
||||||
|
@ -494,12 +546,13 @@ MessageSender.prototype = {
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
sendMessageToNumber: function(number, messageText, attachments, timestamp, expireTimer, profileKey) {
|
sendMessageToNumber: function(number, messageText, attachments, quote, timestamp, expireTimer, profileKey) {
|
||||||
return this.sendMessage({
|
return this.sendMessage({
|
||||||
recipients : [number],
|
recipients : [number],
|
||||||
body : messageText,
|
body : messageText,
|
||||||
timestamp : timestamp,
|
timestamp : timestamp,
|
||||||
attachments : attachments,
|
attachments : attachments,
|
||||||
|
quote : quote,
|
||||||
needsSync : true,
|
needsSync : true,
|
||||||
expireTimer : expireTimer,
|
expireTimer : expireTimer,
|
||||||
profileKey : profileKey
|
profileKey : profileKey
|
||||||
|
@ -558,7 +611,7 @@ MessageSender.prototype = {
|
||||||
]);
|
]);
|
||||||
},
|
},
|
||||||
|
|
||||||
sendMessageToGroup: function(groupId, messageText, attachments, timestamp, expireTimer, profileKey) {
|
sendMessageToGroup: function(groupId, messageText, attachments, quote, timestamp, expireTimer, profileKey) {
|
||||||
return textsecure.storage.groups.getNumbers(groupId).then(function(numbers) {
|
return textsecure.storage.groups.getNumbers(groupId).then(function(numbers) {
|
||||||
if (numbers === undefined)
|
if (numbers === undefined)
|
||||||
return Promise.reject(new Error("Unknown Group"));
|
return Promise.reject(new Error("Unknown Group"));
|
||||||
|
@ -574,6 +627,7 @@ MessageSender.prototype = {
|
||||||
body : messageText,
|
body : messageText,
|
||||||
timestamp : timestamp,
|
timestamp : timestamp,
|
||||||
attachments : attachments,
|
attachments : attachments,
|
||||||
|
quote : quote,
|
||||||
needsSync : true,
|
needsSync : true,
|
||||||
expireTimer : expireTimer,
|
expireTimer : expireTimer,
|
||||||
profileKey : profileKey,
|
profileKey : profileKey,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue