Skip to content

fix: messages not marked as read when new message arrives in active room#7088

Open
divyanshu-patil wants to merge 2 commits intoRocketChat:developfrom
divyanshu-patil:fix/read-prbm-2
Open

fix: messages not marked as read when new message arrives in active room#7088
divyanshu-patil wants to merge 2 commits intoRocketChat:developfrom
divyanshu-patil:fix/read-prbm-2

Conversation

@divyanshu-patil
Copy link
Copy Markdown

@divyanshu-patil divyanshu-patil commented Apr 1, 2026

Proposed changes

When a new message arrived in a room the user was actively viewing, the unread count and read status were not being updated. The user had to leave and re-enter the room to trigger the read receipt.

This PR fixes a bug that caused this:
updateMessage promise never resolved updateMessage was written as new Promise(async resolve => ...) but only called resolve() in the early-return branch (this.rid !== message.rid). On the happy path — when the message did belong to the current room — the function did all its DB work and then silently hung forever. This meant await this.updateMessage(message) in handleMessageReceived never completed, so readMessages was never reached.

Fixed by converting updateMessage to a proper async function, eliminating the antipattern entirely.

Issue(s)

closes #7087

How to test or reproduce

  1. Open a room with another user/device
  2. Have the other user send a message while you are actively viewing the room
  3. Before: unread badge/count does not clear; read receipt not sent until you navigate away and back
  4. After: message is marked as read immediately upon arrival

Screenshots

Before

When a new message arrives in the currently subscribed room, the read status does not update

read.fix.before.mp4

After

When a new message arrives in the currently subscribed room, the read status updates after a debounced interval

read.fix.after.mp4

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • Improvement (non-breaking change which improves a current function)
  • New feature (non-breaking change which adds functionality)
  • Documentation update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if applicable)
  • I have added necessary documentation (if applicable)
  • Any dependent changes have been merged and published in downstream modules

Further comments

Summary by CodeRabbit

  • Refactor
    • Optimized internal message subscription handling for improved code maintainability and reliability.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 1, 2026

Walkthrough

The RoomSubscription.updateMessage method in app/lib/methods/subscriptions/room.ts was refactored from a Promise-wrapping arrow function to a native async function. The control flow logic for message decryption, upsert operations (message, thread, thread-message), and database persistence remains unchanged; only the Promise handling pattern was modernized.

Changes

Cohort / File(s) Summary
Method Refactoring
app/lib/methods/subscriptions/room.ts
Converted updateMessage from explicit Promise wrapping to async function syntax; early exit for rid mismatch now returns directly instead of resolving a Promise; all downstream logic (decryption, upserts, batch operations, error handling) preserved.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

type: bug

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main bug fix: messages not being marked as read when new messages arrive in the active room.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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.

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.

bug: Messages not marked as read when new message arrives in active room

1 participant