From fe7a548fef2f6b0b6ea3218f8ba154c97b77bf1d Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Mar 2026 19:27:43 +0100 Subject: [PATCH] fix: add getChat and sync delay after openChat for proper history loading --- worker/src/tdlib/download.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/worker/src/tdlib/download.ts b/worker/src/tdlib/download.ts index e6f5d14..e4bde10 100644 --- a/worker/src/tdlib/download.ts +++ b/worker/src/tdlib/download.ts @@ -154,12 +154,27 @@ export async function getChannelMessages( const photos: TelegramPhoto[] = []; const boundary = lastProcessedMessageId ? Number(lastProcessedMessageId) : null; - // Open the chat so TDLib loads remote messages + // Open the chat so TDLib loads remote messages, then load chat history + // from the server. getChat forces TDLib to fetch chat metadata and + // getChatHistory with from_message_id=0 triggers a server-side fetch. await invokeWithTimeout(client, { _: "openChat", chat_id: Number(chatId), }); + // Force TDLib to load the full chat list which populates chat state + try { + await invokeWithTimeout(client, { + _: "getChat", + chat_id: Number(chatId), + }); + } catch { + // Ignore - chat may already be loaded + } + + // Give TDLib time to sync chat data from the server + await sleep(2000); + let currentFromId = 0; let totalScanned = 0; let pageCount = 0;