Skip to content

feat: add notification API wrapper#3096

Open
MartinCupela wants to merge 9 commits intomasterfrom
feat/notification-api-wrapper
Open

feat: add notification API wrapper#3096
MartinCupela wants to merge 9 commits intomasterfrom
feat/notification-api-wrapper

Conversation

@MartinCupela
Copy link
Copy Markdown
Contributor

@MartinCupela MartinCupela commented Apr 6, 2026

BREAKING CHANGE:

  • Removed legacy notification text callback props from Message props:
    getDeleteMessageErrorNotification,
    getFetchReactionsErrorNotification,
    getFlagMessageErrorNotification,
    getFlagMessageSuccessNotification,
    getMarkMessageUnreadErrorNotification,
    getMarkMessageUnreadSuccessNotification,
    getMuteUserErrorNotification,
    getMuteUserSuccessNotification,
    getPinMessageErrorNotification.
    Notification customization must now be done through notification translators
    (Streami18n translationBuilder topic: "notification") and/or custom MessageActions.

BREAKING CHANGE:

  • Message action handlers no longer publish notifications internally.
    Errors now propagate to call sites, which are responsible for success/error notifications.

🎯 Goal

Summary

This PR introduces a new notifications facade hook: useNotificationApi at src/components/Notifications/hooks/useNotificationApi.ts, and migrates notification API usage in src to use it.
This PR completes the notification-system migration for message and channel-list actions by removing legacy Message-level notification props and moving notification publishing/customization to the modern notification pipeline (Notification + translation builders + customizable action components).

What changed

  1. Added typed notification API wrapper
  • Introduced useNotificationApi(): NotificationApi.
  • Added explicit exported types for reuse:
    • AddNotificationParams
    • NotificationIncidentDescriptor
    • AddNotification
    • RemoveNotification
    • StartNotificationTimeout
    • NotificationApi
  1. Added addNotification abstraction over client.notifications.add
  • Centralizes construction of notification payload/options.
  • Supports:
    • message, emitter, severity, duration, actions, error, context, tags, targetPanels, type, incident.
  • Notification target behavior:
    • Uses inferred panel from useNotificationTarget by default.
    • Allows overriding via targetPanels (including multiple panels).
    • If targetPanels are provided, inferred panel is ignored.
  • Type behavior:
    • Uses provided type as-is.
    • If type is omitted and incident is provided, type is generated from incident descriptor.
    • If type is provided, incident is optional and not required.
  1. Added other wrappers
  • removeNotification(id) delegates to client.notifications.remove(id).
  • startNotificationTimeout(id) delegates to client.notifications.startTimeout(id).
  1. Migrated direct notification manager usage
  1. Added IconMinus component and used it in NumericInput
  2. Introduced fixes to demo app
  3. Message actions
  • Moved action-level success/error notifications to call sites in:
    • src/components/MessageActions/MessageActions.defaults.tsx
    • src/components/MessageActions/RemindMeSubmenu.tsx
  • Added notifications for:
    • pin/unpin
    • mark unread
    • flag
    • mute/unmute
    • delete
    • remind me set/remove
    • save for later add/remove
  • All emitted message-action notifications now include:
    • type (API-ish event key; message actions use api:*)
    • context: { message }
    • error attached on error notifications (when available)
  1. Hook behavior
  • Message action hooks no longer own user-facing notification publication.
  • Errors are allowed to propagate to callers (so callers decide notification UX).
  • Removed banned-user early branch from useFlagHandler as requested.
  1. Reactions fetch handling
  • Added failure notification handling for fetch reactions flow in:
    • src/components/Reactions/hooks/useFetchReactions.ts
  1. Notification component customization
  • Added Notification override support via ComponentContext and wired NotificationList to use it.
  • Fixed ComponentContext.Notification type to support forwarded refs:
    • now expects a ref-capable component (ForwardRefExoticComponent<...RefAttributes<HTMLDivElement>>).
  1. Channel list item actions
  • Added context: { channel } to channel-list action notifications in:
    • src/components/ChannelListItem/ChannelListItemActionButtons.defaults.tsx
  • Added success notifications (alongside existing failures) for:
    • mute/unmute
    • archive/unarchive
    • ban/unban
    • pin/unpin
    • leave

Why

  • Reduces API surface exposure of client.notifications across components.
  • Centralizes tagging/type/origin behavior in one place.
  • Improves consistency and makes future notification behavior changes cheaper.
  • Provides reusable typed contracts for components/plugins using notifications.

Tests

  • Updated and extended tests for:
    • useNotificationApi behavior (including target panel handling and type generation).
    • Notification lifecycle usage in NotificationList.
    • Dependent tests that needed mocking alignment after migration.
  • Typecheck and targeted notification/audio-related test suites pass.
  • Updated/added tests across message actions, hooks, reactions, notification API, notification list, and message list/message paths to cover the new behavior.

@MartinCupela MartinCupela changed the title Feat/notification api wrapper feat: add notification API wrapper Apr 6, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

Size Change: +4.56 kB (+0.74%)

Total Size: 618 kB

📦 View Changed
Filename Size Change
dist/cjs/emojis.js 2.96 kB +2 B (+0.07%)
dist/cjs/index.js 239 kB +1.54 kB (+0.65%)
dist/cjs/WithAudioPlayback.js 43.4 kB +691 B (+1.62%)
dist/es/emojis.mjs 2.47 kB +1 B (+0.04%)
dist/es/index.mjs 237 kB +1.63 kB (+0.69%)
dist/es/WithAudioPlayback.mjs 43.2 kB +694 B (+1.63%)
ℹ️ View Unchanged
Filename Size
dist/cjs/audioProcessing.js 1.32 kB
dist/cjs/mp3-encoder.js 1.27 kB
dist/css/emoji-replacement.css 456 B
dist/css/index.css 45.5 kB
dist/es/audioProcessing.mjs 1.31 kB
dist/es/mp3-encoder.mjs 756 B

compressed-size-action

…age-notification props

- move message action success/error notifications to MessageActions defaults
- bubble action handler errors to callers (no hook-level notification side effects)
- add notification types + context payloads for message and channel-list actions
- add Reminder/SaveForLater notification handling
- allow custom Notification component override with forwardRef typing in ComponentContext
- add examples/tests for translator-based notification customization

BREAKING CHANGE:
- Removed legacy notification text callback props from Message props:
  getDeleteMessageErrorNotification,
  getFetchReactionsErrorNotification,
  getFlagMessageErrorNotification,
  getFlagMessageSuccessNotification,
  getMarkMessageUnreadErrorNotification,
  getMarkMessageUnreadSuccessNotification,
  getMuteUserErrorNotification,
  getMuteUserSuccessNotification,
  getPinMessageErrorNotification.
  Notification customization must now be done through notification translators
  (Streami18n translationBuilder topic: "notification") and/or custom MessageActions.

BREAKING CHANGE:
- Message action handlers no longer publish notifications internally.
  Errors now propagate to call sites, which are responsible for success/error notifications.
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 7, 2026

Codecov Report

❌ Patch coverage is 72.55814% with 59 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.87%. Comparing base (b5cb01f) to head (32fdf4c).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...ListItem/ChannelListItemActionButtons.defaults.tsx 0.00% 23 Missing ⚠️
...ponents/MessageActions/MessageActions.defaults.tsx 76.38% 17 Missing ⚠️
src/components/MessageActions/RemindMeSubmenu.tsx 68.75% 5 Missing ⚠️
src/components/Location/ShareLocationDialog.tsx 20.00% 4 Missing ⚠️
src/components/Poll/PollActions/EndPollAlert.tsx 0.00% 4 Missing ⚠️
src/components/Message/hooks/usePinHandler.ts 0.00% 2 Missing ⚠️
src/components/Notifications/Notification.tsx 0.00% 2 Missing ⚠️
...rc/components/Message/hooks/useReactionsFetcher.ts 66.66% 1 Missing ⚠️
...mponents/MessageComposer/hooks/useSubmitHandler.ts 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3096      +/-   ##
==========================================
+ Coverage   79.57%   79.87%   +0.30%     
==========================================
  Files         426      427       +1     
  Lines       12181    12214      +33     
  Branches     3914     3914              
==========================================
+ Hits         9693     9756      +63     
+ Misses       2488     2458      -30     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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