From 4a44374bb733e99ce51b9bca62a8d1775445cbb6 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Mar 2026 18:20:30 +0100 Subject: [PATCH] fix: call openChat before getChatHistory to load remote messages --- worker/src/tdlib/download.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/worker/src/tdlib/download.ts b/worker/src/tdlib/download.ts index f953bd2..e6f5d14 100644 --- a/worker/src/tdlib/download.ts +++ b/worker/src/tdlib/download.ts @@ -154,6 +154,12 @@ export async function getChannelMessages( const photos: TelegramPhoto[] = []; const boundary = lastProcessedMessageId ? Number(lastProcessedMessageId) : null; + // Open the chat so TDLib loads remote messages + await invokeWithTimeout(client, { + _: "openChat", + chat_id: Number(chatId), + }); + let currentFromId = 0; let totalScanned = 0; let pageCount = 0; @@ -236,6 +242,12 @@ export async function getChannelMessages( await sleep(config.apiDelayMs); } + // Close the chat after scanning + await invokeWithTimeout(client, { + _: "closeChat", + chat_id: Number(chatId), + }).catch(() => {}); // Ignore close errors + log.info( { chatId: chatId.toString(), archives: archives.length, photos: photos.length, totalScanned, pages: pageCount }, "Channel scan complete"