fix: keep pushed notifications silent while do not disturb is on

This commit is contained in:
Linus Rath
2026-10-29 19:10:30 +01:00
parent ed3f7fabba
commit 6e45d754f9
2 changed files with 20 additions and 1 deletions
@@ -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 });
});
});
+3 -1
View File
@@ -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) => {