From c079020e9e2405bb6beb6b66be09f72dc7bba8d3 Mon Sep 17 00:00:00 2001 From: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Date: Fri, 31 Jan 2025 11:30:06 -0500 Subject: [PATCH] [MM-62113] Force reload of team unreads when following/unfollowing a thread (#29994) * [MM-62113] Force reload of team unreads when following/unfollowing a thread * E2E test * add test key --------- Co-authored-by: yasserfaraazkhan --- .../collapsed_reply_threads/unread_spec.ts | 63 +++++++++++++++++++ .../mattermost-redux/src/actions/threads.ts | 7 +++ 2 files changed, 70 insertions(+) diff --git a/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/unread_spec.ts b/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/unread_spec.ts index 40cf47e412..bc5dc1be9a 100644 --- a/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/unread_spec.ts +++ b/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/unread_spec.ts @@ -96,4 +96,67 @@ describe('Collapsed Reply Threads', () => { cy.uiCloseRHS(); }); }); + + it('MM-T5671 should handle mention counts correctly when marking a thread as unread and unfollowing it', () => { + // # Post a root post as current user + cy.postMessageAs({ + sender: otherUser, + message: `@${testUser.username} Root post for mention test`, + channelId: testChannel.id, + }).then(({id: rootId}) => { + // # Post a reply mentioning the user + cy.postMessageAs({ + sender: otherUser, + message: `Hey @${testUser.username}, check this out!`, + channelId: testChannel.id, + rootId, + }).then(({id: replyId}) => { + // # Post another reply mentioning the user + cy.postMessageAs({ + sender: otherUser, + message: `Hey @${testUser.username}, check this out too!`, + channelId: testChannel.id, + rootId, + }); + + // # Click root post to open RHS + cy.get(`#post_${rootId}`).click(); + + // # Wait for RHS to open + cy.wait(TIMEOUTS.ONE_SEC); + + // # Mark the thread as unread + cy.uiClickPostDropdownMenu(replyId, 'Mark as Unread', 'RHS_COMMENT'); + + // # Wait for unread to be marked correctly + cy.wait(TIMEOUTS.ONE_SEC); + + // # Close RHS + cy.uiCloseRHS(); + + // # Switch to a different team + cy.apiCreateTeam('team', 'Team').then(({team: otherTeam}) => { + // # Click on the other team button to switch teams + cy.get(`#${otherTeam.name}TeamButton`).click(); + + // * Verify mention count on the original team + cy.get(`#${testTeam.name}TeamButton`).find('.badge').should('be.visible'); + + // # Click on the original team button to switch back + cy.get(`#${testTeam.name}TeamButton`).click(); + + // # Unfollow the thread + cy.uiGetPostThreadFooter(rootId).findByText('Following').click(); + + // # Switch to a different team and back + cy.get(`#${otherTeam.name}TeamButton`).click(); + cy.get(`#${testTeam.name}TeamButton`).click(); + cy.get(`#${otherTeam.name}TeamButton`).click(); + + // * Verify there is no mention count on the original team + cy.get(`#${testTeam.name}TeamButton`).find('.badge').should('not.exist'); + }); + }); + }); + }); }); diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/threads.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/threads.ts index 77d934103a..db7c965056 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/threads.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/threads.ts @@ -23,6 +23,7 @@ import type {DispatchFunc, GetStateFunc, ActionFunc, ActionFuncAsync} from 'matt import {logError} from './errors'; import {forceLogoutIfNecessary} from './helpers'; import {getPostThread} from './posts'; +import {getMyTeamUnreads} from './teams'; type ExtendedPost = Post & { system_post_ids?: string[] }; @@ -391,6 +392,12 @@ export function setThreadFollow(userId: string, teamId: string, threadId: string dispatch(logError(error)); return {error}; } + + // As a short term fix for https://mattermost.atlassian.net/browse/MM-62113, we will fetch + // the users team unreads after following or unfollowing a thread. This will ensure that the unreads are + // updated correctly in the case where the user is following or unfollowing a thread that has unread messages. + dispatch(getMyTeamUnreads(isCollapsedThreadsEnabled(getState()))); + return {}; }; }