From 5552a9b149209ac67c15aac20810c1b733a971ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Wed, 11 Nov 2026 22:20:09 +0100 Subject: [PATCH] refactor(notifications): drop the channel option that routed nothing The localised dispatch helper accepted a `channel` and copied it into the metadata as `preferredChannel`, which no sender reads. No caller passed it either; every message still fans out across the user's enabled channels. The option, its comment and the test that pinned the copy go. --- .../__tests__/admin-locale.test.ts | 20 ----------------- src/lib/notifications/dispatch-localised.ts | 22 +++---------------- 2 files changed, 3 insertions(+), 39 deletions(-) diff --git a/src/lib/notifications/__tests__/admin-locale.test.ts b/src/lib/notifications/__tests__/admin-locale.test.ts index a0b257125..d611c3ba9 100644 --- a/src/lib/notifications/__tests__/admin-locale.test.ts +++ b/src/lib/notifications/__tests__/admin-locale.test.ts @@ -204,26 +204,6 @@ describe("dispatchLocalisedNotification — pass-through plumbing", () => { ); }); - it("annotates metadata with preferredChannel when channel is supplied", async () => { - vi.mocked(prisma.user.findUnique).mockResolvedValueOnce({ - locale: "en", - } as never); - - await dispatchLocalisedNotification({ - userId: "u-en", - titleKey: "notifications.admin.testTitle", - messageKey: "notifications.admin.testBody", - params: { name: "Test" }, - channel: "telegram", - metadata: { source: "test" }, - }); - - expect(dispatchNotificationMock.mock.calls[0][0].metadata).toEqual({ - source: "test", - preferredChannel: "telegram", - }); - }); - it("does not crash when the locale lookup throws (logs warning, falls back to default)", async () => { vi.mocked(prisma.user.findUnique).mockRejectedValueOnce( new Error("db down"), diff --git a/src/lib/notifications/dispatch-localised.ts b/src/lib/notifications/dispatch-localised.ts index ac3100ac2..5eea44434 100644 --- a/src/lib/notifications/dispatch-localised.ts +++ b/src/lib/notifications/dispatch-localised.ts @@ -21,10 +21,8 @@ * * The default `eventType` is `SYSTEM_ALERT` — the only event type that * predates F21 outside of the medication-reminder lane. Callers that - * need a different event type pass it explicitly; the `channel` option - * is reserved for a future per-channel routing pass and is currently - * a no-op (the dispatcher fans the message across every enabled - * channel as before). + * need a different event type pass it explicitly. The dispatcher fans + * the message across every enabled channel. * * v1.4.28 (R1.2 H5) — the locale lookup previously fired * `prisma.user.findUnique` on every call. A 30-second TTL LRU keyed on @@ -50,13 +48,6 @@ interface DispatchLocalisedOptions { titleKey: string; messageKey: string; params?: Record; - /** - * Per-channel routing is forward-compat scaffolding. Today the - * dispatcher fans out across every enabled channel for the user; the - * option is accepted so call-sites can declare intent without - * needing a second helper later. - */ - channel?: "telegram" | "email"; /** Event type for preference gating. Defaults to SYSTEM_ALERT. */ eventType?: EventType; /** Channel-specific extras forwarded to the dispatcher metadata. */ @@ -162,13 +153,6 @@ export async function dispatchLocalisedNotification( ); } - // `channel` is accepted for future per-channel routing; today it - // is silently passed through. Suppress unused-var lint by referencing - // it on the metadata if present. - const metadata = opts.channel - ? { ...(opts.metadata ?? {}), preferredChannel: opts.channel } - : opts.metadata; - await dispatchNotification({ eventType: opts.eventType ?? "SYSTEM_ALERT", userId: opts.userId, @@ -177,7 +161,7 @@ export async function dispatchLocalisedNotification( title, message, renderForRecipient, - metadata, + metadata: opts.metadata, managedFanoutEvent: opts.managedFanoutEvent, urgent: opts.urgent, });