mirror of
https://github.com/danog/telegram-tt.git
synced 2025-01-22 13:21:37 +01:00
Sync: Break out of unwanted chat fetching loops
This commit is contained in:
parent
b366d22575
commit
02a0d2db66
@ -16,7 +16,7 @@ import {
|
|||||||
LOCALIZED_TIPS,
|
LOCALIZED_TIPS,
|
||||||
RE_TG_LINK,
|
RE_TG_LINK,
|
||||||
SERVICE_NOTIFICATIONS_USER_ID,
|
SERVICE_NOTIFICATIONS_USER_ID,
|
||||||
TMP_CHAT_ID, ALL_FOLDER_ID,
|
TMP_CHAT_ID, ALL_FOLDER_ID, DEBUG,
|
||||||
} from '../../../config';
|
} from '../../../config';
|
||||||
import { callApi } from '../../../api/gramjs';
|
import { callApi } from '../../../api/gramjs';
|
||||||
import {
|
import {
|
||||||
@ -42,6 +42,7 @@ import { selectGroupCall } from '../../selectors/calls';
|
|||||||
import { getOrderedIds } from '../../../util/folderManager';
|
import { getOrderedIds } from '../../../util/folderManager';
|
||||||
|
|
||||||
const TOP_CHAT_MESSAGES_PRELOAD_INTERVAL = 100;
|
const TOP_CHAT_MESSAGES_PRELOAD_INTERVAL = 100;
|
||||||
|
const INFINITE_LOOP_MARKER = 100;
|
||||||
|
|
||||||
const runThrottledForLoadTopChats = throttle((cb) => cb(), 3000, true);
|
const runThrottledForLoadTopChats = throttle((cb) => cb(), 3000, true);
|
||||||
const runDebouncedForLoadFullChat = debounce((cb) => cb(), 500, false, true);
|
const runDebouncedForLoadFullChat = debounce((cb) => cb(), 500, false, true);
|
||||||
@ -168,9 +169,25 @@ addReducer('openTipsChat', (global, actions, payload) => {
|
|||||||
addReducer('loadAllChats', (global, actions, payload) => {
|
addReducer('loadAllChats', (global, actions, payload) => {
|
||||||
const listType = payload.listType as 'active' | 'archived';
|
const listType = payload.listType as 'active' | 'archived';
|
||||||
let { shouldReplace, onReplace } = payload;
|
let { shouldReplace, onReplace } = payload;
|
||||||
|
let i = 0;
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
while (shouldReplace || !global.chats.isFullyLoaded[listType]) {
|
while (shouldReplace || !global.chats.isFullyLoaded[listType]) {
|
||||||
|
if (i++ >= INFINITE_LOOP_MARKER) {
|
||||||
|
if (DEBUG) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error('`actions/loadAllChats`: Infinite loop detected');
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
global = getGlobal();
|
||||||
|
|
||||||
|
if (global.connectionState !== 'connectionStateReady' || global.authState !== 'authorizationStateReady') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const listIds = !shouldReplace && global.chats.listIds[listType];
|
const listIds = !shouldReplace && global.chats.listIds[listType];
|
||||||
const oldestChat = listIds
|
const oldestChat = listIds
|
||||||
? listIds
|
? listIds
|
||||||
@ -185,10 +202,8 @@ addReducer('loadAllChats', (global, actions, payload) => {
|
|||||||
|
|
||||||
if (shouldReplace) {
|
if (shouldReplace) {
|
||||||
onReplace?.();
|
onReplace?.();
|
||||||
|
shouldReplace = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
global = getGlobal();
|
|
||||||
shouldReplace = false;
|
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user