@zhin.js/plugin-calendar 0.1.15 → 0.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/notify.ts ADDED
@@ -0,0 +1,19 @@
1
+ import type { DeliveryTarget, OutboundHost } from "zhin.js";
2
+ import type { Locale } from "zhin.js/i18n";
3
+ import type { CalendarNotifier } from "./chat-auth.js";
4
+
5
+ /**
6
+ * Authorization notices are not messages, so the dispatch gate does not see them (ADR 0050 / 0055):
7
+ * skip targets whose account or conversation switched calendar off.
8
+ */
9
+ export function createCalendarNotifier(
10
+ outbound: Pick<OutboundHost, "sendTarget"> | undefined,
11
+ isEnabledFor: (target: { conversation: DeliveryTarget }) => boolean
12
+ ): CalendarNotifier<DeliveryTarget> | undefined {
13
+ const sendTarget = outbound?.sendTarget;
14
+ if (!sendTarget) return undefined;
15
+ return async (target: DeliveryTarget, text: string, locale: Locale) => {
16
+ if (!isEnabledFor({ conversation: target })) return;
17
+ await sendTarget.call(outbound, target, text, { locale });
18
+ };
19
+ }