From 760de9290f799bd760f18f1cf2f3c041ac3cf832 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 10 Jun 2024 09:05:19 -0600 Subject: [PATCH 1/3] Add user's accountID to the api/ping command --- src/libs/NetworkConnection.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libs/NetworkConnection.ts b/src/libs/NetworkConnection.ts index de064441047aa..86d86318785d8 100644 --- a/src/libs/NetworkConnection.ts +++ b/src/libs/NetworkConnection.ts @@ -91,6 +91,17 @@ Onyx.connect({ }, }); +let accountID = 'unknown'; +Onyx.connect({ + key: ONYXKEYS.SESSION, + callback: (session) => { + if (!session) { + return; + } + accountID = session.accountID; + }, +}); + /** * Set interval to periodically (re)check backend status. * Because backend unreachability might imply lost internet connection, we need to check internet reachability. @@ -107,7 +118,7 @@ function subscribeToBackendAndInternetReachability(): () => void { return; } // Using the API url ensures reachability is tested over internet - fetch(`${CONFIG.EXPENSIFY.DEFAULT_API_ROOT}api/Ping`, { + fetch(`${CONFIG.EXPENSIFY.DEFAULT_API_ROOT}api/Ping?accountID=${accountID}`, { method: 'GET', cache: 'no-cache', }) From 14bd2be037fcbbcde871ef2b9264302bc254ed05 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 10 Jun 2024 09:14:52 -0600 Subject: [PATCH 2/3] Fix TS error --- src/libs/NetworkConnection.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/NetworkConnection.ts b/src/libs/NetworkConnection.ts index 86d86318785d8..769f163a0c696 100644 --- a/src/libs/NetworkConnection.ts +++ b/src/libs/NetworkConnection.ts @@ -91,11 +91,11 @@ Onyx.connect({ }, }); -let accountID = 'unknown'; +let accountID = 0; Onyx.connect({ key: ONYXKEYS.SESSION, callback: (session) => { - if (!session) { + if (!session?.accountID) { return; } accountID = session.accountID; From c0b3c73ebc23eb2097478efc54f31840f81f0fdd Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 10 Jun 2024 09:15:18 -0600 Subject: [PATCH 3/3] Don't log a zero --- src/libs/NetworkConnection.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/NetworkConnection.ts b/src/libs/NetworkConnection.ts index 769f163a0c696..1e1136fb90c8d 100644 --- a/src/libs/NetworkConnection.ts +++ b/src/libs/NetworkConnection.ts @@ -118,7 +118,7 @@ function subscribeToBackendAndInternetReachability(): () => void { return; } // Using the API url ensures reachability is tested over internet - fetch(`${CONFIG.EXPENSIFY.DEFAULT_API_ROOT}api/Ping?accountID=${accountID}`, { + fetch(`${CONFIG.EXPENSIFY.DEFAULT_API_ROOT}api/Ping?accountID=${accountID || 'unknown'}`, { method: 'GET', cache: 'no-cache', })