fix(calls): incoming-call ringtone respects quiet hours, DND, Focus Assist and snooze
CI / Build & Quality Checks (push) Canceled after 11s
CI / Trigger Desktop Build (push) Canceled after 0s
CI / Secret scan (gitleaks) (push) Canceled after 0s
CI / Docker image build & smoke test (push) Canceled after 0s
CI / Playwright smoke (e2e) (push) Canceled after 0s

The "should we make noise" predicate used for message sounds is extracted
into useNotificationsQuiet() (unit-tested) and applied to the ringtone in
both the full-screen incoming-call overlay and the compact in-call banner.
The overlay/banner still show so the call can be answered; only the audio
is skipped. Join/media paths untouched.

Fixes #28

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
This commit is contained in:
2026-09-15 22:43:17 -04:00
co-authored by Claude Opus 5
parent 4cdd221eff
commit 3dead4b3e1
4 changed files with 130 additions and 42 deletions
@@ -0,0 +1,55 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
// `useNotificationsQuiet.ts` pulls in `state/notificationSnooze.ts`, whose
// `atomWithStorage(..., { getOnInit: true })` reads `localStorage` eagerly at
// module-import time. Plain `node:test` has no `localStorage`, so install a
// minimal stub before dynamically importing the module under test (mirrors the
// mocking approach in `state/settings.test.ts`).
(globalThis as { localStorage?: unknown }).localStorage = {
getItem: () => null,
setItem: () => undefined,
removeItem: () => undefined,
};
const { isNotificationsQuiet } = await import('./useNotificationsQuiet');
const base = {
focusAssistActive: false,
manualDnd: false,
snoozeUntil: 0,
quietHoursEnabled: false,
quietHoursStart: '22:00',
quietHoursEnd: '07:00',
};
test('isNotificationsQuiet: quiet when none of the inputs are active', () => {
assert.equal(isNotificationsQuiet(base), false);
});
test('isNotificationsQuiet: active quiet-hours window suppresses (#28)', () => {
const now = new Date(2026, 0, 1, 23, 0);
assert.equal(isNotificationsQuiet({ ...base, quietHoursEnabled: true, now }), true);
// Disabled setting is not enough on its own, even inside the window.
assert.equal(isNotificationsQuiet({ ...base, quietHoursEnabled: false, now }), false);
// Outside the window, enabling it does not suppress.
const outside = new Date(2026, 0, 1, 12, 0);
assert.equal(isNotificationsQuiet({ ...base, quietHoursEnabled: true, now: outside }), false);
});
test('isNotificationsQuiet: presence/manual DND suppresses (#28)', () => {
assert.equal(isNotificationsQuiet({ ...base, focusAssistActive: true }), true);
assert.equal(isNotificationsQuiet({ ...base, manualDnd: true }), true);
});
test('isNotificationsQuiet: an active snooze suppresses (#28)', () => {
const now = Date.now();
assert.equal(
isNotificationsQuiet({ ...base, snoozeUntil: now + 60_000, now: new Date(now) }),
true,
);
assert.equal(
isNotificationsQuiet({ ...base, snoozeUntil: now - 60_000, now: new Date(now) }),
false,
);
});
+58
View File
@@ -0,0 +1,58 @@
import { useAtomValue } from 'jotai';
import { focusAssistActiveAtom } from '../state/focusAssist';
import { manualDndAtom } from '../state/manualDnd';
import { isSnoozeActive, notificationSnoozeUntilAtom } from '../state/notificationSnooze';
import { isWithinTimeWindow } from '../utils/timeWindow';
import { useSetting } from '../state/hooks/settings';
import { settingsAtom } from '../state/settings';
export type NotificationsQuietInputs = {
focusAssistActive: boolean;
manualDnd: boolean;
snoozeUntil: number;
quietHoursEnabled: boolean;
quietHoursStart: string;
quietHoursEnd: string;
now?: Date;
};
// Gitea #28 — pure "should we make noise right now?" predicate, extracted from
// the gate that `ClientNonUIFeatures` already applies to message/invite sounds
// (Focus Assist, manual tray DND, the snooze, and the quiet-hours window) so the
// incoming-call ringtone (and anything else) can honour the same rules.
export function isNotificationsQuiet({
focusAssistActive,
manualDnd,
snoozeUntil,
quietHoursEnabled,
quietHoursStart,
quietHoursEnd,
now,
}: NotificationsQuietInputs): boolean {
return (
focusAssistActive ||
manualDnd ||
isSnoozeActive(snoozeUntil, now?.getTime()) ||
(quietHoursEnabled && isWithinTimeWindow(quietHoursStart, quietHoursEnd, now))
);
}
// Live-atoms/settings-backed version of `isNotificationsQuiet` for use in
// components.
export function useNotificationsQuiet(): boolean {
const focusAssistActive = useAtomValue(focusAssistActiveAtom);
const manualDnd = useAtomValue(manualDndAtom);
const snoozeUntil = useAtomValue(notificationSnoozeUntilAtom);
const [quietHoursEnabled] = useSetting(settingsAtom, 'quietHoursEnabled');
const [quietHoursStart] = useSetting(settingsAtom, 'quietHoursStart');
const [quietHoursEnd] = useSetting(settingsAtom, 'quietHoursEnd');
return isNotificationsQuiet({
focusAssistActive,
manualDnd,
snoozeUntil,
quietHoursEnabled,
quietHoursStart,
quietHoursEnd,
});
}