[MM-59912] Update unread threads in team when threads are received (#28059)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
9801007b90
Коммит
a2a54af338
@@ -1,10 +1,14 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import type {Team} from '@mattermost/types/teams';
|
||||
import type {UserThread} from '@mattermost/types/threads';
|
||||
import type {RelationOneToMany} from '@mattermost/types/utilities';
|
||||
|
||||
import {ThreadTypes} from 'mattermost-redux/action_types';
|
||||
import deepFreeze from 'mattermost-redux/utils/deep_freeze';
|
||||
|
||||
import {handleFollowChanged} from './threadsInTeam';
|
||||
import {handleFollowChanged, unreadThreadsInTeamReducer} from './threadsInTeam';
|
||||
import type {ExtraData} from './types';
|
||||
|
||||
describe('handleFollowChanged', () => {
|
||||
@@ -74,3 +78,23 @@ describe('handleFollowChanged', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('unreadThreadsInTeam', () => {
|
||||
test('RECEIVED_THREADS should update the state if there are unread threads', () => {
|
||||
const state = deepFreeze({});
|
||||
const nextState: RelationOneToMany<Team, UserThread> = unreadThreadsInTeamReducer(state, {
|
||||
type: ThreadTypes.RECEIVED_THREADS,
|
||||
data: {
|
||||
team_id: 'a',
|
||||
threads: [
|
||||
{id: 't1', unread_replies: 1},
|
||||
{id: 't2', unread_mentions: 1},
|
||||
{id: 't3'},
|
||||
],
|
||||
},
|
||||
}, {threads: {}});
|
||||
|
||||
expect(nextState).not.toBe(state);
|
||||
expect(nextState.a).toEqual(['t1', 't2']);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import type {AnyAction} from 'redux';
|
||||
|
||||
import type {Team} from '@mattermost/types/teams';
|
||||
import type {ThreadsState, UserThread} from '@mattermost/types/threads';
|
||||
import type {ThreadsState, UserThread, UserThreadWithPost} from '@mattermost/types/threads';
|
||||
import type {IDMappedObjects, RelationOneToMany} from '@mattermost/types/utilities';
|
||||
|
||||
import {ChannelTypes, PostTypes, TeamTypes, ThreadTypes, UserTypes} from 'mattermost-redux/action_types';
|
||||
@@ -283,6 +283,14 @@ export const unreadThreadsInTeamReducer = (state: ThreadsState['unreadThreadsInT
|
||||
return handleReceivedThread(state, action, extra);
|
||||
}
|
||||
return state;
|
||||
case ThreadTypes.RECEIVED_THREADS:
|
||||
return handleReceiveThreads(state, {
|
||||
...action,
|
||||
data: {
|
||||
...action.data,
|
||||
threads: action.data.threads.filter((thread: UserThreadWithPost) => thread.unread_replies > 0 || thread.unread_mentions > 0),
|
||||
},
|
||||
});
|
||||
case PostTypes.POST_REMOVED:
|
||||
return handlePostRemoved(state, action);
|
||||
case ThreadTypes.RECEIVED_UNREAD_THREADS:
|
||||
|
||||
Ссылка в новой задаче
Block a user