Skip to content

feat: support quiet hours for push notifications (REACT-1375) - #2000

Open
NikolaGoranNaumovski wants to merge 2 commits into
masterfrom
nikolanaumovski/react-1375-support-quiet-hours-for-push-notifications-v9
Open

NikolaGoranNaumovski wants to merge 2 commits into
masterfrom
nikolanaumovski/react-1375-support-quiet-hours-for-push-notifications-v9

Conversation

@NikolaGoranNaumovski

@NikolaGoranNaumovski NikolaGoranNaumovski commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

CLA

  • I have signed the Stream CLA (required).
  • Code changes are tested

Description of the changes, What, Why and How?

Ticket: https://linear.app/stream/issue/REACT-1375
Spec: CHA-2667 Quiet hours – client SDK
v10 counterpart: #1999

The backend already supports quiet hours for push notifications. A user-level push preference can carry a schedule (a timezone and 1–7 quiet windows), and remove_schedule clears it. v9 has no types for them, so this PR adds the types, the helpers a UI needs, and keeps the connected user's preferences up to date after a save. The helpers and the merge are the same as in the v10 PR.

Types (src/types.ts)

  • PushPreference: schedule?: PushScheduleInput, remove_schedule?: boolean.
  • PushPreferencesResponse: schedule?: PushScheduleResponse.
  • New types: PushScheduleInput, PushScheduleResponse, QuietHoursRuleInput and QuietHoursRuleResponse. They follow the OpenAPI models (start/end as HH:MM, optional days).

Helpers (src/pushPreferences/, exported from the root)

  • isInQuietHours({ schedule, date? }) tells whether a schedule is quiet at date (default: now).
    • It reads the wall clock in the schedule's timezone with Intl.DateTimeFormat, so it follows daylight saving time.
    • A window whose end is earlier than its start runs past midnight. It belongs to the day it opens on, so days is checked against the previous day after midnight.
    • A rule without days applies every day. 00:00–24:00 covers the whole day.
  • getDeviceTimeZone() returns the device's IANA timezone, to pre-fill a schedule.
  • QuietHoursDay names the day values (mon … sun).

Connected user

After a successful request, setPushPreferences merges the user-level preferences of the connected user into client.user.push_preferences:

  • It uses the server's user_preferences[userId] when the response has it.
  • remove_schedule drops the stored schedule unless the response returns a new one. remove_disable does the same for disabled_until.
  • Channel-level items and items for other users leave client.user unchanged.
  • client.user is replaced, not mutated, and only when the preferences changed.

The second commit removes a node_modules link that the first commit included by mistake.

Tests

  • test/unit/pushPreferences/utils.test.ts covers isInQuietHours: windows, past midnight, the whole day, several rules, timezones and DST. It also covers getDeviceTimeZone and the merge cases.
  • test/unit/pushPreferences/setPushPreferences.test.ts covers the request payload and the connected user's state.

Changelog

  • Add the quiet hours schedule / remove_schedule push preference types.
  • Add isInQuietHours, getDeviceTimeZone and QuietHoursDay.
  • Keep client.user.push_preferences in sync after setPushPreferences.

🤖 Generated with Claude Code

Add the schedule and remove_schedule push preferences, isInQuietHours,
getDeviceTimeZone and QuietHoursDay, and keep client.user.push_preferences
in sync after setPushPreferences.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant