Skip to content

Commit

Permalink
Message Requests: Show blurhash for pending stickers
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Nov 12, 2020
1 parent 0c6f424 commit 2977c0c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 9 deletions.
12 changes: 11 additions & 1 deletion ts/models/conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
51 changes: 44 additions & 7 deletions ts/models/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
];
}
Expand Down Expand Up @@ -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, {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
}

Expand All @@ -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()}`
);
Expand Down
4 changes: 3 additions & 1 deletion ts/state/ducks/conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ export type MessageType = {
attachments: Array<AttachmentType>;
sticker: {
data?: {
pending: boolean;
pending?: boolean;
blurHash?: string;
};
};
unread: boolean;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 2977c0c

Please sign in to comment.