Fix sync after sleep mode (#2060)
This commit is contained in:
parent
87062b53ad
commit
403a72312f
@ -6,7 +6,7 @@ import { getActions, getGlobal, withGlobal } from '../../global';
|
|||||||
|
|
||||||
import type { AnimationLevel, LangCode } from '../../types';
|
import type { AnimationLevel, LangCode } from '../../types';
|
||||||
import type {
|
import type {
|
||||||
ApiChat, ApiMessage, ApiUpdateAuthorizationStateType, ApiUpdateConnectionStateType, ApiUser,
|
ApiChat, ApiMessage, ApiUser,
|
||||||
} from '../../api/types';
|
} from '../../api/types';
|
||||||
import type { ApiLimitTypeWithModal, GlobalState } from '../../global/types';
|
import type { ApiLimitTypeWithModal, GlobalState } from '../../global/types';
|
||||||
|
|
||||||
@ -79,8 +79,6 @@ import './Main.scss';
|
|||||||
|
|
||||||
type StateProps = {
|
type StateProps = {
|
||||||
chat?: ApiChat;
|
chat?: ApiChat;
|
||||||
connectionState?: ApiUpdateConnectionStateType;
|
|
||||||
authState?: ApiUpdateAuthorizationStateType;
|
|
||||||
lastSyncTime?: number;
|
lastSyncTime?: number;
|
||||||
isLeftColumnOpen: boolean;
|
isLeftColumnOpen: boolean;
|
||||||
isRightColumnOpen: boolean;
|
isRightColumnOpen: boolean;
|
||||||
@ -131,8 +129,6 @@ let notificationInterval: number | undefined;
|
|||||||
let DEBUG_isLogged = false;
|
let DEBUG_isLogged = false;
|
||||||
|
|
||||||
const Main: FC<StateProps> = ({
|
const Main: FC<StateProps> = ({
|
||||||
connectionState,
|
|
||||||
authState,
|
|
||||||
lastSyncTime,
|
lastSyncTime,
|
||||||
isLeftColumnOpen,
|
isLeftColumnOpen,
|
||||||
isRightColumnOpen,
|
isRightColumnOpen,
|
||||||
@ -174,7 +170,6 @@ const Main: FC<StateProps> = ({
|
|||||||
deleteFolderDialogId,
|
deleteFolderDialogId,
|
||||||
}) => {
|
}) => {
|
||||||
const {
|
const {
|
||||||
sync,
|
|
||||||
loadAnimatedEmojis,
|
loadAnimatedEmojis,
|
||||||
loadNotificationSettings,
|
loadNotificationSettings,
|
||||||
loadNotificationExceptions,
|
loadNotificationExceptions,
|
||||||
@ -206,12 +201,6 @@ const Main: FC<StateProps> = ({
|
|||||||
console.log('>>> RENDER MAIN');
|
console.log('>>> RENDER MAIN');
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (connectionState === 'connectionStateReady' && authState === 'authorizationStateReady') {
|
|
||||||
sync();
|
|
||||||
}
|
|
||||||
}, [connectionState, authState, sync]);
|
|
||||||
|
|
||||||
useInterval(checkAppVersion, APP_OUTDATED_TIMEOUT_MS, true);
|
useInterval(checkAppVersion, APP_OUTDATED_TIMEOUT_MS, true);
|
||||||
|
|
||||||
// Initial API calls
|
// Initial API calls
|
||||||
@ -502,7 +491,6 @@ export default memo(withGlobal(
|
|||||||
animationLevel, language, wasTimeFormatSetManually,
|
animationLevel, language, wasTimeFormatSetManually,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
connectionState,
|
|
||||||
botTrustRequest,
|
botTrustRequest,
|
||||||
requestedAttachBotInstall,
|
requestedAttachBotInstall,
|
||||||
requestedAttachBotInChat,
|
requestedAttachBotInChat,
|
||||||
@ -510,7 +498,6 @@ export default memo(withGlobal(
|
|||||||
urlAuth,
|
urlAuth,
|
||||||
webApp,
|
webApp,
|
||||||
safeLinkModalUrl,
|
safeLinkModalUrl,
|
||||||
authState,
|
|
||||||
lastSyncTime,
|
lastSyncTime,
|
||||||
openedStickerSetShortName,
|
openedStickerSetShortName,
|
||||||
openedCustomEmojiSetIds,
|
openedCustomEmojiSetIds,
|
||||||
@ -526,8 +513,6 @@ export default memo(withGlobal(
|
|||||||
const currentUser = global.currentUserId ? selectUser(global, global.currentUserId) : undefined;
|
const currentUser = global.currentUserId ? selectUser(global, global.currentUserId) : undefined;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
connectionState,
|
|
||||||
authState,
|
|
||||||
lastSyncTime,
|
lastSyncTime,
|
||||||
isLeftColumnOpen: global.isLeftColumnShown,
|
isLeftColumnOpen: global.isLeftColumnShown,
|
||||||
isRightColumnOpen: selectIsRightColumnShown(global),
|
isRightColumnOpen: selectIsRightColumnShown(global),
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import { initCache, loadCache } from './cache';
|
|||||||
import { cloneDeep } from '../util/iteratees';
|
import { cloneDeep } from '../util/iteratees';
|
||||||
import { updatePasscodeSettings } from './reducers';
|
import { updatePasscodeSettings } from './reducers';
|
||||||
import { clearStoredSession } from '../util/sessions';
|
import { clearStoredSession } from '../util/sessions';
|
||||||
|
import './sync';
|
||||||
|
|
||||||
initCache();
|
initCache();
|
||||||
|
|
||||||
|
|||||||
15
src/global/sync.ts
Normal file
15
src/global/sync.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
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;
|
||||||
|
});
|
||||||
Loading…
x
Reference in New Issue
Block a user