Skip to content

feat: Added unread message count badge for channels / teams#40603

Open
devanshkansagra wants to merge 2 commits into
RocketChat:developfrom
devanshkansagra:fix#40461
Open

feat: Added unread message count badge for channels / teams#40603
devanshkansagra wants to merge 2 commits into
RocketChat:developfrom
devanshkansagra:fix#40461

Conversation

@devanshkansagra
Copy link
Copy Markdown

@devanshkansagra devanshkansagra commented May 18, 2026

Proposed changes (including videos or screenshots)

This PR adds unread count support for channels and teams when room notification settings are configured to count all messages.

Previously, channels/teams could be marked as unread visually through bold text or alert state, but no numeric unread badge was shown unless the subscription’s unread value was incremented. This made channel/team unread activity less visible than direct messages.

Demo

Screen.Recording.2026-05-19.at.1.45.11.AM.mov

Issue(s)

Steps to test or reproduce

  1. Create a standard channel or team with multiple users.
  2. Open the channel/team notification settings.
  3. Set:
    • Receive alerts: On
    • Mark as unread: On
  4. Send a new message in that channel/team from another user.
  5. Check the sidebar for the receiving user.

Further comments

Summary by CodeRabbit

  • Improvements
    • Unread message counters now properly respect per-subscription notification settings for both desktop and mobile notifications, ensuring counts align with your preferences.
    • Sidebar rendering performance improved with enhanced memoization for mention and unread status tracking, reducing unnecessary component updates.

Review Change Stack

@devanshkansagra devanshkansagra requested review from a team as code owners May 18, 2026 20:28
@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot Bot commented May 18, 2026

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

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 18, 2026

⚠️ No Changeset found

Latest commit: bcea128

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.

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

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 18, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 18, 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: 5ee160d5-ea4f-4c56-8916-957d7fb9c846

📥 Commits

Reviewing files that changed from the base of the PR and between 0673099 and bcea128.

📒 Files selected for processing (5)
  • apps/meteor/app/lib/server/lib/notifyUsersOnMessage.ts
  • apps/meteor/client/sidebar/RoomList/SidebarItemTemplateWithData.tsx
  • apps/meteor/client/views/navigation/sidebar/RoomList/SidebarItemWithData.tsx
  • packages/model-typings/src/models/ISubscriptionsModel.ts
  • packages/models/src/models/Subscriptions.ts
📜 Recent review details
🧰 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/sidebar/RoomList/SidebarItemTemplateWithData.tsx
  • apps/meteor/client/views/navigation/sidebar/RoomList/SidebarItemWithData.tsx
  • packages/model-typings/src/models/ISubscriptionsModel.ts
  • packages/models/src/models/Subscriptions.ts
  • apps/meteor/app/lib/server/lib/notifyUsersOnMessage.ts
🧠 Learnings (4)
📚 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/sidebar/RoomList/SidebarItemTemplateWithData.tsx
  • apps/meteor/client/views/navigation/sidebar/RoomList/SidebarItemWithData.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/sidebar/RoomList/SidebarItemTemplateWithData.tsx
  • apps/meteor/client/views/navigation/sidebar/RoomList/SidebarItemWithData.tsx
  • packages/model-typings/src/models/ISubscriptionsModel.ts
  • packages/models/src/models/Subscriptions.ts
  • apps/meteor/app/lib/server/lib/notifyUsersOnMessage.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • packages/model-typings/src/models/ISubscriptionsModel.ts
  • packages/models/src/models/Subscriptions.ts
  • apps/meteor/app/lib/server/lib/notifyUsersOnMessage.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • packages/model-typings/src/models/ISubscriptionsModel.ts
  • packages/models/src/models/Subscriptions.ts
  • apps/meteor/app/lib/server/lib/notifyUsersOnMessage.ts
🔇 Additional comments (5)
packages/model-typings/src/models/ISubscriptionsModel.ts (1)

91-92: LGTM!

Also applies to: 119-119

packages/models/src/models/Subscriptions.ts (1)

361-362: LGTM!

Also applies to: 368-369, 379-388, 574-592

apps/meteor/app/lib/server/lib/notifyUsersOnMessage.ts (1)

1-1: LGTM!

Also applies to: 87-100, 116-127, 141-159, 169-169

apps/meteor/client/sidebar/RoomList/SidebarItemTemplateWithData.tsx (1)

153-159: LGTM!

Also applies to: 198-218

apps/meteor/client/views/navigation/sidebar/RoomList/SidebarItemWithData.tsx (1)

90-96: LGTM!

Also applies to: 122-142


Walkthrough

The PR implements unread message counting for subscriptions with default "all messages" notification settings. It adds helper functions to detect eligible subscriptions, updates the subscription model with filtered query logic and a bulk unread increment method, and refines sidebar rendering to properly reflect unread state changes.

Changes

All-Messages Unread Counting

Layer / File(s) Summary
Subscription Model Contract
packages/model-typings/src/models/ISubscriptionsModel.ts
findByRoomIdAndNotAlertOrOpenExcludingUserIds filter type gains optional includeSubscriptionsWithDefaultDesktopNotification and includeSubscriptionsWithDefaultMobileNotification flags. New incUnreadForIds method added to increment unread for a list of subscription IDs.
Subscription Model Implementation
packages/models/src/models/Subscriptions.ts
findByRoomIdAndNotAlertOrOpenExcludingUserIds MongoDB query expands to conditionally match subscriptions with default notification settings when inclusion flags are provided. Previous incUnreadForRoomIdExcludingUserIds method replaced with incUnreadForIds for ID-based bulk increment.
Server Notification and Unread Logic
apps/meteor/app/lib/server/lib/notifyUsersOnMessage.ts
Helper functions determine whether subscriptions should count "all messages" based on unreadAlert and notification defaults. Account-level defaults are computed and passed to the subscription query. A dedicated filtering step selects subscription IDs requiring unread increments, avoiding double-counts from mention/unread-all rules, then calls incUnreadForIds. Per-subscription notifyOnSubscriptionChanged events use the same "should count all messages" predicate for shouldIncUnread.
Sidebar Rendering Updates
apps/meteor/client/sidebar/RoomList/SidebarItemTemplateWithData.tsx, apps/meteor/client/views/navigation/sidebar/RoomList/SidebarItemWithData.tsx
Both components gain safeArrayNotEqualCheck helper for null/undefined-safe string-array comparison. Extended memo comparators now include unread, mention toggles (userMentions, groupMentions), unread/mention visibility flags (hideUnreadStatus, hideMentionStatus), and unread-related arrays (tunread, tunreadUser), ensuring the UI re-renders when unread state changes.

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 accurately describes the main objective of the PR: adding numeric unread-count badge support for channels and teams.
Linked Issues check ✅ Passed The code changes directly implement the feature requested in issue #40461: incrementing unread counts for subscriptions with 'all messages' notification settings to display numeric badges.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing unread message count badges. Updates to notification query logic, helper functions for memoization, and incremental unread methods are all directly related to this objective.
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

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

Choose a reason for hiding this comment

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

No issues found across 5 files

Re-trigger cubic

@coderabbitai coderabbitai Bot added the type: feature Pull requests that introduces new feature label May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community type: feature Pull requests that introduces new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Notify all users of a team or channel, show number of unread messages

2 participants