From 396ee06dcbaf5e7367c7693b1286152c66978c8f Mon Sep 17 00:00:00 2001 From: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Date: Fri, 24 Jan 2025 15:44:11 -0500 Subject: [PATCH] [MM-61319] Delete the thread from state when the root post is deleted by another user (#29975) --- .../src/reducers/entities/threads/index.ts | 1 + .../reducers/entities/threads/threads.test.js | 16 ++++++++-------- .../reducers/entities/threads/threadsInTeam.ts | 2 ++ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/threads/index.ts b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/threads/index.ts index 41a8924674..f3774ba16b 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/threads/index.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/threads/index.ts @@ -26,6 +26,7 @@ export const threadsReducer = (state: ThreadsState['threads'] = {}, action: MMRe }, {}), }; } + case PostTypes.POST_DELETED: case PostTypes.POST_REMOVED: { const post = action.data; diff --git a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/threads/threads.test.js b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/threads/threads.test.js index e27a0afd12..c69250e5a5 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/threads/threads.test.js +++ b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/threads/threads.test.js @@ -310,7 +310,7 @@ describe('threads', () => { expect(nextState.threadsInTeam.a).toBe(undefined); }); - test('POST_REMOVED should remove the thread when root post', () => { + test.each([PostTypes.POST_REMOVED, PostTypes.POST_DELETED])('%s should remove the thread when root post', (action) => { const state = deepFreeze({ threadsInTeam: { a: ['t1', 't2', 't3'], @@ -334,7 +334,7 @@ describe('threads', () => { }); const nextState = threadsReducer(state, { - type: PostTypes.POST_REMOVED, + type: action, data: {id: 't2', root_id: ''}, }); @@ -344,7 +344,7 @@ describe('threads', () => { expect(nextState.unreadThreadsInTeam.a).toEqual(['t1', 't3']); }); - test('POST_REMOVED should remove the thread when root post from all teams', () => { + test.each([PostTypes.POST_REMOVED, PostTypes.POST_DELETED])('%s should remove the thread when root post from all teams', (action) => { const state = deepFreeze({ threadsInTeam: { a: ['t1', 't2', 't3'], @@ -370,7 +370,7 @@ describe('threads', () => { }); const nextState = threadsReducer(state, { - type: PostTypes.POST_REMOVED, + type: action, data: {id: 't2', root_id: ''}, }); @@ -382,7 +382,7 @@ describe('threads', () => { expect(nextState.unreadThreadsInTeam.b).toEqual([]); }); - test('POST_REMOVED should do nothing when not a root post', () => { + test.each([PostTypes.POST_REMOVED, PostTypes.POST_DELETED])('%s should do nothing when not a root post', (action) => { const state = deepFreeze({ threadsInTeam: { a: ['t1', 't2', 't3'], @@ -406,7 +406,7 @@ describe('threads', () => { }); const nextState = threadsReducer(state, { - type: PostTypes.POST_REMOVED, + type: action, data: {id: 't2', root_id: 't1'}, }); @@ -416,7 +416,7 @@ describe('threads', () => { expect(nextState.unreadThreadsInTeam.a).toEqual(['t1', 't2', 't3']); }); - test('POST_REMOVED should do nothing when post not exist', () => { + test.each([PostTypes.POST_REMOVED, PostTypes.POST_DELETED])('%s should do nothing when post not exist', (action) => { const state = deepFreeze({ threadsInTeam: { a: ['t1', 't2'], @@ -437,7 +437,7 @@ describe('threads', () => { }); const nextState = threadsReducer(state, { - type: PostTypes.POST_REMOVED, + type: action, data: {id: 't3', root_id: ''}, }); diff --git a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/threads/threadsInTeam.ts b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/threads/threadsInTeam.ts index 088289d6e5..5f28eeac14 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/threads/threadsInTeam.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/threads/threadsInTeam.ts @@ -247,6 +247,7 @@ export const threadsInTeamReducer = (state: ThreadsState['threadsInTeam'] = {}, switch (action.type) { case ThreadTypes.RECEIVED_THREAD: return handleReceivedThread(state, action, extra); + case PostTypes.POST_DELETED: case PostTypes.POST_REMOVED: return handlePostRemoved(state, action); case ThreadTypes.RECEIVED_THREADS: @@ -292,6 +293,7 @@ export const unreadThreadsInTeamReducer = (state: ThreadsState['unreadThreadsInT threads: action.data.threads.filter((thread: UserThreadWithPost) => thread.unread_replies > 0 || thread.unread_mentions > 0), }, }); + case PostTypes.POST_DELETED: case PostTypes.POST_REMOVED: return handlePostRemoved(state, action); case ThreadTypes.RECEIVED_UNREAD_THREADS: