feat(notifications): Phase C — Don't Disturb (quiet hours window)
User задаёт quiet window (e.g. 22:00–08:00 Europe/Moscow) — external channels (email + express) DROP'аются dispatcher'ом. In-app bell badge остаётся (юзер видит при следующем визите UI). Cross-midnight aware. ## Backend - Migration 0026: user_notification_settings table (user_id PK + quiet_hours_start/end LocalTime + tz) - Entity UserNotificationSettings + Repository (stock CRUD) - UserPreferencesGate extended: - Constructor takes settingsRepo - allows() checks isQuiet(userId) первым for external channels (EMAIL/EXPRESS/TELEGRAM) - isQuiet: load settings → if hasEffectiveQuietHours() → check current LocalTime в user's TZ - inWindow() helper: cross-midnight semantics (22:00–08:00 wraps midnight) - Invalid TZ → fallback к DEFAULT_TZ (Europe/Moscow) с WARN log - Test seam: setClockForTesting(Clock) для deterministic tests - MeNotificationsSettingsController: GET/PUT /api/v1/me/notifications/settings - HH:mm input parsing, IANA TZ validation, enabled=false clears window - Auth required (JWT sub claim) ## Frontend - NotificationSettings type в client.ts - useMyNotificationSettings query (60s stale) - useUpdateNotificationSettings mutation - QuietHoursSection в /me/notifications/preferences route: - Switch toggle + 2 time inputs + TZ select (12 RU/UTC zones) - Optimistic local state synced from query - Save button с pending/success/error states - i18n RU + EN ## Tests - 9 new tests UserPreferencesGateQuietHoursTest: - Same-day window match (inclusive start, exclusive end) - Cross-midnight window match (22:00–08:00) - No settings row → не блокирует - Quiet window active → email + express dropped - Outside window → email allowed - start == end → disabled (zero-duration treated as off) - Reviewer pool bypasses (always ON) - Invalid TZ → fallback default - Specific pref ON + quiet ON → quiet wins (drop) - NotificationsDispatcherTest constructor updated к new signature - Total notifications tests: 53 → 62, все green ## Design rationale (drop vs defer) Drop chosen за defer (queue + re-fire scheduler) потому что: - Defer needs persistent queue + scheduled retry — high complexity - Most notifications time-relevant (draft N hours ago less actionable) - Bell badge показывает full feed — ничего не «теряется» - Phase D summary digest можно build later если demand surfaces
This commit is contained in:
@@ -764,6 +764,18 @@ export type ChannelToggles = {
|
||||
/** Map keyed по event type. Backend сейчас возвращает 4 known events. */
|
||||
export type NotificationPreferences = Record<string, ChannelToggles>
|
||||
|
||||
/**
|
||||
* Phase C Don't Disturb — per-user quiet hours. Когда window активен,
|
||||
* external channels (email + express) DROPPED dispatcher'ом. Bell badge
|
||||
* остаётся.
|
||||
*/
|
||||
export type NotificationSettings = {
|
||||
quietHoursEnabled: boolean
|
||||
quietHoursStart: string | null // "HH:mm" or "HH:mm:ss"
|
||||
quietHoursEnd: string | null
|
||||
quietHoursTz: string // IANA, default "Europe/Moscow"
|
||||
}
|
||||
|
||||
/**
|
||||
* Canonical event types — должны совпадать с backend
|
||||
* MeNotificationsPreferencesController.KNOWN_EVENT_TYPES.
|
||||
|
||||
Reference in New Issue
Block a user