Skip to content

Fix mobile notification sound#7327

Open
psrsingh wants to merge 3 commits into
RocketChat:developfrom
psrsingh:fix-mobile-notification-sound
Open

Fix mobile notification sound#7327
psrsingh wants to merge 3 commits into
RocketChat:developfrom
psrsingh:fix-mobile-notification-sound

Conversation

@psrsingh
Copy link
Copy Markdown

@psrsingh psrsingh commented May 17, 2026

Summary

Fixes #7192 by enabling room-specific in-app notification sound playback using audioNotificationValue.

Changes

  • Persisted audioNotificationValue in local subscription storage
  • Added WatermelonDB schema/model/migration support
  • Updated subscription merge flow
  • Added notification sound playback helper using expo-av
  • Integrated room-specific sound playback into in-app notifications
  • Added compatibility fallback for audioNotificationsValue
  • Improved playback cleanup and normalization handling
  • Updated related typings

Notes

The mobile repository currently includes limited bundled notification sound assets, so existing bundled sounds are reused to validate room-specific playback behavior.

Testing

Tested on Android:

  • in-app notification banner display
  • room-specific sound playback
  • sound switching
  • persistence across reloads
  • no-sound preference handling

Summary by CodeRabbit

  • New Features
    • Audio notifications for in-app alerts are now available.
    • Per-room/conversation sound selection is respected; the configured sound plays when a notification arrives (including a “none”/silent option).
    • Playback is handled reliably with automatic cleanup and safeguards to avoid lingering audio.

Review Change Stack

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 17, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c714d525-eecf-422e-9e6d-f9e50c8263b1

📥 Commits

Reviewing files that changed from the base of the PR and between 834a2d3 and 7a8e465.

📒 Files selected for processing (3)
  • app/containers/InAppNotification/index.tsx
  • app/lib/methods/helpers/mergeSubscriptionsRooms.ts
  • app/lib/methods/helpers/playNotificationSound.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • app/lib/methods/helpers/mergeSubscriptionsRooms.ts
  • app/containers/InAppNotification/index.tsx
  • app/lib/methods/helpers/playNotificationSound.ts

Walkthrough

Adds audio preference fields to room/subscription types and DB, a migration, a playNotificationSound helper using Expo AV, maps room preference into subscriptions, and makes InAppNotification fetch the subscription and call the helper to play the chosen sound when an in-app notification arrives.

Changes

In-app notification sound playback

Layer / File(s) Summary
Type definitions for audio preferences
app/definitions/IRoom.ts, app/definitions/ISubscription.ts
Added optional audioNotificationValue/audioNotificationsValue fields to IRoom, IServerRoom, IRoomNotifications, ISubscription, and changed IServerSubscription.audioNotificationValue to string.
Database schema and persistence
app/lib/database/schema/app.js, app/lib/database/model/Subscription.js, app/lib/database/model/migrations.js
Bumped WatermelonDB schema to 29, added optional audio_notification_value string column to subscriptions, added migration, added audioNotificationValue field to Subscription model and included it in asPlain().
Audio playback helper module
app/lib/methods/helpers/playNotificationSound.ts
New playNotificationSound(soundName: string) maps normalized names to bundled assets, plays via Expo AV, auto-unloads on finish, enforces a 5s watchdog unload, and swallows errors for best-effort behavior.
Notification flow and mapping
app/lib/methods/helpers/mergeSubscriptionsRooms.ts, app/containers/InAppNotification/index.tsx
mergeSubscriptionsRooms maps audioNotificationValue (fallback to pluralized field); InAppNotification.show is now async, fetches subscription by room id, and conditionally invokes playNotificationSound with the stored preference.

Sequence Diagram

sequenceDiagram
  participant NotificationEvent
  participant InAppNotification
  participant SubscriptionRepo
  participant PlayHelper
  NotificationEvent->>InAppNotification: show(payload with rid)
  InAppNotification->>SubscriptionRepo: getSubscriptionByRoomId(rid)
  SubscriptionRepo-->>InAppNotification: subscription (includes audioNotificationValue)
  alt audioNotificationValue present
    InAppNotification->>PlayHelper: playNotificationSound(audioNotificationValue)
    PlayHelper-->>InAppNotification: playback started
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

type: feature

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title "Fix mobile notification sound" is concise and directly describes the main change - implementing sound playback for in-app notifications based on room settings.
Linked Issues check ✅ Passed The PR addresses issue #7192's core requirements: reading audioNotificationValue from room settings, mapping to sound assets, and triggering playback on in-app notifications. Schema, model, and merge logic updates support persistence.
Out of Scope Changes check ✅ Passed All changes are scoped to in-app notification sound support: database schema/model updates for audioNotificationValue field, subscription merge logic, and notification sound playback helper. No unrelated changes detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/containers/InAppNotification/index.tsx`:
- Around line 49-52: Wrap the async subscription lookup and the notification
sound call in a try/catch so rejections cannot prevent the banner render: call
getSubscriptionByRoomId(payload.rid) inside a try block (or assign a safe
default on failure) and catch/log any error, and await
playNotificationSound(sub.audioNotificationValue) inside its own try/catch (or
chain .catch) to prevent an unhandled promise; keep the banner rendering logic
independent of these operations so failures only affect sound, not rendering.

In `@app/lib/methods/helpers/mergeSubscriptionsRooms.ts`:
- Around line 113-118: The current logic in mergeSubscriptionsRooms.ts sets
mergedSubscription.audioNotificationValue from room.audioNotificationValue and
then unconditionally overwrites it if room.audioNotificationsValue exists,
letting the legacy key win; change this to use the legacy key only as a fallback
by making the second branch conditional (else if or check that
'audioNotificationValue' is not present/undefined) so that
mergedSubscription.audioNotificationValue is set from
room.audioNotificationValue when present, and only set from
room.audioNotificationsValue when the canonical room.audioNotificationValue is
absent.

In `@app/lib/methods/helpers/playNotificationSound.ts`:
- Around line 34-66: The playback setup can leak if createAsync succeeds but
playAsync throws because unload() is block-scoped; refactor
playNotificationSound so the created Sound instance and the unload function are
declared in the outer scope (e.g., let sound: Audio.Sound | null = null; let
unload = () => {};), assign them after await Audio.Sound.createAsync(asset), and
in the catch block call unload() if a sound was created; ensure unload clears
watchdog, guards with an unloaded flag, and calls sound.unloadAsync().catch(...)
for best-effort cleanup.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6e4c3a6e-b6e2-4380-b181-23d8fa6bc8ab

📥 Commits

Reviewing files that changed from the base of the PR and between 7f1d9de and 834a2d3.

📒 Files selected for processing (8)
  • app/containers/InAppNotification/index.tsx
  • app/definitions/IRoom.ts
  • app/definitions/ISubscription.ts
  • app/lib/database/model/Subscription.js
  • app/lib/database/model/migrations.js
  • app/lib/database/schema/app.js
  • app/lib/methods/helpers/mergeSubscriptionsRooms.ts
  • app/lib/methods/helpers/playNotificationSound.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{js,ts,jsx,tsx}: Use descriptive names for functions, variables, and classes that clearly convey their purpose
Write comments that explain the 'why' behind code decisions, not the 'what'
Keep functions small and focused on a single responsibility
Use const by default, let when reassignment is needed, and avoid var
Prefer async/await over .then() chains for handling asynchronous operations
Use explicit error handling with try/catch blocks for async operations
Avoid deeply nested code; refactor complex logic into helper functions

Files:

  • app/lib/database/model/Subscription.js
  • app/definitions/ISubscription.ts
  • app/lib/methods/helpers/mergeSubscriptionsRooms.ts
  • app/lib/database/schema/app.js
  • app/lib/methods/helpers/playNotificationSound.ts
  • app/lib/database/model/migrations.js
  • app/containers/InAppNotification/index.tsx
  • app/definitions/IRoom.ts
**/*.{ts,tsx,js,jsx,json}

📄 CodeRabbit inference engine (CLAUDE.md)

Use Prettier formatting with tabs, single quotes, 130 character width, no trailing commas, avoid arrow parens, and bracket same line

Files:

  • app/lib/database/model/Subscription.js
  • app/definitions/ISubscription.ts
  • app/lib/methods/helpers/mergeSubscriptionsRooms.ts
  • app/lib/database/schema/app.js
  • app/lib/methods/helpers/playNotificationSound.ts
  • app/lib/database/model/migrations.js
  • app/containers/InAppNotification/index.tsx
  • app/definitions/IRoom.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Use ESLint with @rocket.chat/eslint-config base including React, React Native, TypeScript, and Jest plugins

Files:

  • app/lib/database/model/Subscription.js
  • app/definitions/ISubscription.ts
  • app/lib/methods/helpers/mergeSubscriptionsRooms.ts
  • app/lib/database/schema/app.js
  • app/lib/methods/helpers/playNotificationSound.ts
  • app/lib/database/model/migrations.js
  • app/containers/InAppNotification/index.tsx
  • app/definitions/IRoom.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Use TypeScript for type safety; add explicit type annotations to function parameters and return types
Prefer interfaces over type aliases for defining object shapes in TypeScript
Use enums for sets of related constants rather than magic strings or numbers

Files:

  • app/definitions/ISubscription.ts
  • app/lib/methods/helpers/mergeSubscriptionsRooms.ts
  • app/lib/methods/helpers/playNotificationSound.ts
  • app/containers/InAppNotification/index.tsx
  • app/definitions/IRoom.ts
app/definitions/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Place shared TypeScript type definitions in 'app/definitions/' directory

Files:

  • app/definitions/ISubscription.ts
  • app/definitions/IRoom.ts
app/containers/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Place reusable UI components in 'app/containers/' directory

Files:

  • app/containers/InAppNotification/index.tsx
🧠 Learnings (1)
📚 Learning: 2026-04-30T17:07:51.020Z
Learnt from: diegolmello
Repo: RocketChat/Rocket.Chat.ReactNative PR: 7274
File: app/lib/services/voip/MediaCallEvents.ts:0-0
Timestamp: 2026-04-30T17:07:51.020Z
Learning: In this Rocket.Chat React Native codebase, the ESLint rule `no-void: error` is enforced. When you see a promise returned from an async call that is not awaited (a “floating promise”), do not silence it with the `void somePromise()` pattern. Instead, handle the promise explicitly by attaching `.catch(...)` (or otherwise awaiting/handling the error) so unhandled-rejection risks are addressed in a way that satisfies the existing ESLint configuration.

Applied to files:

  • app/definitions/ISubscription.ts
  • app/lib/methods/helpers/mergeSubscriptionsRooms.ts
  • app/lib/methods/helpers/playNotificationSound.ts
  • app/containers/InAppNotification/index.tsx
  • app/definitions/IRoom.ts
🔇 Additional comments (5)
app/definitions/IRoom.ts (1)

65-66: LGTM!

Also applies to: 243-244, 254-254

app/definitions/ISubscription.ts (1)

118-118: LGTM!

Also applies to: 183-183

app/lib/database/schema/app.js (1)

4-4: LGTM!

Also applies to: 77-78

app/lib/database/model/Subscription.js (1)

164-164: LGTM!

Also applies to: 236-237

app/lib/database/model/migrations.js (1)

348-356: LGTM!

Comment thread app/containers/InAppNotification/index.tsx
Comment thread app/lib/methods/helpers/mergeSubscriptionsRooms.ts
Comment thread app/lib/methods/helpers/playNotificationSound.ts Outdated
Signed-off-by: psrsingh <psr.singh336@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature request: in-app notification sound

2 participants