Fix calling missing actions too early (#2066)

This commit is contained in:
Alexander Zinchuk 2022-10-10 14:37:56 +02:00
parent 957819cff4
commit c3a3597b7d
4 changed files with 15 additions and 18 deletions

View File

@ -1,10 +1,11 @@
import {
addActionHandler, getGlobal, setGlobal, getActions,
} from '../../index';
import { addCallback } from '../../../lib/teact/teactn';
import type { ApiChat, ApiMessage } from '../../../api/types';
import { MAIN_THREAD_ID } from '../../../api/types';
import type { Thread } from '../../types';
import type { GlobalState, Thread } from '../../types';
import {
DEBUG, MESSAGE_LIST_SLICE, SERVICE_NOTIFICATIONS_USER_ID,
@ -205,3 +206,15 @@ function loadTopMessages(chat: ApiChat) {
limit: MESSAGE_LIST_SLICE,
});
}
let previousGlobal: GlobalState | undefined;
// RAF can be unreliable when device goes into sleep mode, so sync logic is handled outside any component
addCallback((global: GlobalState) => {
const { connectionState, authState } = global;
if (previousGlobal?.connectionState === connectionState && previousGlobal?.authState === authState) return;
if (connectionState === 'connectionStateReady' && authState === 'authorizationStateReady') {
getActions().sync();
}
previousGlobal = global;
});

View File

@ -6,7 +6,6 @@ import { initCache, loadCache } from './cache';
import { cloneDeep } from '../util/iteratees';
import { updatePasscodeSettings } from './reducers';
import { clearStoredSession } from '../util/sessions';
import './sync';
initCache();

View File

@ -1,15 +0,0 @@
import { getActions } from '.';
import { addCallback, getGlobal } from '../lib/teact/teactn';
import type { GlobalState } from './types';
let previousGlobal = getGlobal();
// RAF can be unreliable when device goes into sleep mode, so sync logic is handled outside any component
addCallback((global: GlobalState) => {
const { connectionState, authState } = global;
if (previousGlobal.connectionState === connectionState && previousGlobal.authState === authState) return;
if (connectionState === 'connectionStateReady' && authState === 'authorizationStateReady') {
getActions().sync();
}
previousGlobal = global;
});

View File

@ -72,7 +72,7 @@ if (IS_SERVICE_WORKER_SUPPORTED) {
}
if (!IS_IOS && !IS_ANDROID && !IS_TEST) {
getActions().showDialog({ data: { message: 'SERVICE_WORKER_DISABLED', hasErrorKey: true } });
getActions().showDialog?.({ data: { message: 'SERVICE_WORKER_DISABLED', hasErrorKey: true } });
}
}
} catch (err) {