diff --git a/src/store/messages/saga.test.ts b/src/store/messages/saga.test.ts index 558993e91..d523fce29 100644 --- a/src/store/messages/saga.test.ts +++ b/src/store/messages/saga.test.ts @@ -216,7 +216,30 @@ describe('messages saga', () => { }); describe(receiveUpdateMessage, () => { - it('updates the messages', async () => { + it('does not update the message if already updated', async () => { + const originalMessage = { + id: 8667728016, + message: 'edited message', + parentMessageText: null, + createdAt: 1678861267433, + updatedAt: 1678861290000, + }; + + const messages = { 8667728016: originalMessage }; + + const { storeState } = await expectSaga(receiveUpdateMessage, { + payload: { channelId: 'channel-1', message: originalMessage }, + }) + .provide([ + ...successResponses(), + ]) + .withReducer(rootReducer, { normalized: { messages } as any } as RootState) + .run(); + + expect(storeState.normalized.messages).toEqual({ 8667728016: originalMessage }); + }); + + it('updates the message if not already updated', async () => { const message = { id: 8667728016, message: 'original message', @@ -224,6 +247,7 @@ describe(receiveUpdateMessage, () => { createdAt: 1678861267433, updatedAt: 0, }; + const editedMessage = { id: 8667728016, message: 'edited message', diff --git a/src/store/messages/saga.ts b/src/store/messages/saga.ts index 2b8794f8d..988a62c5c 100644 --- a/src/store/messages/saga.ts +++ b/src/store/messages/saga.ts @@ -486,6 +486,12 @@ export function* replaceOptimisticMessage(currentMessages, message) { export function* receiveUpdateMessage(action) { let { message } = action.payload; + // Check if the message already exists in the state + const existingMessage = yield select(messageSelector(message.id)); + if (existingMessage && existingMessage.message === message.message) { + return; + } + const preview = yield call(getPreview, message.message); message.preview = preview;