fix(notifications): auto-add channel type to alert rules on Telegram pairing

claimPairingToken stored the chatId and verified the channel but never
updated the user's existing alertRules.channels array. The relay's
verifiedChannels filter requires rule.channels.includes(channelType),
so Telegram was silently excluded even though the channel record existed
and the UI showed CONNECTED.

Mirrors the reverse logic already in deleteChannelForUser which removes
the channel type from all rules on disconnect.

User action required after deploy: remove Telegram in UI and re-pair
once — this triggers claimPairingToken which now adds 'telegram' to
all existing alert rules automatically.
This commit is contained in:
Elie Habib
2026-04-01 16:02:35 +04:00
parent 5b0cf24ba1
commit 0f375e50df

View File

@@ -332,6 +332,19 @@ export const claimPairingToken = mutation({
await ctx.db.insert("notificationChannels", doc);
}
// Add 'telegram' to all existing alert rules for this user so alerts
// are delivered immediately without requiring a manual rule edit.
// Mirrors the reverse logic in deleteChannelForUser which removes the channel.
const rules = await ctx.db
.query("alertRules")
.withIndex("by_user", (q) => q.eq("userId", record.userId))
.collect();
for (const rule of rules) {
if (!rule.channels.includes("telegram")) {
await ctx.db.patch(rule._id, { channels: [...rule.channels, "telegram"] });
}
}
return { ok: true, reason: null };
},
});