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 // 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); } while (messages.length > 0);
} }

View file

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

View file

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