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"