From 6e45d754f9105e2192de88d895026fa5f44af37e Mon Sep 17 00:00:00 2001 From: Linus Rath <139418639+rathlinus@users.noreply.github.com> Date: Thu, 29 Oct 2026 19:10:30 +0100 Subject: [PATCH] fix: keep pushed notifications silent while do not disturb is on --- stores/__tests__/settings-push-dnd.test.ts | 17 +++++++++++++++++ stores/settings-store.ts | 4 +++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 stores/__tests__/settings-push-dnd.test.ts diff --git a/stores/__tests__/settings-push-dnd.test.ts b/stores/__tests__/settings-push-dnd.test.ts new file mode 100644 index 000000000..52df90530 --- /dev/null +++ b/stores/__tests__/settings-push-dnd.test.ts @@ -0,0 +1,17 @@ +import { describe, expect, it, vi } from 'vitest'; + +const writePushPreferences = vi.hoisted(() => vi.fn(async () => {})); +vi.mock('@/lib/push-preferences', () => ({ writePushPreferences })); + +import { useSettingsStore } from '../settings-store'; + +describe('do not disturb and push notifications (CO-13)', () => { + it('keeps pushed notifications silent while do not disturb is on', () => { + useSettingsStore.setState({ emailNotificationsEnabled: true, emailNotificationSound: true, doNotDisturb: false }); + writePushPreferences.mockClear(); + useSettingsStore.getState().updateSetting('doNotDisturb', true); + expect(writePushPreferences).toHaveBeenLastCalledWith({ sound: false }); + useSettingsStore.getState().updateSetting('doNotDisturb', false); + expect(writePushPreferences).toHaveBeenLastCalledWith({ sound: true }); + }); +}); diff --git a/stores/settings-store.ts b/stores/settings-store.ts index 3a9cd7cb4..688c0a1d4 100644 --- a/stores/settings-store.ts +++ b/stores/settings-store.ts @@ -2131,7 +2131,9 @@ if (typeof window !== 'undefined') { // The service worker shows push notifications without this store, so it // reads the sound preference from its own Cache store (#1289). - const pushSound = (s: SettingsState) => s.emailNotificationsEnabled && s.emailNotificationSound; + // Do not disturb can't keep a push from showing (browsers require one per + // push), but it keeps it silent. + const pushSound = (s: SettingsState) => s.emailNotificationsEnabled && s.emailNotificationSound && !s.doNotDisturb; let lastPushSound = pushSound(store); void writePushPreferences({ sound: lastPushSound }); useSettingsStore.subscribe((state) => {