diff --git a/app/actions/remote/channel.ts b/app/actions/remote/channel.ts index 9dd07e6217..b8ad866923 100644 --- a/app/actions/remote/channel.ts +++ b/app/actions/remote/channel.ts @@ -394,6 +394,7 @@ export async function fetchMissingSidebarInfo(serverUrl: string, directChannels: const displayName = displayNameByChannel[c.id]; if (displayName) { c.display_name = displayName; + c.fake = true; } }); diff --git a/app/actions/remote/user.ts b/app/actions/remote/user.ts index 52b685e4d5..7399116e25 100644 --- a/app/actions/remote/user.ts +++ b/app/actions/remote/user.ts @@ -121,7 +121,7 @@ export async function fetchProfilesPerChannels(serverUrl: string, channelIds: st // let's filter those channels that we already have the users const membersCount = await getMembersCountByChannelsId(database, channelIds); - const channelsToFetch = channelIds.filter((c) => membersCount[c] <= 1); + const channelsToFetch = channelIds.filter((c) => membersCount[c] <= 1 || membersCount[c] > 2); // Batch fetching profiles per channel by chunks of 50 const channels = chunk(channelsToFetch, 50); diff --git a/app/components/channel_icon/index.tsx b/app/components/channel_icon/index.tsx index 54b832c8ce..1df2a12b27 100644 --- a/app/components/channel_icon/index.tsx +++ b/app/components/channel_icon/index.tsx @@ -178,7 +178,7 @@ const ChannelIcon = ({ style={[styles.group, unreadGroup, activeGroup, {fontSize}]} testID={`${testID}.gm_member_count`} > - {membersCount} + {membersCount - 1} ); diff --git a/app/components/channel_item/__snapshots__/channel_item.test.tsx.snap b/app/components/channel_item/__snapshots__/channel_item.test.tsx.snap index ff68ef6d85..ae6f9a82cc 100644 --- a/app/components/channel_item/__snapshots__/channel_item.test.tsx.snap +++ b/app/components/channel_item/__snapshots__/channel_item.test.tsx.snap @@ -79,46 +79,23 @@ exports[`components/channel_list/categories/body/channel_item should match snaps ] } > - - - 1 - - + testID="undefined.public" + /> { it('should match snapshot', () => { const wrapper = renderWithIntlAndTheme( { channel={{displayName: 'Hello!', type: 'G', shared: false, name: 'hello', deleteAt: 0} as ChannelModel} hasDraft={true} isActive={false} + membersCount={3} myChannel={myChannel} isMuted={false} collapsed={false} diff --git a/app/components/channel_item/channel_item.tsx b/app/components/channel_item/channel_item.tsx index a0290793f9..b832b3f91f 100644 --- a/app/components/channel_item/channel_item.tsx +++ b/app/components/channel_item/channel_item.tsx @@ -29,6 +29,7 @@ type Props = { isInfo?: boolean; isMuted: boolean; isVisible: boolean; + membersCount: number; myChannel?: MyChannelModel; onPress: (channelId: string) => void; teamDisplayName?: string; @@ -115,7 +116,7 @@ export const textStyle = StyleSheet.create({ const ChannelListItem = ({ channel, collapsed, currentUserId, hasDraft, - isActive, isInfo, isMuted, isVisible, + isActive, isInfo, isMuted, isVisible, membersCount, myChannel, onPress, teamDisplayName, testID}: Props) => { const {formatMessage} = useIntl(); const theme = useTheme(); @@ -151,13 +152,6 @@ const ChannelListItem = ({ onPress(myChannel?.id || channel.id); }, [channel.id, myChannel?.id]); - const membersCount = useMemo(() => { - if (channel.type === General.GM_CHANNEL) { - return channel.name.split(',').length; - } - return 0; - }, [channel.type, channel.name]); - const textStyles = useMemo(() => [ isBright ? textStyle.bright : textStyle.regular, styles.text, diff --git a/app/components/channel_item/index.ts b/app/components/channel_item/index.ts index 0b8ce6ba9d..e9a877b6fb 100644 --- a/app/components/channel_item/index.ts +++ b/app/components/channel_item/index.ts @@ -7,7 +7,7 @@ import React from 'react'; import {of as of$, combineLatest} from 'rxjs'; import {switchMap, distinctUntilChanged} from 'rxjs/operators'; -import {Preferences} from '@constants'; +import {General, Preferences} from '@constants'; import {getPreferenceAsBool} from '@helpers/api/preference'; import {observeMyChannel} from '@queries/servers/channel'; import {queryDraft} from '@queries/servers/drafts'; @@ -79,6 +79,11 @@ const enhance = withObservables(['channel', 'isUnreads', 'showTeamName'], ({chan ); } + let membersCount = of$(0); + if (channel.type === General.GM_CHANNEL) { + membersCount = channel.members.observeCount(); + } + return { channel: channel.observe(), currentUserId, @@ -86,6 +91,7 @@ const enhance = withObservables(['channel', 'isUnreads', 'showTeamName'], ({chan isActive, isMuted, isVisible, + membersCount, myChannel, teamDisplayName, }; diff --git a/app/helpers/database/index.ts b/app/helpers/database/index.ts index e84946cb4d..737b31f4ca 100644 --- a/app/helpers/database/index.ts +++ b/app/helpers/database/index.ts @@ -11,19 +11,17 @@ export const extractRecordsForTable = (records: Model[], tableName: string): return records.filter((r) => r.constructor.table === tableName) as T[]; }; -export function extractChannelDisplayName(raw: Pick, record?: ChannelModel) { +export function extractChannelDisplayName(raw: Pick, record?: ChannelModel) { let displayName = ''; switch (raw.type) { case General.DM_CHANNEL: displayName = raw.display_name.trim() || record?.displayName || ''; break; case General.GM_CHANNEL: { - const rawMembers = raw.display_name.split(',').length; - const recordMembers = record?.displayName.split(',').length || rawMembers; - if (recordMembers < rawMembers && record?.displayName) { - displayName = record.displayName; - } else { + if (raw.fake) { displayName = raw.display_name; + } else { + displayName = record?.displayName || raw.display_name; } break; }