Manual DND only existed via the desktop tray (manualDndAtom), so web/mobile users had no way to pause notifications, and there was no snooze-for-a-duration anywhere. Add a "Pause Notifications" control in Settings > Notifications: - Presets: 30 min / 1 hour / 4 hours / Until 8 AM / Until I resume, plus Resume; live "Paused until ..." status that flips back on when the snooze lapses. - Persisted snooze instant (cinny_notification_snooze_until_v1) so it survives a reload; 0 = off, SNOOZE_INDEFINITE = until resumed. - Feeds the existing notification gate (ClientNonUIFeatures, both the message and invite monitors) alongside Focus Assist / manual DND / Quiet Hours, suppressing notify() and playSound(). - Pure helpers isSnoozeActive/nextTimeAtHour/SNOOZE_INDEFINITE in utils/snooze.ts (+5 unit tests); persisted atom in state/notificationSnooze.ts. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
22 lines
908 B
TypeScript
22 lines
908 B
TypeScript
// Pure helpers for the cross-platform "pause notifications" / snooze feature.
|
|
// Kept free of jotai/localStorage so they're unit-testable in isolation; the
|
|
// persisted atom lives in state/notificationSnooze.ts.
|
|
|
|
// Represents "paused until I turn it back on" (a far-future instant).
|
|
export const SNOOZE_INDEFINITE = Number.MAX_SAFE_INTEGER;
|
|
|
|
// Is the snooze currently active (i.e. suppressing notifications)?
|
|
export function isSnoozeActive(until: number, now: number = Date.now()): boolean {
|
|
return until > now;
|
|
}
|
|
|
|
// The soonest future instant at the given local hour (0-23), minute 0 — used for
|
|
// the "Until 8 AM" preset. If that hour has already passed today, rolls to
|
|
// tomorrow.
|
|
export function nextTimeAtHour(hour: number, now: number = Date.now()): number {
|
|
const d = new Date(now);
|
|
d.setHours(hour, 0, 0, 0);
|
|
if (d.getTime() <= now) d.setDate(d.getDate() + 1);
|
|
return d.getTime();
|
|
}
|