From 8228ed3400f557cda43e80deb2ac1862763ec266 Mon Sep 17 00:00:00 2001 From: Ashish Bhate Date: Thu, 19 Aug 2021 19:58:56 +0530 Subject: [PATCH] [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 --- app/mm-redux/utils/channel_utils.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/mm-redux/utils/channel_utils.ts b/app/mm-redux/utils/channel_utils.ts index f95cf9b50..41c18d448 100644 --- a/app/mm-redux/utils/channel_utils.ts +++ b/app/mm-redux/utils/channel_utils.ts @@ -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: Channel): boolean { +function channelHasUnreadMessages(collapsedThreadsEnabled: boolean, members: RelationOneToOne, 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, members: RelationOn sort(sortChannelsByDisplayName.bind(null, locale)); } -function buildUnreadChannels(channels: Array, members: RelationOneToOne, locale: string) { - return channels.filter(channelHasUnreadMessages.bind(null, members)). +function buildUnreadChannels(channels: Array, members: RelationOneToOne, locale: string, collapsedThreadsEnabled: boolean) { + return channels.filter(channelHasUnreadMessages.bind(null, collapsedThreadsEnabled, members)). sort(sortChannelsByDisplayName.bind(null, locale)); }