From 930ca847eb2f9eb399ac9493e35dd3be68cfdafd Mon Sep 17 00:00:00 2001 From: automated-signal <37887102+automated-signal@users.noreply.github.com> Date: Tue, 2 Jul 2024 18:32:28 -0500 Subject: [PATCH] Improve story cleanup on expiration/deletion Co-authored-by: Scott Nonnenberg --- ts/models/messages.ts | 7 +++---- ts/util/cleanup.ts | 10 +++++----- ts/util/getStoryReplyText.ts | 4 ---- ts/util/hydrateStoryContext.ts | 10 ++++++++-- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/ts/models/messages.ts b/ts/models/messages.ts index 5ea7d90bbe42..f49c1c44c55c 100644 --- a/ts/models/messages.ts +++ b/ts/models/messages.ts @@ -264,13 +264,12 @@ export class MessageModel extends window.Backbone.Model { async hydrateStoryContext( inMemoryMessage?: MessageAttributesType, - { - shouldSave, - }: { + options: { shouldSave?: boolean; + isStoryErased?: boolean; } = {} ): Promise { - await hydrateStoryContext(this.id, inMemoryMessage, { shouldSave }); + await hydrateStoryContext(this.id, inMemoryMessage, options); } // Dependencies of prop-generation functions diff --git a/ts/util/cleanup.ts b/ts/util/cleanup.ts index 11dac01c8943..8e354f94ec13 100644 --- a/ts/util/cleanup.ts +++ b/ts/util/cleanup.ts @@ -139,8 +139,10 @@ async function cleanupStoryReplies( reply, 'cleanupStoryReplies/1:1' ); - model.set('storyReplyContext', undefined); - await model.hydrateStoryContext(story, { shouldSave: true }); + await model.hydrateStoryContext(story, { + shouldSave: true, + isStoryErased: true, + }); }) ); } @@ -157,9 +159,7 @@ export async function deleteMessageData( await window.Signal.Migrations.deleteExternalMessageFiles(message); if (isStory(message)) { - // Attachments have been deleted from disk; remove from memory before replies update - const storyWithoutAttachments = { ...message, attachments: undefined }; - await cleanupStoryReplies(storyWithoutAttachments); + await cleanupStoryReplies(message); } const { sticker } = message; diff --git a/ts/util/getStoryReplyText.ts b/ts/util/getStoryReplyText.ts index a7dfb4088d72..a39ce414f8d3 100644 --- a/ts/util/getStoryReplyText.ts +++ b/ts/util/getStoryReplyText.ts @@ -13,10 +13,6 @@ export function getStoryReplyText( return i18n('icu:Quote__story-unavailable'); } - if (attachment.caption) { - return attachment.caption; - } - const attachments = [attachment]; if (isImage(attachments)) { diff --git a/ts/util/hydrateStoryContext.ts b/ts/util/hydrateStoryContext.ts index 67ef4ae82dd6..d7ab7313ebd2 100644 --- a/ts/util/hydrateStoryContext.ts +++ b/ts/util/hydrateStoryContext.ts @@ -14,8 +14,10 @@ export async function hydrateStoryContext( storyMessageParam?: MessageAttributesType, { shouldSave, + isStoryErased, }: { shouldSave?: boolean; + isStoryErased?: boolean; } = {} ): Promise { let messageAttributes: MessageAttributesType; @@ -35,7 +37,11 @@ export async function hydrateStoryContext( const { storyReplyContext: context } = messageAttributes; // We'll continue trying to get the attachment as long as the message still exists - if (context && (context.attachment?.url || !context.messageId)) { + if ( + !isStoryErased && + context && + (context.attachment?.url || !context.messageId) + ) { return; } @@ -52,7 +58,7 @@ export async function hydrateStoryContext( storyMessage = undefined; } - if (!storyMessage) { + if (!storyMessage || isStoryErased) { const conversation = window.ConversationController.get( messageAttributes.conversationId );