1import type { Notification, NotificationBehavior } from "expo-notifications";
2
3import { extractAgentNotificationDeepLink } from "./notificationPayload";
4
5const SHOW: NotificationBehavior = {
6 shouldShowBanner: true,
7 shouldShowList: true,
8 shouldPlaySound: true,
9 shouldSetBadge: false,
10};
11
12const SUPPRESS: NotificationBehavior = {
13 shouldShowBanner: false,
14 shouldShowList: false,
15 shouldPlaySound: false,
16 shouldSetBadge: false,
17};
18
19/**
20 * Decides how a notification that arrives while the app is open is presented.
21 * A notification for the thread already on screen is redundant with the live
22 * feed, so it stays silent; everything else banners like it would in the
23 * background. `deepLinkOnScreen` is the normalized `/threads/:env/:thread`
24 * path of the current route, or null when no thread is open.
25 */
26export function foregroundNotificationBehavior(
27 notification: Notification,
28 deepLinkOnScreen: string | null,
29): NotificationBehavior {
30 const target = extractAgentNotificationDeepLink({ notification });
31 if (target !== null && target === deepLinkOnScreen) {
32 return SUPPRESS;
33 }
34 return SHOW;
35}