[MM-60555] Use channel memberships to calculate total unread status instead of team memberships (#30166)

* [MM-60555] Use channel memberships to calculate total unread status instead of team memberships

* Fix lint

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Devin Binnie
2025-02-18 14:04:06 -05:00
коммит произвёл GitHub
родитель ce61ed8f52
Коммит b604930cf6
2 изменённых файлов: 9 добавлений и 97 удалений

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

@@ -2189,7 +2189,7 @@ describe('Selectors.Channels.getUnreadStatus', () => {
});
it('get unreads', () => {
expect(Selectors.getUnreadStatus(testState)).toBe(69);
expect(Selectors.getUnreadStatus(testState)).toBe(5);
});
it('get unreads with a missing profile entity', () => {
@@ -2208,7 +2208,7 @@ describe('Selectors.Channels.getUnreadStatus', () => {
},
};
expect(Selectors.getUnreadStatus(newState)).toBe(69);
expect(Selectors.getUnreadStatus(newState)).toBe(5);
});
it('get unreads with a deactivated user', () => {
@@ -2230,7 +2230,7 @@ describe('Selectors.Channels.getUnreadStatus', () => {
},
},
};
expect(Selectors.getUnreadStatus(newState)).toBe(69);
expect(Selectors.getUnreadStatus(newState)).toBe(5);
});
it('get unreads with a deactivated channel', () => {
@@ -2253,17 +2253,15 @@ describe('Selectors.Channels.getUnreadStatus', () => {
},
};
expect(Selectors.getUnreadStatus(newState)).toBe(65);
expect(Selectors.getUnreadStatus(newState)).toBe(1);
});
});
describe('Selectors.Channels.getUnreadStatus', () => {
const team1 = {id: 'team1', delete_at: 0};
const team2 = {id: 'team2', delete_at: 0};
const channelA = {id: 'channelA', name: 'channelA', team_id: 'team1', delete_at: 0};
const channelB = {id: 'channelB', name: 'channelB', team_id: 'team1', delete_at: 0};
const channelC = {id: 'channelB', name: 'channelB', team_id: 'team2', delete_at: 0};
const dmChannel = {id: 'dmChannel', name: 'user1__user2', team_id: '', delete_at: 0, type: General.DM_CHANNEL};
const gmChannel = {id: 'gmChannel', name: 'gmChannel', team_id: 'team1', delete_at: 0, type: General.GM_CHANNEL};
@@ -2497,61 +2495,6 @@ describe('Selectors.Channels.getUnreadStatus', () => {
expect(unreadMeta.isUnread).toBe(true); // gmChannel is unread
expect(unreadMeta.unreadMentionCount).toBe(gmMember.mention_count);
});
test('should count mentions and messages for other teams from team members', () => {
const myMemberA = {mention_count: 2, msg_count: 3, notify_props: {mark_unread: 'all'}};
const myMemberC = {mention_count: 5, msg_count: 7, notify_props: {mark_unread: 'all'}};
const teamMember1 = {msg_count: 1, mention_count: 2};
const teamMember2 = {msg_count: 3, mention_count: 6};
const state = {
entities: {
general: {config: {}},
preferences: {
myPreferences: {},
},
threads: {
counts: {},
},
channels: {
channels: {
channelA,
channelC,
},
messageCounts: {
channelA: {total: 11},
channelC: {total: 17},
},
myMembers: {
channelA: myMemberA,
channelC: myMemberC,
},
},
teams: {
currentTeamId: 'team1',
myMembers: {
team1: teamMember1,
team2: teamMember2,
},
teams: {
team1,
team2,
},
},
users: {
currentUserId: 'user1',
profiles: {},
},
},
} as unknown as GlobalState;
const unreadStatus = Selectors.getUnreadStatus(state);
const unreadMeta = Selectors.basicUnreadMeta(unreadStatus);
expect(unreadMeta.isUnread).toBe(true); // channelA and channelC are unread
expect(unreadMeta.unreadMentionCount).toBe(myMemberA.mention_count + teamMember2.mention_count);
});
});
describe('Selectors.Channels.getUnreadStatus', () => {

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

@@ -42,7 +42,7 @@ import {
haveICurrentChannelPermission,
haveITeamPermission,
} from 'mattermost-redux/selectors/entities/roles';
import {getCurrentTeamId, getMyTeams, getTeamMemberships} from 'mattermost-redux/selectors/entities/teams';
import {getCurrentTeamId, getMyTeams} from 'mattermost-redux/selectors/entities/teams';
import {
getCurrentUserId,
getStatusForUserId,
@@ -612,8 +612,6 @@ export const getUnreadStatus: (state: GlobalState) => BasicUnreadStatus = create
getUsers,
getCurrentUserId,
getCurrentTeamId,
getMyTeams,
getTeamMemberships,
isCollapsedThreadsEnabled,
getThreadCounts,
getThreadCountsIncludingDirect,
@@ -624,15 +622,13 @@ export const getUnreadStatus: (state: GlobalState) => BasicUnreadStatus = create
users,
currentUserId,
currentTeamId,
myTeams,
myTeamMemberships,
collapsedThreads,
threadCounts,
threadCountsIncludingDirect,
) => {
const {
messages: currentTeamUnreadMessages,
mentions: currentTeamUnreadMentions,
messages: unreadMessages,
mentions: unreadMentions,
} = Object.entries(myMembers).reduce((counts, [channelId, membership]) => {
const channel = channels[channelId];
@@ -640,15 +636,6 @@ export const getUnreadStatus: (state: GlobalState) => BasicUnreadStatus = create
return counts;
}
if (
// other-team non-DM/non-GM channels
channel.team_id !== currentTeamId &&
channel.type !== General.DM_CHANNEL &&
channel.type !== General.GM_CHANNEL
) {
return counts;
}
const channelExists = channel.type === General.DM_CHANNEL ? users[getUserIdFromChannelName(currentUserId, channel.name)]?.delete_at === 0 : channel.delete_at === 0;
if (!channelExists) {
return counts;
@@ -670,26 +657,8 @@ export const getUnreadStatus: (state: GlobalState) => BasicUnreadStatus = create
mentions: 0,
});
// Includes mention count and message count from teams other than the current team
// This count does not include GM's and DM's
const {
messages: otherTeamsUnreadMessages,
mentions: otherTeamsUnreadMentions,
} = myTeams.reduce((acc, team) => {
if (currentTeamId !== team.id) {
const member = myTeamMemberships[team.id];
acc.messages += collapsedThreads ? member.msg_count_root : member.msg_count;
acc.mentions += collapsedThreads ? member.mention_count_root : member.mention_count;
}
return acc;
}, {
messages: 0,
mentions: 0,
});
const totalUnreadMessages = currentTeamUnreadMessages + otherTeamsUnreadMessages;
let totalUnreadMentions = currentTeamUnreadMentions + otherTeamsUnreadMentions;
const totalUnreadMessages = unreadMessages;
let totalUnreadMentions = unreadMentions;
let anyUnreadThreads = false;
// when collapsed threads are enabled, we start with root-post counts from channels, then