Update sendStateByConversationId after merge

This commit is contained in:
Fedor Indutny 2024-04-17 09:00:29 +02:00 committed by GitHub
parent da9e657211
commit 99fd03078e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 240 additions and 11 deletions

View file

@ -16,6 +16,7 @@ import { isNotNil } from '../util/isNotNil';
import { map } from '../util/iterables';
import { softAssert, strictAssert } from '../util/assert';
import { isStory } from '../messages/helpers';
import type { SendStateByConversationId } from '../messages/MessageSendState';
import { getStoryDataFromMessageAttributes } from './storyLoader';
const MAX_THROTTLED_REDUX_UPDATERS = 200;
@ -95,13 +96,42 @@ export class MessageCache {
conversationId: string;
obsoleteId: string;
}): void {
const updateSendState = (
sendState?: SendStateByConversationId
): SendStateByConversationId | undefined => {
if (!sendState?.[obsoleteId]) {
return sendState;
}
const { [obsoleteId]: obsoleteSendState, ...rest } = sendState;
return {
[conversationId]: obsoleteSendState,
...rest,
};
};
for (const [messageId, messageAttributes] of this.state.messages) {
if (messageAttributes.conversationId !== obsoleteId) {
continue;
}
const editHistory = messageAttributes.editHistory?.map(history => {
return {
...history,
sendStateByConversationId: updateSendState(
history.sendStateByConversationId
),
};
});
this.setAttributes({
messageId,
messageAttributes: { conversationId },
messageAttributes: {
conversationId,
sendStateByConversationId: updateSendState(
messageAttributes.sendStateByConversationId
),
editHistory,
},
skipSaveToDatabase: true,
});
}