avoid sleep, retry device token at login if previously failed

This commit is contained in:
Roland Osborne 2024-01-16 13:07:55 -08:00
parent da5b12d0e7
commit 993434b96c
2 changed files with 11 additions and 17 deletions

View File

@ -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)

View File

@ -60,7 +60,7 @@ export function Channels({ cardId, channelId, navigation, openConversation, dmCh
),
});
}
}, [navigation, state.allowUnsealed]);
}, [navigation, state.sealable, state.allowUnsealed]);
return (
<View style={styles.container}>