diff --git a/app/features/notifications/core/notify.server.test.ts b/app/features/notifications/core/notify.server.test.ts index c3069fa80..3cb31ac2a 100644 --- a/app/features/notifications/core/notify.server.test.ts +++ b/app/features/notifications/core/notify.server.test.ts @@ -251,6 +251,7 @@ describe("notify() - web push notifications", () => { expect(mockSendNotification).toHaveBeenCalledWith( mockSubscription, expect.any(String), + { urgency: "high" }, ); const callArgs = mockSendNotification.mock.calls[0][1]; @@ -306,10 +307,12 @@ describe("notify() - web push notifications", () => { expect(mockSendNotification).toHaveBeenCalledWith( mockSubscription1, expect.any(String), + { urgency: "normal" }, ); expect(mockSendNotification).toHaveBeenCalledWith( mockSubscription2, expect.any(String), + { urgency: "normal" }, ); }); diff --git a/app/features/notifications/core/notify.server.ts b/app/features/notifications/core/notify.server.ts index d77204af3..1f97022d7 100644 --- a/app/features/notifications/core/notify.server.ts +++ b/app/features/notifications/core/notify.server.ts @@ -1,6 +1,6 @@ import type { TFunction } from "i18next"; import pLimit from "p-limit"; -import { WebPushError } from "web-push"; +import { type Urgency, WebPushError } from "web-push"; import { IS_E2E_TEST_RUN } from "~/utils/e2e"; import type { NotificationSubscription } from "../../../db/tables"; import { i18next } from "../../../modules/i18n/i18next.server"; @@ -13,6 +13,29 @@ import { } from "../notifications-utils"; import webPush, { webPushEnabled } from "./webPush.server"; +const NOTIFICATION_URGENCY: Record = { + SQ_ADDED_TO_GROUP: "high", + SQ_NEW_MATCH: "high", + TO_ADDED_TO_TEAM: "normal", + TO_BRACKET_STARTED: "high", + TO_CHECK_IN_OPENED: "high", + TO_TEST_CREATED: "normal", + TO_LIKE_RECEIVED: "high", + TO_LIKE_ACCEPTED: "high", + BADGE_ADDED: "normal", + BADGE_MANAGER_ADDED: "normal", + PLUS_VOTING_STARTED: "normal", + PLUS_SUGGESTION_ADDED: "normal", + TAGGED_TO_ART: "normal", + SEASON_STARTED: "normal", + SCRIM_NEW_REQUEST: "high", + SCRIM_SCHEDULED: "high", + SCRIM_CANCELED: "high", + SCRIM_STARTING_SOON: "high", + COMMISSIONS_CLOSED: "normal", + FRIEND_REQUEST_RECEIVED: "normal", +}; + /** * Create notifications both in the database and send push notifications to users (if enabled). */ @@ -125,6 +148,7 @@ async function sendPushNotification({ await webPush.sendNotification( subscription, JSON.stringify(pushNotificationOptions(notification, t)), + { urgency: NOTIFICATION_URGENCY[notification.type] }, ); } catch (err) { if (!(err instanceof WebPushError)) {