Message Requests: Show blurhash for pending stickers

This commit is contained in:
Scott Nonnenberg 2020-11-12 13:22:40 -08:00 committed by GitHub
parent 0c6f4248f3
commit 2977c0ca3d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 9 deletions

View file

@ -681,15 +681,17 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
if (sticker && sticker.data) {
const { data } = sticker;
// We don't show anything if we're still loading a sticker
if (data.pending || !data.path) {
// We don't show anything if we don't have the sticker or the blurhash...
if (!data.blurHash && (data.pending || !data.path)) {
return [];
}
return [
{
...data,
url: getAbsoluteAttachmentPath(data.path),
// We want to show the blurhash for stickers, not the spinner
pending: false,
url: data.path ? getAbsoluteAttachmentPath(data.path) : undefined,
},
];
}
@ -2449,7 +2451,19 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
);
const attachments = await Promise.all(
normalAttachments.map((attachment, index) => {
if (!attachment) {
return attachment;
}
// We've already downloaded this!
if (attachment.path) {
window.log.info(
`Normal attachment already downloaded for message ${this.idForLogging()}`
);
return attachment;
}
count += 1;
return window.Signal.AttachmentDownloads.addJob<
typeof window.WhatIsThis
>(attachment, {
@ -2471,6 +2485,13 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
if (!item.image) {
return item;
}
// We've already downloaded this!
if (item.image.path) {
window.log.info(
`Preview attachment already downloaded for message ${this.idForLogging()}`
);
return item;
}
count += 1;
return {
@ -2495,6 +2516,13 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
if (!item.avatar || !item.avatar.avatar) {
return item;
}
// We've already downloaded this!
if (item.avatar.avatar.path) {
window.log.info(
`Contact attachment already downloaded for message ${this.idForLogging()}`
);
return item;
}
count += 1;
return {
@ -2528,9 +2556,14 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
...quote,
attachments: await Promise.all(
(quote.attachments || []).map(async (item, index) => {
// If we already have a path, then we copied this image from the quoted
// message and we don't need to download the attachment.
if (!item.thumbnail || item.thumbnail.path) {
if (!item.thumbnail) {
return item;
}
// We've already downloaded this!
if (item.thumbnail.path) {
window.log.info(
`Quote attachment already downloaded for message ${this.idForLogging()}`
);
return item;
}
@ -2553,7 +2586,11 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
let sticker = this.get('sticker')!;
if (sticker) {
if (sticker && sticker.data && sticker.data.path) {
window.log.info(
`Sticker attachment already downloaded for message ${this.idForLogging()}`
);
} else if (sticker) {
window.log.info(
`Queueing sticker download for message ${this.idForLogging()}`
);