From 6324d648709b495ff5c77ec2b32eeed924f86b50 Mon Sep 17 00:00:00 2001 From: xCyanGrizzly Date: Mon, 22 Jun 2026 01:16:42 +0200 Subject: [PATCH] feat(telegram): expose isForum on ChannelRow and add listChannelTopics ChannelRow now carries isForum so the UI can show the Topics action for forum channels only. listChannelTopics returns per-topic fetch state for a channel from TopicProgress. Co-Authored-By: Claude Opus 4.8 --- src/lib/telegram/admin-queries.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/lib/telegram/admin-queries.ts b/src/lib/telegram/admin-queries.ts index aef6791..fa9f16f 100644 --- a/src/lib/telegram/admin-queries.ts +++ b/src/lib/telegram/admin-queries.ts @@ -41,6 +41,7 @@ export async function listChannels() { telegramId: c.telegramId.toString(), title: c.title, type: c.type, + isForum: c.isForum, isActive: c.isActive, category: c.category, createdAt: c.createdAt.toISOString(), @@ -140,3 +141,24 @@ export async function getUnlinkedChannels(accountId: string) { telegramId: c.telegramId.toString(), })); } + +// ── Channel topic queries ── + +export async function listChannelTopics(channelId: string) { + const rows = await prisma.topicProgress.findMany({ + where: { accountChannelMap: { channelId } }, + orderBy: [{ fetchEnabled: "desc" }, { topicName: "asc" }], + }); + + return rows.map((r) => ({ + id: r.id, + topicId: r.topicId.toString(), + topicName: r.topicName, + fetchEnabled: r.fetchEnabled, + lastScannedAt: r.lastScannedAt?.toISOString() ?? null, + })); +} + +export type ChannelTopicRow = Awaited< + ReturnType +>[number];