fix: multiple DaR/DaS messages can no longer appear

pull/3281/head
Audric Ackermann 4 months ago
parent 021c600b1d
commit 70cd069175
No known key found for this signature in database

@ -1365,6 +1365,23 @@ const throttledAllMessagesDispatch = debounce(
{ trailing: true, leading: true, maxWait: 1000 }
);
/**
* With `throttledAllMessagesDispatch`, we batch refresh changed messages every XXXms.
* Sometimes, a message is changed and then deleted quickly.
* This can cause an issue because if the message is deleted, but the XXXms ticks after that,
* the message will appear again in the redux store.
* This is a mistake, and was usually fixed by reloading the corresponding conversation.
* Well, this function should hopefully fix this issue.
* Anytime we delete a message, we have to call it to "cancel scheduled refreshes"
* @param messageIds the ids to cancel the dispatch of.
*/
export function cancelUpdatesToDispatch(messageIds: Array<string>) {
for (let index = 0; index < messageIds.length; index++) {
const messageId = messageIds[index];
updatesToDispatch.delete(messageId);
}
}
const updatesToDispatch: Map<string, MessageModelPropsWithoutConvoProps> = new Map();
export class MessageCollection extends Backbone.Collection<MessageModel> {}

@ -26,6 +26,7 @@ import {
import { AttachmentType } from '../../types/Attachment';
import { CONVERSATION_PRIORITIES, ConversationTypeEnum } from '../../models/types';
import { WithConvoId, WithMessageHash, WithMessageId } from '../../session/types/with';
import { cancelUpdatesToDispatch } from '../../models/message';
export type MessageModelPropsWithoutConvoProps = {
propsForMessage: PropsForMessageWithoutConvoProps;
@ -543,6 +544,10 @@ function handleMessageExpiredOrDeleted(
const messageId = (payload as any).messageId as string | undefined;
const messageHash = (payload as any).messageHash as string | undefined;
if (messageId) {
cancelUpdatesToDispatch([messageId]);
}
if (conversationId === state.selectedConversation) {
// search if we find this message id.
// we might have not loaded yet, so this case might not happen

Loading…
Cancel
Save