From 5cdcbfb12a8f2647771a6145686f2a1960f0ff4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Espino=20Garc=C3=ADa?= Date: Wed, 22 Feb 2023 10:12:58 +0100 Subject: [PATCH] Fix Group Message member count on GraphQL scenario (#7151) * Fix Group Message member count on GraphQL scenario * Fix lint * Use fetchProfilesInGroupChannels instead of fetchMissingDirectChannelsInfo * Use reduce instead of filter map * Simplify using set in the reduce --- app/actions/remote/entry/common.ts | 10 ++++------ app/actions/remote/entry/gql_common.ts | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/app/actions/remote/entry/common.ts b/app/actions/remote/entry/common.ts index 12b04a26a6..e206ac0b07 100644 --- a/app/actions/remote/entry/common.ts +++ b/app/actions/remote/entry/common.ts @@ -312,13 +312,8 @@ export async function restDeferredAppEntryActions( serverUrl: string, since: number, currentUserId: string, currentUserLocale: string, preferences: PreferenceType[] | undefined, config: ClientConfig, license: ClientLicense | undefined, teamData: MyTeamsRequest, chData: MyChannelsRequest | undefined, initialTeamId?: string, initialChannelId?: string) { - // defer sidebar DM & GM profiles - let channelsToFetchProfiles: Set|undefined; setTimeout(async () => { if (chData?.channels?.length && chData.memberships?.length) { - const directChannels = chData.channels.filter(isDMorGM); - channelsToFetchProfiles = new Set(directChannels); - // defer fetching posts for unread channels on initial team fetchPostsForUnreadChannels(serverUrl, chData.channels, chData.memberships, initialChannelId); } @@ -350,8 +345,11 @@ export async function restDeferredAppEntryActions( // Fetch groups for current user fetchGroupsForMember(serverUrl, currentUserId); + // defer sidebar DM & GM profiles setTimeout(async () => { - if (channelsToFetchProfiles?.size) { + const directChannels = chData?.channels?.filter(isDMorGM); + const channelsToFetchProfiles = new Set(directChannels); + if (channelsToFetchProfiles.size) { const teammateDisplayNameSetting = getTeammateNameDisplaySetting(preferences || [], config.LockTeammateNameDisplay, config.TeammateNameDisplay, license); fetchMissingDirectChannelsInfo(serverUrl, Array.from(channelsToFetchProfiles), currentUserLocale, teammateDisplayNameSetting, currentUserId); } diff --git a/app/actions/remote/entry/gql_common.ts b/app/actions/remote/entry/gql_common.ts index b8f79eb746..805397dc87 100644 --- a/app/actions/remote/entry/gql_common.ts +++ b/app/actions/remote/entry/gql_common.ts @@ -7,9 +7,9 @@ import {fetchPostsForUnreadChannels} from '@actions/remote/post'; import {fetchDataRetentionPolicy} from '@actions/remote/systems'; import {MyTeamsRequest, updateCanJoinTeams} from '@actions/remote/team'; import {syncTeamThreads} from '@actions/remote/thread'; -import {autoUpdateTimezone, updateAllUsersSince} from '@actions/remote/user'; +import {autoUpdateTimezone, fetchProfilesInGroupChannels, updateAllUsersSince} from '@actions/remote/user'; import {gqlEntry, gqlEntryChannels, gqlOtherChannels} from '@client/graphQL/entry'; -import {Preferences} from '@constants'; +import {General, Preferences} from '@constants'; import DatabaseManager from '@database/manager'; import {getPreferenceValue} from '@helpers/api/preference'; import {selectDefaultTeam} from '@helpers/api/team'; @@ -28,6 +28,8 @@ import type ClientError from '@client/rest/error'; import type {Database} from '@nozbe/watermelondb'; import type ChannelModel from '@typings/database/models/servers/channel'; +const FETCH_MISSING_GM_TIMEOUT = 2500; + export async function deferredAppEntryGraphQLActions( serverUrl: string, since: number, @@ -98,6 +100,19 @@ export async function deferredAppEntryGraphQLActions( updateCanJoinTeams(serverUrl); updateAllUsersSince(serverUrl, since); + // defer sidebar GM profiles + setTimeout(async () => { + const gmIds = chData?.channels?.reduce>((acc, v) => { + if (v?.type === General.GM_CHANNEL) { + acc.add(v.id); + } + return acc; + }, new Set()); + if (gmIds?.size) { + fetchProfilesInGroupChannels(serverUrl, Array.from(gmIds)); + } + }, FETCH_MISSING_GM_TIMEOUT); + return {error: undefined}; }