fix(topics): handle TDLib 1.8.64 renamed forum-topic fields

After the TDLib upgrade in 18a0efb, getForumTopicList returned 0 topics
for every forum channel. Confirmed in production logs:

  "title":"Model Printing Emporium","topicCount":0
  "title":"GB_Butler_Bot2","topicCount":0
  "title":"Darnascus 2 : Flamigos Miniatures","topicCount":0

Cycle results: messagesScanned=0, zipsFound=0 — main account's entire
ingestion pipeline was a no-op because all source channels are forums.

Root cause: TDLib 1.8.64 renamed three fields without bumping the
breaking-change indicator we'd notice:

  Request  offset_message_thread_id           → offset_forum_topic_id
  Response next_offset_message_thread_id      → next_offset_forum_topic_id
  Response topics[].info.message_thread_id    → topics[].info.forum_topic_id

The old field names became no-ops in the new TDLib, so every request
came back with an empty topic list and the "stuck pagination" detection
correctly bailed out.

Fix: send the new field name on the request side, read both old and
new names on the response side (so a future TDLib version change in
either direction stays handled).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-25 16:18:08 +02:00
parent 04effed825
commit 106700b13f

View File

@@ -64,7 +64,11 @@ export async function getForumTopicList(
const topics: ForumTopic[] = []; const topics: ForumTopic[] = [];
let offsetDate = 0; let offsetDate = 0;
let offsetMessageId = 0; let offsetMessageId = 0;
let offsetMessageThreadId = 0; // TDLib 1.8.64+ renamed `offset_message_thread_id` → `offset_forum_topic_id`
// in the getForumTopics request, and `next_offset_message_thread_id` →
// `next_offset_forum_topic_id` in the response. Individual topic infos
// also moved from `info.message_thread_id` → `info.forum_topic_id`.
let offsetForumTopicId = 0;
let pageCount = 0; let pageCount = 0;
// eslint-disable-next-line no-constant-condition // eslint-disable-next-line no-constant-condition
@@ -80,12 +84,16 @@ export async function getForumTopicList(
const prevOffsetDate = offsetDate; const prevOffsetDate = offsetDate;
const prevOffsetMessageId = offsetMessageId; const prevOffsetMessageId = offsetMessageId;
const prevOffsetMessageThreadId = offsetMessageThreadId; const prevOffsetForumTopicId = offsetForumTopicId;
const result = await invokeWithTimeout<{ const result = await invokeWithTimeout<{
topics?: { topics?: {
info?: { info?: {
// Both names — 1.8.50 used the first, 1.8.64+ uses the second.
// Read both so a future TDLib downgrade or transition build is
// still handled.
message_thread_id?: number; message_thread_id?: number;
forum_topic_id?: number;
name?: string; name?: string;
is_general?: boolean; is_general?: boolean;
}; };
@@ -93,45 +101,49 @@ export async function getForumTopicList(
next_offset_date?: number; next_offset_date?: number;
next_offset_message_id?: number; next_offset_message_id?: number;
next_offset_message_thread_id?: number; next_offset_message_thread_id?: number;
next_offset_forum_topic_id?: number;
}>(client, { }>(client, {
_: "getForumTopics", _: "getForumTopics",
chat_id: Number(chatId), chat_id: Number(chatId),
query: "", query: "",
offset_date: offsetDate, offset_date: offsetDate,
offset_message_id: offsetMessageId, offset_message_id: offsetMessageId,
offset_message_thread_id: offsetMessageThreadId, offset_forum_topic_id: offsetForumTopicId,
limit: 100, limit: 100,
}); });
if (!result.topics || result.topics.length === 0) break; if (!result.topics || result.topics.length === 0) break;
for (const t of result.topics) { for (const t of result.topics) {
if (!t.info?.message_thread_id) continue; const topicId = t.info?.forum_topic_id ?? t.info?.message_thread_id;
if (!topicId) continue;
topics.push({ topics.push({
topicId: BigInt(t.info.message_thread_id), topicId: BigInt(topicId),
name: t.info.is_general ? "General" : (t.info.name ?? "Unnamed"), name: t.info?.is_general ? "General" : (t.info?.name ?? "Unnamed"),
}); });
} }
// Check if there are more pages // Check if there are more pages
const nextForumTopicId =
result.next_offset_forum_topic_id ?? result.next_offset_message_thread_id;
if ( if (
!result.next_offset_date && !result.next_offset_date &&
!result.next_offset_message_id && !result.next_offset_message_id &&
!result.next_offset_message_thread_id !nextForumTopicId
) { ) {
break; break;
} }
offsetDate = result.next_offset_date ?? 0; offsetDate = result.next_offset_date ?? 0;
offsetMessageId = result.next_offset_message_id ?? 0; offsetMessageId = result.next_offset_message_id ?? 0;
offsetMessageThreadId = result.next_offset_message_thread_id ?? 0; offsetForumTopicId = nextForumTopicId ?? 0;
// Stuck detection: if offsets didn't advance, break // Stuck detection: if offsets didn't advance, break
if ( if (
offsetDate === prevOffsetDate && offsetDate === prevOffsetDate &&
offsetMessageId === prevOffsetMessageId && offsetMessageId === prevOffsetMessageId &&
offsetMessageThreadId === prevOffsetMessageThreadId offsetForumTopicId === prevOffsetForumTopicId
) { ) {
log.warn( log.warn(
{ chatId: chatId.toString(), topicCount: topics.length }, { chatId: chatId.toString(), topicCount: topics.length },