Fix online status (#2948)
This commit is contained in:
parent
494b8021f4
commit
55dbc323aa
@ -611,18 +611,6 @@ const NOTIFICATION_INTERVAL = 500;
|
|||||||
addActionHandler('onTabFocusChange', (global, actions, payload): ActionReturnType => {
|
addActionHandler('onTabFocusChange', (global, actions, payload): ActionReturnType => {
|
||||||
const { isBlurred, tabId = getCurrentTabId() } = payload;
|
const { isBlurred, tabId = getCurrentTabId() } = payload;
|
||||||
|
|
||||||
if (!isBlurred) {
|
|
||||||
actions.updateIsOnline(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
const blurredTabTokens = unique(isBlurred
|
|
||||||
? [...global.blurredTabTokens, tabId]
|
|
||||||
: global.blurredTabTokens.filter((t) => t !== tabId));
|
|
||||||
|
|
||||||
if (blurredTabTokens.length === getAllMultitabTokens().length) {
|
|
||||||
actions.updateIsOnline(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isBlurred) {
|
if (isBlurred) {
|
||||||
if (notificationInterval) clearInterval(notificationInterval);
|
if (notificationInterval) clearInterval(notificationInterval);
|
||||||
|
|
||||||
@ -636,9 +624,12 @@ addActionHandler('onTabFocusChange', (global, actions, payload): ActionReturnTyp
|
|||||||
notificationInterval = undefined;
|
notificationInterval = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
global = updateTabState(global, {
|
||||||
|
isBlurred,
|
||||||
|
}, tabId);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...global,
|
...global,
|
||||||
blurredTabTokens,
|
|
||||||
initialUnreadNotifications: isBlurred ? getAllNotificationsCount() : undefined,
|
initialUnreadNotifications: isBlurred ? getAllNotificationsCount() : undefined,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@ -689,14 +680,31 @@ addActionHandler('updatePageTitle', (global, actions, payload): ActionReturnType
|
|||||||
});
|
});
|
||||||
|
|
||||||
let prevIsScreenLocked: boolean | undefined;
|
let prevIsScreenLocked: boolean | undefined;
|
||||||
|
let prevBlurredTabsCount: number = 0;
|
||||||
|
let onlineTimeout: number | undefined;
|
||||||
|
const ONLINE_TIMEOUT = 100;
|
||||||
addCallback((global: GlobalState) => {
|
addCallback((global: GlobalState) => {
|
||||||
// eslint-disable-next-line eslint-multitab-tt/no-getactions-in-actions
|
// eslint-disable-next-line eslint-multitab-tt/no-getactions-in-actions
|
||||||
const { updatePageTitle } = getActions();
|
const { updatePageTitle, updateIsOnline } = getActions();
|
||||||
|
|
||||||
const isLockedUpdated = global.passcode.isScreenLocked !== prevIsScreenLocked;
|
const isLockedUpdated = global.passcode.isScreenLocked !== prevIsScreenLocked;
|
||||||
prevIsScreenLocked = global.passcode.isScreenLocked;
|
const blurredTabsCount = Object.values(global.byTabId).filter((l) => l.isBlurred).length;
|
||||||
|
const isMasterTab = selectTabState(global, getCurrentTabId()).isMasterTab;
|
||||||
|
|
||||||
if (isLockedUpdated) {
|
if (isLockedUpdated) {
|
||||||
updatePageTitle();
|
updatePageTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (blurredTabsCount !== prevBlurredTabsCount && isMasterTab) {
|
||||||
|
if (onlineTimeout) clearTimeout(onlineTimeout);
|
||||||
|
|
||||||
|
onlineTimeout = window.setTimeout(() => {
|
||||||
|
global = getGlobal();
|
||||||
|
const newBlurredTabsCount = Object.values(global.byTabId).filter((l) => l.isBlurred).length;
|
||||||
|
updateIsOnline(newBlurredTabsCount !== getAllMultitabTokens().length);
|
||||||
|
}, ONLINE_TIMEOUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
prevIsScreenLocked = global.passcode.isScreenLocked;
|
||||||
|
prevBlurredTabsCount = blurredTabsCount;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -11,7 +11,6 @@ import { IS_IOS, IS_MAC_OS } from '../util/windowEnvironment';
|
|||||||
|
|
||||||
export const INITIAL_GLOBAL_STATE: GlobalState = {
|
export const INITIAL_GLOBAL_STATE: GlobalState = {
|
||||||
attachMenu: { bots: {} },
|
attachMenu: { bots: {} },
|
||||||
blurredTabTokens: [],
|
|
||||||
passcode: {},
|
passcode: {},
|
||||||
twoFaSettings: {},
|
twoFaSettings: {},
|
||||||
isUpdateAvailable: false,
|
isUpdateAvailable: false,
|
||||||
|
|||||||
@ -176,6 +176,7 @@ export type ChatRequestedTranslations = {
|
|||||||
|
|
||||||
export type TabState = {
|
export type TabState = {
|
||||||
id: number;
|
id: number;
|
||||||
|
isBlurred?: boolean;
|
||||||
isMasterTab: boolean;
|
isMasterTab: boolean;
|
||||||
isInactive?: boolean;
|
isInactive?: boolean;
|
||||||
inviteHash?: string;
|
inviteHash?: string;
|
||||||
@ -552,7 +553,6 @@ export type GlobalState = {
|
|||||||
isSyncing?: boolean;
|
isSyncing?: boolean;
|
||||||
isUpdateAvailable?: boolean;
|
isUpdateAvailable?: boolean;
|
||||||
lastSyncTime?: number;
|
lastSyncTime?: number;
|
||||||
blurredTabTokens: number[];
|
|
||||||
leftColumnWidth?: number;
|
leftColumnWidth?: number;
|
||||||
lastIsChatInfoShown?: boolean;
|
lastIsChatInfoShown?: boolean;
|
||||||
initialUnreadNotifications?: number;
|
initialUnreadNotifications?: number;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user