From a3489d96748a3ff6a281d97ffd6ea8195a05c6ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Espino=20Garc=C3=ADa?= Date: Fri, 2 Dec 2022 14:18:02 +0100 Subject: [PATCH] Start spinner on websocket reconnect (#6815) --- app/actions/remote/entry/common.ts | 5 ++++- app/actions/remote/entry/gql_common.ts | 5 ++++- app/actions/websocket/index.ts | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/actions/remote/entry/common.ts b/app/actions/remote/entry/common.ts index f3f1b833a6..a82fe6d09b 100644 --- a/app/actions/remote/entry/common.ts +++ b/app/actions/remote/entry/common.ts @@ -2,6 +2,7 @@ // See LICENSE.txt for license information. import {Database, Model} from '@nozbe/watermelondb'; +import {DeviceEventEmitter} from 'react-native'; import {fetchMissingDirectChannelsInfo, fetchMyChannelsForTeam, MyChannelsRequest} from '@actions/remote/channel'; import {fetchGroupsForMember} from '@actions/remote/groups'; @@ -13,7 +14,7 @@ import {fetchAllTeams, fetchMyTeams, fetchTeamsChannelsAndUnreadPosts, MyTeamsRe import {syncTeamThreads} from '@actions/remote/thread'; import {autoUpdateTimezone, fetchMe, MyUserRequest, updateAllUsersSince} from '@actions/remote/user'; import {gqlAllChannels} from '@client/graphQL/entry'; -import {General, Preferences, Screens} from '@constants'; +import {Events, General, Preferences, Screens} from '@constants'; import {SYSTEM_IDENTIFIERS} from '@constants/database'; import {PUSH_PROXY_RESPONSE_NOT_AVAILABLE, PUSH_PROXY_RESPONSE_UNKNOWN, PUSH_PROXY_STATUS_NOT_AVAILABLE, PUSH_PROXY_STATUS_UNKNOWN, PUSH_PROXY_STATUS_VERIFIED} from '@constants/push_proxy'; import DatabaseManager from '@database/manager'; @@ -318,6 +319,8 @@ export async function restDeferredAppEntryActions( // defer fetching posts for unread channels on initial team fetchPostsForUnreadChannels(serverUrl, chData.channels, chData.memberships, initialChannelId, true); + } else { + DeviceEventEmitter.emit(Events.FETCHING_POSTS, false); } }, FETCH_UNREADS_TIMEOUT); diff --git a/app/actions/remote/entry/gql_common.ts b/app/actions/remote/entry/gql_common.ts index 6810997385..4fcda9fa42 100644 --- a/app/actions/remote/entry/gql_common.ts +++ b/app/actions/remote/entry/gql_common.ts @@ -2,6 +2,7 @@ // See LICENSE.txt for license information. import {Database} from '@nozbe/watermelondb'; +import {DeviceEventEmitter} from 'react-native'; import {storeConfigAndLicense} from '@actions/local/systems'; import {MyChannelsRequest} from '@actions/remote/channel'; @@ -11,7 +12,7 @@ import {MyTeamsRequest} from '@actions/remote/team'; import {syncTeamThreads} from '@actions/remote/thread'; import {autoUpdateTimezone, updateAllUsersSince} from '@actions/remote/user'; import {gqlEntry, gqlEntryChannels, gqlOtherChannels} from '@client/graphQL/entry'; -import {Preferences} from '@constants'; +import {Events, Preferences} from '@constants'; import DatabaseManager from '@database/manager'; import {getPreferenceValue} from '@helpers/api/preference'; import {selectDefaultTeam} from '@helpers/api/team'; @@ -49,6 +50,8 @@ export async function deferredAppEntryGraphQLActions( if (chData?.channels?.length && chData.memberships?.length) { // defer fetching posts for unread channels on initial team fetchPostsForUnreadChannels(serverUrl, chData.channels, chData.memberships, initialChannelId, true); + } else { + DeviceEventEmitter.emit(Events.FETCHING_POSTS, false); } }, FETCH_UNREADS_TIMEOUT); diff --git a/app/actions/websocket/index.ts b/app/actions/websocket/index.ts index 1af41822f9..d0eb6d799b 100644 --- a/app/actions/websocket/index.ts +++ b/app/actions/websocket/index.ts @@ -137,6 +137,9 @@ async function doReconnect(serverUrl: string) { const currentChannel = await getCurrentChannel(database); const currentActiveServerUrl = await getActiveServerUrl(); + if (serverUrl === currentActiveServerUrl) { + DeviceEventEmitter.emit(Events.FETCHING_POSTS, true); + } const entryData = await entry(serverUrl, currentTeam?.id, currentChannel?.id, lastDisconnectedAt); if ('error' in entryData) { if (serverUrl === currentActiveServerUrl) {