mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-10-31 16:13:15 +00:00
fix: keep pushed notifications silent while do not disturb is on
This commit is contained in:
@@ -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 });
|
||||
});
|
||||
});
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user