Fix attachments not loading for stickers/long messages

This commit is contained in:
Fedor Indutny 2021-03-19 12:09:44 -07:00 committed by Josh Perez
parent d7ec22fb0b
commit 6fec6b2646
2 changed files with 28 additions and 2 deletions

View file

@ -2102,7 +2102,10 @@ export async function startApp(): Promise<void> {
const attachmentsToDownload = attachmentDownloadQueue.filter(
(message, index) =>
index <= MAX_ATTACHMENT_MSGS_TO_DOWNLOAD ||
message.getReceivedAt() < THREE_DAYS_AGO
message.getReceivedAt() > THREE_DAYS_AGO ||
// Stickers and long text attachments has to be downloaded for UI
// to display the message properly.
message.hasRequiredAttachmentDownloads()
);
window.log.info(
'Downloading recent attachments of total attachments',

View file

@ -38,7 +38,7 @@ import {
getCallingNotificationText,
} from '../util/callingNotification';
import { PropsType as ProfileChangeNotificationPropsType } from '../components/conversation/ProfileChangeNotification';
import { isImage, isVideo } from '../types/Attachment';
import { AttachmentType, isImage, isVideo } from '../types/Attachment';
/* eslint-disable camelcase */
/* eslint-disable more/no-then */
@ -2598,6 +2598,29 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
return this.syncPromise;
}
hasRequiredAttachmentDownloads(): boolean {
const attachments: ReadonlyArray<AttachmentType> =
this.get('attachments') || [];
const hasLongMessageAttachments = attachments.some(attachment => {
return (
attachment.contentType ===
window.Whisper.Message.LONG_MESSAGE_CONTENT_TYPE
);
});
if (hasLongMessageAttachments) {
return true;
}
const sticker = this.get('sticker');
if (sticker) {
return !sticker.data || !sticker.data.path;
}
return false;
}
// NOTE: If you're modifying this function then you'll likely also need
// to modify queueAttachmentDownloads since it contains the logic below
hasAttachmentDownloads(): boolean {