[MM-61319] Delete the thread from state when the root post is deleted by another user (#29975)

Этот коммит содержится в:
Devin Binnie
2025-01-24 15:44:11 -05:00
коммит произвёл GitHub
родитель ca2b3fd528
Коммит 396ee06dcb
3 изменённых файлов: 11 добавлений и 8 удалений

Просмотреть файл

@@ -26,6 +26,7 @@ export const threadsReducer = (state: ThreadsState['threads'] = {}, action: MMRe
}, {}), }, {}),
}; };
} }
case PostTypes.POST_DELETED:
case PostTypes.POST_REMOVED: { case PostTypes.POST_REMOVED: {
const post = action.data; const post = action.data;

Просмотреть файл

@@ -310,7 +310,7 @@ describe('threads', () => {
expect(nextState.threadsInTeam.a).toBe(undefined); 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({ const state = deepFreeze({
threadsInTeam: { threadsInTeam: {
a: ['t1', 't2', 't3'], a: ['t1', 't2', 't3'],
@@ -334,7 +334,7 @@ describe('threads', () => {
}); });
const nextState = threadsReducer(state, { const nextState = threadsReducer(state, {
type: PostTypes.POST_REMOVED, type: action,
data: {id: 't2', root_id: ''}, data: {id: 't2', root_id: ''},
}); });
@@ -344,7 +344,7 @@ describe('threads', () => {
expect(nextState.unreadThreadsInTeam.a).toEqual(['t1', 't3']); 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({ const state = deepFreeze({
threadsInTeam: { threadsInTeam: {
a: ['t1', 't2', 't3'], a: ['t1', 't2', 't3'],
@@ -370,7 +370,7 @@ describe('threads', () => {
}); });
const nextState = threadsReducer(state, { const nextState = threadsReducer(state, {
type: PostTypes.POST_REMOVED, type: action,
data: {id: 't2', root_id: ''}, data: {id: 't2', root_id: ''},
}); });
@@ -382,7 +382,7 @@ describe('threads', () => {
expect(nextState.unreadThreadsInTeam.b).toEqual([]); 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({ const state = deepFreeze({
threadsInTeam: { threadsInTeam: {
a: ['t1', 't2', 't3'], a: ['t1', 't2', 't3'],
@@ -406,7 +406,7 @@ describe('threads', () => {
}); });
const nextState = threadsReducer(state, { const nextState = threadsReducer(state, {
type: PostTypes.POST_REMOVED, type: action,
data: {id: 't2', root_id: 't1'}, data: {id: 't2', root_id: 't1'},
}); });
@@ -416,7 +416,7 @@ describe('threads', () => {
expect(nextState.unreadThreadsInTeam.a).toEqual(['t1', 't2', 't3']); 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({ const state = deepFreeze({
threadsInTeam: { threadsInTeam: {
a: ['t1', 't2'], a: ['t1', 't2'],
@@ -437,7 +437,7 @@ describe('threads', () => {
}); });
const nextState = threadsReducer(state, { const nextState = threadsReducer(state, {
type: PostTypes.POST_REMOVED, type: action,
data: {id: 't3', root_id: ''}, data: {id: 't3', root_id: ''},
}); });

Просмотреть файл

@@ -247,6 +247,7 @@ export const threadsInTeamReducer = (state: ThreadsState['threadsInTeam'] = {},
switch (action.type) { switch (action.type) {
case ThreadTypes.RECEIVED_THREAD: case ThreadTypes.RECEIVED_THREAD:
return handleReceivedThread(state, action, extra); return handleReceivedThread(state, action, extra);
case PostTypes.POST_DELETED:
case PostTypes.POST_REMOVED: case PostTypes.POST_REMOVED:
return handlePostRemoved(state, action); return handlePostRemoved(state, action);
case ThreadTypes.RECEIVED_THREADS: 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), threads: action.data.threads.filter((thread: UserThreadWithPost) => thread.unread_replies > 0 || thread.unread_mentions > 0),
}, },
}); });
case PostTypes.POST_DELETED:
case PostTypes.POST_REMOVED: case PostTypes.POST_REMOVED:
return handlePostRemoved(state, action); return handlePostRemoved(state, action);
case ThreadTypes.RECEIVED_UNREAD_THREADS: case ThreadTypes.RECEIVED_UNREAD_THREADS: