Improve story cleanup on expiration/deletion

This commit is contained in:
Scott Nonnenberg 2024-07-02 16:15:17 -07:00 committed by GitHub
parent 39d15ba620
commit bde4fa40fe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 16 additions and 15 deletions

View file

@ -264,13 +264,12 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
async hydrateStoryContext(
inMemoryMessage?: MessageAttributesType,
{
shouldSave,
}: {
options: {
shouldSave?: boolean;
isStoryErased?: boolean;
} = {}
): Promise<void> {
await hydrateStoryContext(this.id, inMemoryMessage, { shouldSave });
await hydrateStoryContext(this.id, inMemoryMessage, options);
}
// Dependencies of prop-generation functions

View file

@ -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;

View file

@ -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)) {

View file

@ -14,8 +14,10 @@ export async function hydrateStoryContext(
storyMessageParam?: MessageAttributesType,
{
shouldSave,
isStoryErased,
}: {
shouldSave?: boolean;
isStoryErased?: boolean;
} = {}
): Promise<void> {
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
);