fix: auto-create READER links when enabling a source channel
All checks were successful
continuous-integration/drone/push Build is passing

toggleChannelActive only flipped isActive but never created the
AccountChannelMap READER link needed by the worker. Channels enabled
via the toggle (rather than the channel picker) were invisible to the
scanner. Now auto-creates READER links for all active authenticated
accounts when a SOURCE channel is enabled.

Also ran a one-time DB fix to backfill READER links for the 14 active
channels that were missing them.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-23 23:29:52 +01:00
parent bd358a134b
commit 9bc9271f11

View File

@@ -231,11 +231,35 @@ export async function toggleChannelActive(id: string): Promise<ActionResult> {
const existing = await prisma.telegramChannel.findUnique({ where: { id } });
if (!existing) return { success: false, error: "Channel not found" };
const newActive = !existing.isActive;
try {
await prisma.telegramChannel.update({
where: { id },
data: { isActive: !existing.isActive },
data: { isActive: newActive },
});
// When enabling a SOURCE channel, auto-create READER links for all
// active authenticated accounts so the worker can scan it.
// Without this, toggling a channel active without going through the
// channel picker leaves it with no AccountChannelMap READER link.
if (newActive && existing.type === "SOURCE") {
const accounts = await prisma.telegramAccount.findMany({
where: { isActive: true, authState: "AUTHENTICATED" },
select: { id: true },
});
for (const account of accounts) {
try {
await prisma.accountChannelMap.create({
data: { accountId: account.id, channelId: id, role: "READER" },
});
} catch {
// Already linked — ignore unique constraint violation
}
}
}
revalidatePath(REVALIDATE_PATH);
return { success: true, data: undefined };
} catch {