From 993434b96c131b51957c7c346ad8a551a4b941b6 Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Tue, 16 Jan 2024 13:07:55 -0800 Subject: [PATCH] avoid sleep, retry device token at login if previously failed --- app/mobile/src/context/useAppContext.hook.js | 26 ++++++++------------ app/mobile/src/session/channels/Channels.jsx | 2 +- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/app/mobile/src/context/useAppContext.hook.js b/app/mobile/src/context/useAppContext.hook.js index 730277c2..8d10c46d 100644 --- a/app/mobile/src/context/useAppContext.hook.js +++ b/app/mobile/src/context/useAppContext.hook.js @@ -44,23 +44,14 @@ export function useAppContext() { setState((s) => ({ ...s, ...value })) } - const setFcmToken = async () => { + const setDeviceToken = async () => { if (!deviceToken.current) { - try { - const token = await messaging().getToken(); - if (!token) { - throw new Error('null push token'); - } - deviceToken.current = token; - pushType.current = "fcm"; - } - catch (err) { - console.log(err); - await new Promise(r => setTimeout(r, 2000)); - const token = await messaging().getToken(); - deviceToken.current = token; - pushType.current = "fcm"; + const token = await messaging().getToken(); + if (!token) { + throw new Error('null push token'); } + deviceToken.current = token; + pushType.current = "fcm"; } } @@ -74,7 +65,7 @@ export function useAppContext() { (async () => { try { - await setFcmToken(); + await setDeviceToken(); } catch (err) { console.log(err); @@ -127,6 +118,7 @@ export function useAppContext() { if (!init.current || access.current) { throw new Error('invalid session state'); } + setDeviceToken(); updateState({ loggedOut: false }); await addAccount(server, username, password, token); const session = await setLogin(username, server, password, getApplicationName(), getVersion(), getDeviceId(), deviceToken.current, pushType.current, notifications) @@ -141,6 +133,7 @@ export function useAppContext() { if (!init.current || access.current) { throw new Error('invalid session state'); } + setDeviceToken(); updateState({ loggedOut: false }); const session = await setAccountAccess(server, token, getApplicationName(), getVersion(), getDeviceId(), deviceToken.current, pushType.current, notifications); access.current = { loginTimestamp: session.created, server, token: session.appToken, guid: session.guid }; @@ -154,6 +147,7 @@ export function useAppContext() { if (!init.current || access.current) { throw new Error('invalid session state'); } + setDeviceToken(); updateState({ loggedOut: false }); const acc = username.includes('/') ? username.split('/') : username.split('@'); const session = await setLogin(acc[0], acc[1], password, getApplicationName(), getVersion(), getDeviceId(), deviceToken.current, pushType.current, notifications) diff --git a/app/mobile/src/session/channels/Channels.jsx b/app/mobile/src/session/channels/Channels.jsx index ae2f63b1..ad6ac4e6 100644 --- a/app/mobile/src/session/channels/Channels.jsx +++ b/app/mobile/src/session/channels/Channels.jsx @@ -60,7 +60,7 @@ export function Channels({ cardId, channelId, navigation, openConversation, dmCh ), }); } - }, [navigation, state.allowUnsealed]); + }, [navigation, state.sealable, state.allowUnsealed]); return (