Link Previews
This commit is contained in:
parent
91ef39e482
commit
813924685e
36 changed files with 2298 additions and 134 deletions
|
@ -18,6 +18,7 @@ function Message(options) {
|
|||
this.body = options.body;
|
||||
this.attachments = options.attachments || [];
|
||||
this.quote = options.quote;
|
||||
this.preview = options.preview;
|
||||
this.group = options.group;
|
||||
this.flags = options.flags;
|
||||
this.recipients = options.recipients;
|
||||
|
@ -102,6 +103,15 @@ Message.prototype = {
|
|||
proto.group.id = stringToArrayBuffer(this.group.id);
|
||||
proto.group.type = this.group.type;
|
||||
}
|
||||
if (Array.isArray(this.preview)) {
|
||||
proto.preview = this.preview.map(preview => {
|
||||
const item = new textsecure.protobuf.DataMessage.Preview();
|
||||
item.title = preview.title;
|
||||
item.url = preview.url;
|
||||
item.image = preview.image;
|
||||
return item;
|
||||
});
|
||||
}
|
||||
if (this.quote) {
|
||||
const { QuotedAttachment } = textsecure.protobuf.DataMessage.Quote;
|
||||
const { Quote } = textsecure.protobuf.DataMessage;
|
||||
|
@ -238,6 +248,25 @@ MessageSender.prototype = {
|
|||
});
|
||||
},
|
||||
|
||||
async uploadLinkPreviews(message) {
|
||||
try {
|
||||
const preview = await Promise.all(
|
||||
(message.preview || []).map(async item => ({
|
||||
...item,
|
||||
image: await this.makeAttachmentPointer(item.image),
|
||||
}))
|
||||
);
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
message.preview = preview;
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.name === 'HTTPError') {
|
||||
throw new textsecure.MessageError(message, error);
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
uploadThumbnails(message) {
|
||||
const makePointer = this.makeAttachmentPointer.bind(this);
|
||||
const { quote } = message;
|
||||
|
@ -274,6 +303,7 @@ MessageSender.prototype = {
|
|||
return Promise.all([
|
||||
this.uploadAttachments(message),
|
||||
this.uploadThumbnails(message),
|
||||
this.uploadLinkPreviews(message),
|
||||
]).then(
|
||||
() =>
|
||||
new Promise((resolve, reject) => {
|
||||
|
@ -734,6 +764,7 @@ MessageSender.prototype = {
|
|||
messageText,
|
||||
attachments,
|
||||
quote,
|
||||
preview,
|
||||
timestamp,
|
||||
expireTimer,
|
||||
profileKey,
|
||||
|
@ -746,6 +777,7 @@ MessageSender.prototype = {
|
|||
timestamp,
|
||||
attachments,
|
||||
quote,
|
||||
preview,
|
||||
needsSync: true,
|
||||
expireTimer,
|
||||
profileKey,
|
||||
|
@ -822,6 +854,7 @@ MessageSender.prototype = {
|
|||
messageText,
|
||||
attachments,
|
||||
quote,
|
||||
preview,
|
||||
timestamp,
|
||||
expireTimer,
|
||||
profileKey,
|
||||
|
@ -845,6 +878,7 @@ MessageSender.prototype = {
|
|||
timestamp,
|
||||
attachments,
|
||||
quote,
|
||||
preview,
|
||||
needsSync: true,
|
||||
expireTimer,
|
||||
profileKey,
|
||||
|
@ -1023,6 +1057,12 @@ MessageSender.prototype = {
|
|||
options
|
||||
);
|
||||
},
|
||||
makeProxiedRequest(url, options) {
|
||||
return this.server.makeProxiedRequest(url, options);
|
||||
},
|
||||
getProxiedSize(url) {
|
||||
return this.server.getProxiedSize(url);
|
||||
},
|
||||
};
|
||||
|
||||
window.textsecure = window.textsecure || {};
|
||||
|
@ -1068,6 +1108,8 @@ textsecure.MessageSender = function MessageSenderWrapper(
|
|||
this.syncVerification = sender.syncVerification.bind(sender);
|
||||
this.sendDeliveryReceipt = sender.sendDeliveryReceipt.bind(sender);
|
||||
this.sendReadReceipts = sender.sendReadReceipts.bind(sender);
|
||||
this.makeProxiedRequest = sender.makeProxiedRequest.bind(sender);
|
||||
this.getProxiedSize = sender.getProxiedSize.bind(sender);
|
||||
};
|
||||
|
||||
textsecure.MessageSender.prototype = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue