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

@ -1299,7 +1299,17 @@ export class ConversationModel extends window.Backbone.Model<
}
// eslint-disable-next-line no-await-in-loop
await Promise.all(readMessages.map(m => m.queueAttachmentDownloads()));
await Promise.all(
readMessages.map(async m => {
const registered = window.MessageController.register(m.id, m);
const shouldSave = await registered.queueAttachmentDownloads();
if (shouldSave) {
await window.Signal.Data.saveMessage(registered.attributes, {
Message: window.Whisper.Message,
});
}
})
);
} while (messages.length > 0);
}

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()}`
);

View file

@ -118,7 +118,8 @@ export type MessageType = {
attachments: Array<AttachmentType>;
sticker: {
data?: {
pending: boolean;
pending?: boolean;
blurHash?: string;
};
};
unread: boolean;
@ -663,6 +664,7 @@ function hasMessageHeightChanged(
message.sticker.data &&
previous.sticker &&
previous.sticker.data &&
!previous.sticker.data.blurHash &&
previous.sticker.data.pending !== message.sticker.data.pending;
if (stickerPendingChanged) {
return true;