Chat List: Fix a case causing infinite loop when loading chats
This commit is contained in:
parent
8979f83542
commit
4b4b9281a7
@ -170,6 +170,10 @@ addActionHandler('loadAllChats', async (global, actions, payload) => {
|
|||||||
let { shouldReplace } = payload;
|
let { shouldReplace } = payload;
|
||||||
let i = 0;
|
let i = 0;
|
||||||
|
|
||||||
|
const getOrderDate = (chat: ApiChat) => {
|
||||||
|
return chat.lastMessage?.date || chat.joinDate;
|
||||||
|
};
|
||||||
|
|
||||||
while (shouldReplace || !getGlobal().chats.isFullyLoaded[listType]) {
|
while (shouldReplace || !getGlobal().chats.isFullyLoaded[listType]) {
|
||||||
if (i++ >= INFINITE_LOOP_MARKER) {
|
if (i++ >= INFINITE_LOOP_MARKER) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
@ -192,15 +196,15 @@ addActionHandler('loadAllChats', async (global, actions, payload) => {
|
|||||||
/* eslint-disable @typescript-eslint/no-loop-func */
|
/* eslint-disable @typescript-eslint/no-loop-func */
|
||||||
.map((id) => global.chats.byId[id])
|
.map((id) => global.chats.byId[id])
|
||||||
.filter((chat) => (
|
.filter((chat) => (
|
||||||
Boolean(chat?.lastMessage)
|
Boolean(chat && getOrderDate(chat))
|
||||||
&& chat.id !== SERVICE_NOTIFICATIONS_USER_ID
|
&& chat.id !== SERVICE_NOTIFICATIONS_USER_ID
|
||||||
&& !selectIsChatPinned(global, chat.id)
|
&& !selectIsChatPinned(global, chat.id)
|
||||||
))
|
))
|
||||||
/* eslint-enable @typescript-eslint/no-loop-func */
|
/* eslint-enable @typescript-eslint/no-loop-func */
|
||||||
.sort((chat1, chat2) => (chat1.lastMessage!.date - chat2.lastMessage!.date))[0]
|
.sort((chat1, chat2) => getOrderDate(chat1)! - getOrderDate(chat2)!)[0]
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
await loadChats(listType, oldestChat?.id, oldestChat?.lastMessage!.date, shouldReplace);
|
await loadChats(listType, oldestChat?.id, oldestChat ? getOrderDate(oldestChat) : undefined, shouldReplace);
|
||||||
|
|
||||||
if (shouldReplace) {
|
if (shouldReplace) {
|
||||||
onReplace?.();
|
onReplace?.();
|
||||||
|
|||||||
@ -235,10 +235,6 @@ export function getChatSlowModeOptions(chat?: ApiChat) {
|
|||||||
return chat.fullInfo.slowMode;
|
return chat.fullInfo.slowMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getChatOrder(chat: ApiChat) {
|
|
||||||
return Math.max(chat.joinDate || 0, chat.draftDate || 0, chat.lastMessage?.date || 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isChatArchived(chat: ApiChat) {
|
export function isChatArchived(chat: ApiChat) {
|
||||||
return chat.folderId === ARCHIVED_FOLDER_ID;
|
return chat.folderId === ARCHIVED_FOLDER_ID;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user