[MM-37602] fix channel unread filtering for CRT (#5622)

Summary:
Fixes filtering of unread channels with CRT

Ticket Link:
https://mattermost.atlassian.net/browse/MM-37602

This PR was tested on:
ios 12 simulator, ios 14.4
This commit is contained in:
Ashish Bhate 2021-08-19 19:58:56 +05:30 committed by GitHub
parent 7f69a1adf9
commit 8228ed3400
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -43,10 +43,9 @@ export function buildDisplayableChannelListWithUnreadSection(usersState: UsersSt
const locale = getUserLocale(currentUserId, profiles);
const missingDirectChannels = createMissingDirectChannels(currentUserId, myChannels, myPreferences);
const channels = buildChannels(usersState, myChannels, missingDirectChannels, teammateNameDisplay, locale);
const unreadChannels = [...buildChannelsWithMentions(channels, myMembers, locale), ...buildUnreadChannels(channels, myMembers, locale)];
const unreadChannels = [...buildChannelsWithMentions(channels, myMembers, locale), ...buildUnreadChannels(channels, myMembers, locale, collapsedThreadsEnabled)];
// collapsedThreadsEnabled is set to "false" as we are filtering not just based on root posts
const notUnreadChannels = channels.filter((channel: Channel) => !isUnreadChannel(myMembers, channel, false));
const notUnreadChannels = channels.filter((channel: Channel) => !isUnreadChannel(myMembers, channel, collapsedThreadsEnabled));
const favoriteChannels = buildFavoriteChannels(notUnreadChannels, myPreferences, locale);
const notFavoriteChannels = buildNotFavoriteChannels(notUnreadChannels, myPreferences);
@ -550,10 +549,10 @@ function channelHasMentions(members: RelationOneToOne<Channel, ChannelMembership
return false;
}
function channelHasUnreadMessages(members: RelationOneToOne<Channel, ChannelMembership>, channel: Channel): boolean {
function channelHasUnreadMessages(collapsedThreadsEnabled: boolean, members: RelationOneToOne<Channel, ChannelMembership>, channel: Channel): boolean {
const member = members[channel.id];
if (member) {
const msgCount = channel.total_msg_count - member.msg_count;
const msgCount = getMsgCountInChannel(collapsedThreadsEnabled, channel, member);
const onlyMentions = member.notify_props && member.notify_props.mark_unread === General.MENTION;
return (Boolean(msgCount) && !onlyMentions && member.mention_count === 0);
}
@ -715,8 +714,8 @@ function buildChannelsWithMentions(channels: Array<Channel>, members: RelationOn
sort(sortChannelsByDisplayName.bind(null, locale));
}
function buildUnreadChannels(channels: Array<Channel>, members: RelationOneToOne<Channel, ChannelMembership>, locale: string) {
return channels.filter(channelHasUnreadMessages.bind(null, members)).
function buildUnreadChannels(channels: Array<Channel>, members: RelationOneToOne<Channel, ChannelMembership>, locale: string, collapsedThreadsEnabled: boolean) {
return channels.filter(channelHasUnreadMessages.bind(null, collapsedThreadsEnabled, members)).
sort(sortChannelsByDisplayName.bind(null, locale));
}