From 2977c0ca3dddc43d3c750210db31d134a6841c83 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Thu, 12 Nov 2020 13:22:40 -0800 Subject: [PATCH] Message Requests: Show blurhash for pending stickers --- ts/models/conversations.ts | 12 +++++++- ts/models/messages.ts | 51 ++++++++++++++++++++++++++++----- ts/state/ducks/conversations.ts | 4 ++- 3 files changed, 58 insertions(+), 9 deletions(-) diff --git a/ts/models/conversations.ts b/ts/models/conversations.ts index f98b8c7a73..61856296d2 100644 --- a/ts/models/conversations.ts +++ b/ts/models/conversations.ts @@ -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); } diff --git a/ts/models/messages.ts b/ts/models/messages.ts index 6a60fe3392..5cdcea977d 100644 --- a/ts/models/messages.ts +++ b/ts/models/messages.ts @@ -681,15 +681,17 @@ export class MessageModel extends window.Backbone.Model { 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 { ); 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 { 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 { 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 { ...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 { // 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()}` ); diff --git a/ts/state/ducks/conversations.ts b/ts/state/ducks/conversations.ts index 4e6984c440..90d7cf2656 100644 --- a/ts/state/ducks/conversations.ts +++ b/ts/state/ducks/conversations.ts @@ -118,7 +118,8 @@ export type MessageType = { attachments: Array; 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;