From 997984c99401e6a8fb3948a7999ad76239f56cdd Mon Sep 17 00:00:00 2001 From: Andrew Rosiclair Date: Mon, 1 Apr 2024 15:23:25 -0400 Subject: [PATCH 1/5] remove background refresh --- .../backgroundRefresh/index.android.ts | 50 ------------------- .../backgroundRefresh/index.ts | 11 ---- .../backgroundRefresh/types.ts | 3 -- ...bscribeToReportCommentPushNotifications.ts | 3 -- 4 files changed, 67 deletions(-) delete mode 100644 src/libs/Notification/PushNotification/backgroundRefresh/index.android.ts delete mode 100644 src/libs/Notification/PushNotification/backgroundRefresh/index.ts delete mode 100644 src/libs/Notification/PushNotification/backgroundRefresh/types.ts diff --git a/src/libs/Notification/PushNotification/backgroundRefresh/index.android.ts b/src/libs/Notification/PushNotification/backgroundRefresh/index.android.ts deleted file mode 100644 index 15c26b8648fe..000000000000 --- a/src/libs/Notification/PushNotification/backgroundRefresh/index.android.ts +++ /dev/null @@ -1,50 +0,0 @@ -import Onyx from 'react-native-onyx'; -import Log from '@libs/Log'; -import Visibility from '@libs/Visibility'; -import * as App from '@userActions/App'; -import CONST from '@src/CONST'; -import ONYXKEYS from '@src/ONYXKEYS'; -import type BackgroundRefresh from './types'; - -function getLastOnyxUpdateID(): Promise { - return new Promise((resolve) => { - const connectionID = Onyx.connect({ - key: ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, - callback: (lastUpdateIDAppliedToClient) => { - Onyx.disconnect(connectionID); - resolve(lastUpdateIDAppliedToClient); - }, - }); - }); -} - -/** - * Runs our reconnectApp action if the app is in the background. - * - * We use this to refresh the app in the background after receiving a push notification (native only). Since the full app - * wakes on iOS and by extension runs reconnectApp already, this is a no-op on everything but Android. - */ -const backgroundRefresh: BackgroundRefresh = () => { - if (Visibility.isVisible()) { - return; - } - - getLastOnyxUpdateID() - .then((lastUpdateIDAppliedToClient) => { - /** - * ReconnectApp waits on the isReadyToOpenApp promise to resolve and this normally only resolves when the LHN is rendered. - * However on Android, this callback is run in the background using a Headless JS task which does not render the React UI, - * so we must manually run confirmReadyToOpenApp here instead. - * - * See more here: https://reactnative.dev/docs/headless-js-android - */ - App.confirmReadyToOpenApp(); - Log.info('[PushNotification] Sending ReconnectApp'); - App.reconnectApp(lastUpdateIDAppliedToClient ?? undefined); - }) - .catch((error) => { - Log.alert(`${CONST.ERROR.ENSURE_BUGBOT} [PushNotification] backgroundRefresh failed. This should never happen.`, {error}); - }); -}; - -export default backgroundRefresh; diff --git a/src/libs/Notification/PushNotification/backgroundRefresh/index.ts b/src/libs/Notification/PushNotification/backgroundRefresh/index.ts deleted file mode 100644 index 54fd14e219a9..000000000000 --- a/src/libs/Notification/PushNotification/backgroundRefresh/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -import type BackgroundRefresh from './types'; - -/** - * Runs our reconnectApp action if the app is in the background. - * - * We use this to refresh the app in the background after receiving a push notification (native only). Since the full app - * wakes on iOS and by extension runs reconnectApp already, this is a no-op on everything but Android. - */ -const backgroundRefresh: BackgroundRefresh = () => {}; - -export default backgroundRefresh; diff --git a/src/libs/Notification/PushNotification/backgroundRefresh/types.ts b/src/libs/Notification/PushNotification/backgroundRefresh/types.ts deleted file mode 100644 index d3d1ee44a1fd..000000000000 --- a/src/libs/Notification/PushNotification/backgroundRefresh/types.ts +++ /dev/null @@ -1,3 +0,0 @@ -type BackgroundRefresh = () => void; - -export default BackgroundRefresh; diff --git a/src/libs/Notification/PushNotification/subscribeToReportCommentPushNotifications.ts b/src/libs/Notification/PushNotification/subscribeToReportCommentPushNotifications.ts index 7f86d3ddb9ac..71f68d69acc7 100644 --- a/src/libs/Notification/PushNotification/subscribeToReportCommentPushNotifications.ts +++ b/src/libs/Notification/PushNotification/subscribeToReportCommentPushNotifications.ts @@ -12,7 +12,6 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type {OnyxUpdatesFromServer} from '@src/types/onyx'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; -import backgroundRefresh from './backgroundRefresh'; import PushNotification from './index'; let lastVisitedPath: string | undefined; @@ -51,8 +50,6 @@ export default function subscribeToReportCommentPushNotifications() { } else { Log.hmmm("[PushNotification] Didn't apply onyx updates because some data is missing", {lastUpdateID, previousUpdateID, onyxDataCount: onyxData?.length ?? 0}); } - - backgroundRefresh(); }); // Open correct report when push notification is clicked From c5550040d139738d807c63162f372573e581c3f5 Mon Sep 17 00:00:00 2001 From: Andrew Rosiclair Date: Mon, 1 Apr 2024 15:42:31 -0400 Subject: [PATCH 2/5] add GetMissingOnyxMessagesForPushNotification --- src/libs/API/types.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index fd84e65c028e..6f7a9f8420ff 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -474,6 +474,7 @@ const SIDE_EFFECT_REQUEST_COMMANDS = { OPEN_OLD_DOT_LINK: 'OpenOldDotLink', REVEAL_EXPENSIFY_CARD_DETAILS: 'RevealExpensifyCardDetails', GET_MISSING_ONYX_MESSAGES: 'GetMissingOnyxMessages', + GET_MISSING_ONYX_MESSAGES_FOR_PUSH_NOTIFICATION: 'GetMissingOnyxMessagesForPushNotification', JOIN_POLICY_VIA_INVITE_LINK: 'JoinWorkspaceViaInviteLink', RECONNECT_APP: 'ReconnectApp', } as const; @@ -486,6 +487,7 @@ type SideEffectRequestCommandParameters = { [SIDE_EFFECT_REQUEST_COMMANDS.OPEN_OLD_DOT_LINK]: Parameters.OpenOldDotLinkParams; [SIDE_EFFECT_REQUEST_COMMANDS.REVEAL_EXPENSIFY_CARD_DETAILS]: Parameters.RevealExpensifyCardDetailsParams; [SIDE_EFFECT_REQUEST_COMMANDS.GET_MISSING_ONYX_MESSAGES]: Parameters.GetMissingOnyxMessagesParams; + [SIDE_EFFECT_REQUEST_COMMANDS.GET_MISSING_ONYX_MESSAGES_FOR_PUSH_NOTIFICATION]: Parameters.GetMissingOnyxMessagesParams; [SIDE_EFFECT_REQUEST_COMMANDS.JOIN_POLICY_VIA_INVITE_LINK]: Parameters.JoinPolicyInviteLinkParams; [SIDE_EFFECT_REQUEST_COMMANDS.RECONNECT_APP]: Parameters.ReconnectAppParams; }; From 837eb25c73ea653ce82c321009c017d6f7fcae79 Mon Sep 17 00:00:00 2001 From: Andrew Rosiclair Date: Mon, 1 Apr 2024 15:44:39 -0400 Subject: [PATCH 3/5] use GetMissingOnyxMessagesForPushNotification when filling onyx update gaps from push notifications --- src/libs/actions/App.ts | 6 ++++-- src/libs/actions/OnyxUpdateManager.ts | 2 +- src/types/onyx/OnyxUpdatesFromServer.ts | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/libs/actions/App.ts b/src/libs/actions/App.ts index 3a9ab4c52b3c..63bec7aaab80 100644 --- a/src/libs/actions/App.ts +++ b/src/libs/actions/App.ts @@ -29,6 +29,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type {Route} from '@src/ROUTES'; import ROUTES from '@src/ROUTES'; import type * as OnyxTypes from '@src/types/onyx'; +import type {OnyxUpdatesType} from '@src/types/onyx/OnyxUpdatesFromServer'; import type {SelectedTimezone} from '@src/types/onyx/PersonalDetails'; import type {OnyxData} from '@src/types/onyx/Request'; import * as Policy from './Policy'; @@ -278,9 +279,10 @@ function finalReconnectAppAfterActivatingReliableUpdates(): Promise { +function getMissingOnyxUpdates(updateIDFrom = 0, updateIDTo: number | string = 0, updateType: OnyxUpdatesType = 'pusher'): Promise { console.debug(`[OnyxUpdates] Fetching missing updates updateIDFrom: ${updateIDFrom} and updateIDTo: ${updateIDTo}`); + const command = updateType === 'airship' ? SIDE_EFFECT_REQUEST_COMMANDS.GET_MISSING_ONYX_MESSAGES_FOR_PUSH_NOTIFICATION : SIDE_EFFECT_REQUEST_COMMANDS.GET_MISSING_ONYX_MESSAGES; const parameters: GetMissingOnyxMessagesParams = { updateIDFrom, updateIDTo, @@ -290,7 +292,7 @@ function getMissingOnyxUpdates(updateIDFrom = 0, updateIDTo: number | string = 0 // DO NOT FOLLOW THIS PATTERN!!!!! // It was absolutely necessary in order to block OnyxUpdates while fetching the missing updates from the server or else the udpates aren't applied in the proper order. // eslint-disable-next-line rulesdir/no-api-side-effects-method - return API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.GET_MISSING_ONYX_MESSAGES, parameters, getOnyxDataForOpenOrReconnect()); + return API.makeRequestWithSideEffects(command, parameters, getOnyxDataForOpenOrReconnect()); } /** diff --git a/src/libs/actions/OnyxUpdateManager.ts b/src/libs/actions/OnyxUpdateManager.ts index 9c6f30cc5e9e..9b02a7ef2875 100644 --- a/src/libs/actions/OnyxUpdateManager.ts +++ b/src/libs/actions/OnyxUpdateManager.ts @@ -82,7 +82,7 @@ export default () => { previousUpdateIDFromServer, lastUpdateIDAppliedToClient, }); - canUnpauseQueuePromise = App.getMissingOnyxUpdates(lastUpdateIDAppliedToClient, previousUpdateIDFromServer); + canUnpauseQueuePromise = App.getMissingOnyxUpdates(lastUpdateIDAppliedToClient, previousUpdateIDFromServer, value.type); } canUnpauseQueuePromise.finally(() => { diff --git a/src/types/onyx/OnyxUpdatesFromServer.ts b/src/types/onyx/OnyxUpdatesFromServer.ts index 3c6933da19ba..3c4f5cedd6ce 100644 --- a/src/types/onyx/OnyxUpdatesFromServer.ts +++ b/src/types/onyx/OnyxUpdatesFromServer.ts @@ -13,7 +13,7 @@ type OnyxUpdateEvent = { }; type OnyxUpdatesFromServer = { - type: 'https' | 'pusher' | 'airship'; + type: OnyxUpdatesType; lastUpdateID: number | string; previousUpdateID: number | string; request?: Request; @@ -21,4 +21,6 @@ type OnyxUpdatesFromServer = { updates?: OnyxUpdateEvent[]; }; -export type {OnyxUpdatesFromServer, OnyxUpdateEvent, OnyxServerUpdate}; +type OnyxUpdatesType = 'https' | 'pusher' | 'airship'; + +export type {OnyxUpdatesFromServer, OnyxUpdateEvent, OnyxServerUpdate, OnyxUpdatesType}; From 948104d4e10e2ca84a181ad98df36c12db412492 Mon Sep 17 00:00:00 2001 From: Andrew Rosiclair Date: Wed, 3 Apr 2024 13:51:58 -0400 Subject: [PATCH 4/5] Revert "use GetMissingOnyxMessagesForPushNotification when filling onyx update gaps from push notifications" This reverts commit 837eb25c73ea653ce82c321009c017d6f7fcae79. --- src/libs/actions/App.ts | 6 ++---- src/libs/actions/OnyxUpdateManager.ts | 2 +- src/types/onyx/OnyxUpdatesFromServer.ts | 6 ++---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/libs/actions/App.ts b/src/libs/actions/App.ts index 63bec7aaab80..3a9ab4c52b3c 100644 --- a/src/libs/actions/App.ts +++ b/src/libs/actions/App.ts @@ -29,7 +29,6 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type {Route} from '@src/ROUTES'; import ROUTES from '@src/ROUTES'; import type * as OnyxTypes from '@src/types/onyx'; -import type {OnyxUpdatesType} from '@src/types/onyx/OnyxUpdatesFromServer'; import type {SelectedTimezone} from '@src/types/onyx/PersonalDetails'; import type {OnyxData} from '@src/types/onyx/Request'; import * as Policy from './Policy'; @@ -279,10 +278,9 @@ function finalReconnectAppAfterActivatingReliableUpdates(): Promise { +function getMissingOnyxUpdates(updateIDFrom = 0, updateIDTo: number | string = 0): Promise { console.debug(`[OnyxUpdates] Fetching missing updates updateIDFrom: ${updateIDFrom} and updateIDTo: ${updateIDTo}`); - const command = updateType === 'airship' ? SIDE_EFFECT_REQUEST_COMMANDS.GET_MISSING_ONYX_MESSAGES_FOR_PUSH_NOTIFICATION : SIDE_EFFECT_REQUEST_COMMANDS.GET_MISSING_ONYX_MESSAGES; const parameters: GetMissingOnyxMessagesParams = { updateIDFrom, updateIDTo, @@ -292,7 +290,7 @@ function getMissingOnyxUpdates(updateIDFrom = 0, updateIDTo: number | string = 0 // DO NOT FOLLOW THIS PATTERN!!!!! // It was absolutely necessary in order to block OnyxUpdates while fetching the missing updates from the server or else the udpates aren't applied in the proper order. // eslint-disable-next-line rulesdir/no-api-side-effects-method - return API.makeRequestWithSideEffects(command, parameters, getOnyxDataForOpenOrReconnect()); + return API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.GET_MISSING_ONYX_MESSAGES, parameters, getOnyxDataForOpenOrReconnect()); } /** diff --git a/src/libs/actions/OnyxUpdateManager.ts b/src/libs/actions/OnyxUpdateManager.ts index 9b02a7ef2875..9c6f30cc5e9e 100644 --- a/src/libs/actions/OnyxUpdateManager.ts +++ b/src/libs/actions/OnyxUpdateManager.ts @@ -82,7 +82,7 @@ export default () => { previousUpdateIDFromServer, lastUpdateIDAppliedToClient, }); - canUnpauseQueuePromise = App.getMissingOnyxUpdates(lastUpdateIDAppliedToClient, previousUpdateIDFromServer, value.type); + canUnpauseQueuePromise = App.getMissingOnyxUpdates(lastUpdateIDAppliedToClient, previousUpdateIDFromServer); } canUnpauseQueuePromise.finally(() => { diff --git a/src/types/onyx/OnyxUpdatesFromServer.ts b/src/types/onyx/OnyxUpdatesFromServer.ts index 3c4f5cedd6ce..3c6933da19ba 100644 --- a/src/types/onyx/OnyxUpdatesFromServer.ts +++ b/src/types/onyx/OnyxUpdatesFromServer.ts @@ -13,7 +13,7 @@ type OnyxUpdateEvent = { }; type OnyxUpdatesFromServer = { - type: OnyxUpdatesType; + type: 'https' | 'pusher' | 'airship'; lastUpdateID: number | string; previousUpdateID: number | string; request?: Request; @@ -21,6 +21,4 @@ type OnyxUpdatesFromServer = { updates?: OnyxUpdateEvent[]; }; -type OnyxUpdatesType = 'https' | 'pusher' | 'airship'; - -export type {OnyxUpdatesFromServer, OnyxUpdateEvent, OnyxServerUpdate, OnyxUpdatesType}; +export type {OnyxUpdatesFromServer, OnyxUpdateEvent, OnyxServerUpdate}; From ad4ec77a5082dfbc826909c867fcddd4f37fa60c Mon Sep 17 00:00:00 2001 From: Andrew Rosiclair Date: Wed, 3 Apr 2024 13:52:07 -0400 Subject: [PATCH 5/5] Revert "add GetMissingOnyxMessagesForPushNotification" This reverts commit c5550040d139738d807c63162f372573e581c3f5. --- src/libs/API/types.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index 6f7a9f8420ff..fd84e65c028e 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -474,7 +474,6 @@ const SIDE_EFFECT_REQUEST_COMMANDS = { OPEN_OLD_DOT_LINK: 'OpenOldDotLink', REVEAL_EXPENSIFY_CARD_DETAILS: 'RevealExpensifyCardDetails', GET_MISSING_ONYX_MESSAGES: 'GetMissingOnyxMessages', - GET_MISSING_ONYX_MESSAGES_FOR_PUSH_NOTIFICATION: 'GetMissingOnyxMessagesForPushNotification', JOIN_POLICY_VIA_INVITE_LINK: 'JoinWorkspaceViaInviteLink', RECONNECT_APP: 'ReconnectApp', } as const; @@ -487,7 +486,6 @@ type SideEffectRequestCommandParameters = { [SIDE_EFFECT_REQUEST_COMMANDS.OPEN_OLD_DOT_LINK]: Parameters.OpenOldDotLinkParams; [SIDE_EFFECT_REQUEST_COMMANDS.REVEAL_EXPENSIFY_CARD_DETAILS]: Parameters.RevealExpensifyCardDetailsParams; [SIDE_EFFECT_REQUEST_COMMANDS.GET_MISSING_ONYX_MESSAGES]: Parameters.GetMissingOnyxMessagesParams; - [SIDE_EFFECT_REQUEST_COMMANDS.GET_MISSING_ONYX_MESSAGES_FOR_PUSH_NOTIFICATION]: Parameters.GetMissingOnyxMessagesParams; [SIDE_EFFECT_REQUEST_COMMANDS.JOIN_POLICY_VIA_INVITE_LINK]: Parameters.JoinPolicyInviteLinkParams; [SIDE_EFFECT_REQUEST_COMMANDS.RECONNECT_APP]: Parameters.ReconnectAppParams; };