Skip to content

fix: Stop media player when message is not accessible - #41600

Open
yash-rajpal wants to merge 3 commits into
developfrom
reg/audio-stop-on-msg-delete
Open

fix: Stop media player when message is not accessible#41600
yash-rajpal wants to merge 3 commits into
developfrom
reg/audio-stop-on-msg-delete

Conversation

@yash-rajpal

@yash-rajpal yash-rajpal commented Jul 28, 2026

Copy link
Copy Markdown
Member

Proposed changes (including videos or screenshots)

Recently we made a global audio player which didn't require the audio message to be mounted but this created issue that audio player should stop once the user no longer has access to the message, either by message being deleted or the user being no longer part of the room.

This PR implements this edge case by listening to the required stream events, it stops playing audio when user can no longer access the message.

Issue(s)

Steps to test or reproduce

Further comments

CORE-2484

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Audio playback now stops automatically when the currently playing message is hard-deleted or soft-deleted.
    • Playback also stops when the user’s subscription changes remove access to the associated room.
    • Improved real-time handling of room and account updates to keep media playback in sync.

@dionisio-bot

dionisio-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is targeting the wrong base branch. It should target 8.9.0, but it targets 8.8.0

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot

changeset-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 28db67f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

MediaPlayerProvider now observes message deletion and subscription events, stopping playback when the active track’s message is removed or its room is no longer subscribed.

Changes

Media playback invalidation

Layer / File(s) Summary
Playback event handling
apps/meteor/client/providers/MediaPlayerProvider/MediaPlayerProvider.tsx
Adds current-user context and stream/store subscriptions that close playback after hard deletion, soft deletion, or removal of the track’s room from the user’s subscriptions.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested labels: type: bug

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: stopping media playback when the associated message is no longer accessible.

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • CORE-2484: Request failed with status code 401

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.

@yash-rajpal
yash-rajpal changed the base branch from develop to release-8.7.0 July 28, 2026 14:13
@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 15.78947% with 64 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.39%. Comparing base (987f8d6) to head (28db67f).
⚠️ Report is 4 commits behind head on release-8.7.0.

Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                @@
##           release-8.7.0   #41600      +/-   ##
=================================================
- Coverage          68.68%   68.39%   -0.30%     
=================================================
  Files               4139     4139              
  Lines             159681   158374    -1307     
  Branches           28306    28362      +56     
=================================================
- Hits              109677   108316    -1361     
- Misses             44869    44915      +46     
- Partials            5135     5143       +8     
Flag Coverage Δ
e2e 58.81% <23.68%> (-0.08%) ⬇️
e2e-api 45.60% <ø> (+0.24%) ⬆️
unit 70.28% <3.94%> (-0.44%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 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.

@yash-rajpal
yash-rajpal marked this pull request as ready for review July 28, 2026 14:48
@yash-rajpal
yash-rajpal requested a review from a team as a code owner July 28, 2026 14:48
@yash-rajpal yash-rajpal added the stat: QA assured Means it has been tested and approved by a company insider label Jul 28, 2026
@yash-rajpal yash-rajpal added this to the 8.7.0 milestone Jul 28, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Jul 28, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
apps/meteor/client/providers/MediaPlayerProvider/MediaPlayerProvider.tsx (1)

110-110: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove implementation comments.

As per path instructions, **/*.{ts,tsx,js} should "Avoid code comments in the implementation". These two explanatory comments should be dropped (or turned into descriptive variable/effect names if the intent needs preserving).

Also applies to: 140-140

🤖 Prompt for 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.

In `@apps/meteor/client/providers/MediaPlayerProvider/MediaPlayerProvider.tsx` at
line 110, Remove the explanatory implementation comments near the hard-delete
handling and the corresponding code around the second referenced location in
MediaPlayerProvider. Preserve the existing behavior; do not replace the comments
unless intent must be represented through clearer descriptive names.

Source: Path instructions

🤖 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 `@apps/meteor/client/providers/MediaPlayerProvider/MediaPlayerProvider.tsx`:
- Around line 111-138: Update all three notification-listener effects in the
MediaPlayerProvider to attach whenever track is loaded, regardless of playback
state: remove the playing guard and remove playing from each effect’s dependency
array. Preserve the existing track, room/message ID validation, subscriptions,
cleanup, and close behavior.

---

Nitpick comments:
In `@apps/meteor/client/providers/MediaPlayerProvider/MediaPlayerProvider.tsx`:
- Line 110: Remove the explanatory implementation comments near the hard-delete
handling and the corresponding code around the second referenced location in
MediaPlayerProvider. Preserve the existing behavior; do not replace the comments
unless intent must be represented through clearer descriptive names.
🪄 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 Plus

Run ID: d84c06fa-72b8-4a7e-bf00-dc97ae56ac84

📥 Commits

Reviewing files that changed from the base of the PR and between 008fee8 and a8ae3ea.

📒 Files selected for processing (1)
  • apps/meteor/client/providers/MediaPlayerProvider/MediaPlayerProvider.tsx
📜 Review details
⏰ Context from checks skipped due to timeout. (4)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Hacktron Security Check
  • GitHub Check: 📦 Build Packages
  • GitHub Check: CodeQL-Build
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/client/providers/MediaPlayerProvider/MediaPlayerProvider.tsx
🧠 Learnings (2)
📚 Learning: 2026-03-27T14:52:56.865Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 39892
File: apps/meteor/client/views/room/contextualBar/Threads/Thread.tsx:150-155
Timestamp: 2026-03-27T14:52:56.865Z
Learning: In Rocket.Chat, there are two different `ModalBackdrop` components with different prop APIs. During review, confirm the import source: (1) `rocket.chat/fuselage` `ModalBackdrop` uses `ModalBackdropProps` based on `BoxProps` (so it supports `onClick` and other Box/DOM props) and does not have an `onDismiss` prop; (2) `rocket.chat/ui-client` `ModalBackdrop` uses a narrower props interface like `{ children?: ReactNode; onDismiss?: () => void }` and handles Escape keypress and outside mouse-up, and it does not forward arbitrary DOM props such as `onClick`. Flag mismatched props (e.g., `onDismiss` passed to the fuselage component or `onClick` passed to the ui-client component) and ensure the usage matches the correct component being imported.

Applied to files:

  • apps/meteor/client/providers/MediaPlayerProvider/MediaPlayerProvider.tsx
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • apps/meteor/client/providers/MediaPlayerProvider/MediaPlayerProvider.tsx
🔇 Additional comments (1)
apps/meteor/client/providers/MediaPlayerProvider/MediaPlayerProvider.tsx (1)

2-9: LGTM!

Also applies to: 32-32, 107-108

Comment thread apps/meteor/client/providers/MediaPlayerProvider/MediaPlayerProvider.tsx Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 1 file

Re-trigger cubic

@gabriellsh gabriellsh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Technically, I don't think this is a regression. If you had access to a room/message, you could download the audio and have it forever.

Another point is, whenever you see a message that has a file, in most cases a temporary URL will be generated through the files endpoint that already checks for the message/room. That URL allows you to access the file until it expires, which can be a long time.

In summary, IDK if we should implement these checks this way. Whenever the access is properly removed, it will eventually disappear. I'll bring this discussion forward.

Comment on lines +162 to +178
useEffect(() => {
if (!track || !userId) {
return;
}

const { rid } = track;

if (!rid) {
return;
}

return subscribeToNotifyUser(`${userId}/subscriptions-changed`, (event, subscription) => {
if (event === 'removed' && subscription.rid === rid) {
close();
}
});
}, [userId, subscribeToNotifyUser, track, close]);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you leave a public room, you might still have access to the message, so listening for subscription removal would stop playing a sound even if you still have access to the message.

Another scenario is, you're listening to an audio in a public room, without joining it, and loosing the permission preview-c-room.

Comment on lines +111 to +157
useEffect(() => {
if (!track) {
return;
}

const { rid, mid } = track;

if (!rid || !mid) {
return;
}

const unsubscribeFromDeleteMessage = subscribeToNotifyRoom(`${rid}/deleteMessage`, ({ _id }) => {
if (_id === mid) {
close();
}
});

const unsubscribeFromDeleteMessageBulk = subscribeToNotifyRoom(`${rid}/deleteMessageBulk`, ({ ids }) => {
if (ids?.includes(mid)) {
close();
}
});

return () => {
unsubscribeFromDeleteMessage();
unsubscribeFromDeleteMessageBulk();
};
}, [track, subscribeToNotifyRoom, close]);

//For soft message delete, when Message_ShowDeletedStatus is on and server updates message.t to rm
useEffect(() => {
if (!track) {
return;
}

const unsub = Messages.use.subscribe((state, prevState) => {
const { mid } = track;
if (!mid) {
return;
}

const message = state.records.get(mid);

if (message && message !== prevState.records.get(mid) && message.t === 'rm') {
close();
}
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd like for this to at least be isolated in it's own hook.

@yash-rajpal yash-rajpal removed this from the 8.7.0 milestone Jul 30, 2026
@dionisio-bot dionisio-bot Bot removed the stat: ready to merge PR tested and approved waiting for merge label Jul 30, 2026
@yash-rajpal yash-rajpal changed the title regression: Stop media player when message is not accessible fix: Stop media player when message is not accessible Jul 30, 2026
@alfredodelfabro alfredodelfabro added this to the 8.8.0 milestone Aug 4, 2026
Base automatically changed from release-8.7.0 to master August 7, 2026 01:58
@tassoevan
tassoevan changed the base branch from master to develop August 11, 2026 18:44
@alfredodelfabro alfredodelfabro modified the milestones: 8.8.0, 8.9.0 Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider type: bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants