Reset storyReplyContext whenever a story expires
This commit is contained in:
parent
25bc16300c
commit
e80d9d1f30
2 changed files with 55 additions and 2 deletions
|
@ -342,7 +342,9 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
);
|
||||
}
|
||||
|
||||
async hydrateStoryContext(inMemoryMessage?: MessageModel): Promise<void> {
|
||||
async hydrateStoryContext(
|
||||
inMemoryMessage?: MessageModel | null
|
||||
): Promise<void> {
|
||||
const storyId = this.get('storyId');
|
||||
if (!storyId) {
|
||||
return;
|
||||
|
@ -352,7 +354,10 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
return;
|
||||
}
|
||||
|
||||
const message = inMemoryMessage || (await getMessageById(storyId));
|
||||
const message =
|
||||
inMemoryMessage === undefined
|
||||
? await getMessageById(storyId)
|
||||
: inMemoryMessage;
|
||||
|
||||
if (!message) {
|
||||
const conversation = this.getConversation();
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
import type { MessageAttributesType } from '../model-types.d';
|
||||
import { deletePackReference } from '../types/Stickers';
|
||||
import { isStory } from '../messages/helpers';
|
||||
|
||||
export async function cleanupMessage(
|
||||
message: MessageAttributesType
|
||||
|
@ -17,6 +18,53 @@ export async function cleanupMessage(
|
|||
window.MessageController.unregister(id);
|
||||
|
||||
await deleteMessageData(message);
|
||||
|
||||
if (isStory(message)) {
|
||||
await fixupStoryReplies(conversationId, id);
|
||||
}
|
||||
}
|
||||
|
||||
async function fixupStoryReplies(
|
||||
conversationId: string,
|
||||
storyId: string,
|
||||
pagination?: {
|
||||
messageId: string;
|
||||
receivedAt: number;
|
||||
}
|
||||
): Promise<void> {
|
||||
const { messageId, receivedAt } = pagination || {};
|
||||
|
||||
const replies = await window.Signal.Data.getOlderMessagesByConversation(
|
||||
conversationId,
|
||||
{
|
||||
includeStoryReplies: false,
|
||||
receivedAt,
|
||||
storyId,
|
||||
}
|
||||
);
|
||||
|
||||
if (!replies.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const lastMessage = replies[replies.length - 1];
|
||||
const lastMessageId = lastMessage.id;
|
||||
const lastReceivedAt = lastMessage.received_at;
|
||||
|
||||
if (messageId === lastMessageId) {
|
||||
return;
|
||||
}
|
||||
|
||||
replies.forEach(reply => {
|
||||
const model = window.MessageController.register(reply.id, reply);
|
||||
model.unset('storyReplyContext');
|
||||
model.hydrateStoryContext(null);
|
||||
});
|
||||
|
||||
return fixupStoryReplies(conversationId, storyId, {
|
||||
messageId: lastMessageId,
|
||||
receivedAt: lastReceivedAt,
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteMessageData(
|
||||
|
|
Loading…
Reference in a new issue