From aaf19a44054105aa7ce781b176d64753832099da Mon Sep 17 00:00:00 2001 From: zubiden <19638254+zubiden@users.noreply.github.com> Date: Tue, 29 Jul 2025 14:33:42 +0200 Subject: [PATCH] Cache: Force cache linked monoforum chat with channel (#6077) --- src/global/cache.ts | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/global/cache.ts b/src/global/cache.ts index a80df2b02..e3b32722e 100644 --- a/src/global/cache.ts +++ b/src/global/cache.ts @@ -535,7 +535,7 @@ function reduceChats(global: T): GlobalState['chats'] { }); })); - const idsToSave = unique([ + const unlinkedIdsToSave = [ ...currentUserId ? [currentUserId] : [], ...currentChatIds, ...messagesChatIds, @@ -544,19 +544,34 @@ function reduceChats(global: T): GlobalState['chats'] { ...getOrderedIds(ALL_FOLDER_ID) || [], ...getOrderedIds(SAVED_FOLDER_ID) || [], ...Object.keys(byId), - ]).slice(0, GLOBAL_STATE_CACHE_CHAT_LIST_LIMIT); + ]; + + let idsToSave: string[] = []; + + for (const id of unlinkedIdsToSave) { + const chat = byId[id]; + if (!chat) continue; + + idsToSave.push(id); + + if (chat.linkedMonoforumId) { + idsToSave.push(chat.linkedMonoforumId); + } + } + + idsToSave = unique(idsToSave).slice(0, GLOBAL_STATE_CACHE_CHAT_LIST_LIMIT); return { ...global.chats, similarChannelsById: {}, similarBotsById: {}, isFullyLoaded: {}, - notifyExceptionById: pickTruthy(global.chats.notifyExceptionById, idsToSave), + notifyExceptionById: pickTruthy(global.chats.notifyExceptionById, unlinkedIdsToSave), loadingParameters: INITIAL_GLOBAL_STATE.chats.loadingParameters, - byId: pickTruthy(global.chats.byId, idsToSave), - fullInfoById: pickTruthy(global.chats.fullInfoById, idsToSave), + byId: pickTruthy(global.chats.byId, unlinkedIdsToSave), + fullInfoById: pickTruthy(global.chats.fullInfoById, unlinkedIdsToSave), lastMessageIds: { - all: pickTruthy(global.chats.lastMessageIds.all || {}, idsToSave), + all: pickTruthy(global.chats.lastMessageIds.all || {}, unlinkedIdsToSave), saved: global.chats.lastMessageIds.saved, }, topicsInfoById: pickTruthy(global.chats.topicsInfoById, currentChatIds),