diff --git a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/threads/threadsInTeam.test.ts b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/threads/threadsInTeam.test.ts index b4e4387bc2..67e57b8cf4 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/threads/threadsInTeam.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/threads/threadsInTeam.test.ts @@ -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 = 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']); + }); +}); 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 834bae04fc..7f36cc0d82 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 @@ -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: