Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions apps/meteor/app/lib/server/lib/notifyUsersOnMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async function updateUsersSubscriptions(message: IMessage, room: IRoom): Promise
roomId: room._id,
uidsExclude: [message.u._id],
uidsInclude: userIds,
onlyRead: !toAll && !toHere && !unreadAllMessages,
onlyRead: !toAll && !toHere && !unreadAllMessages && room.t !== 'd',
}).toArray();

// Give priority to user mentions over group mentions
Expand All @@ -115,7 +115,7 @@ async function updateUsersSubscriptions(message: IMessage, room: IRoom): Promise
await Subscriptions.incGroupMentionsAndUnreadForRoomIdExcludingUserId(room._id, message.u._id, 1, groupMentionInc);
}

if (!toAll && !toHere && unreadAllMessages) {
if (!toAll && !toHere && (unreadAllMessages || room.t === 'd')) {
await Subscriptions.incUnreadForRoomIdExcludingUserIds(room._id, [...userIds, message.u._id], 1);
}
Comment on lines +118 to 120
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

rg -n "Unread_Count_DM" --type ts -C 3

Repository: RocketChat/Rocket.Chat

Length of output: 1034


🏁 Script executed:

cat -n apps/meteor/app/lib/server/lib/notifyUsersOnMessage.ts | head -150

Repository: RocketChat/Rocket.Chat

Length of output: 6772


🏁 Script executed:

# Search for Unread_Count_DM in all file types to understand its definition
rg "Unread_Count_DM" -C 5

Repository: RocketChat/Rocket.Chat

Length of output: 50378


🏁 Script executed:

# Get the full setting definition for Unread_Count_DM
sed -n '146,160p' apps/meteor/server/settings/general.ts

Repository: RocketChat/Rocket.Chat

Length of output: 380


🏁 Script executed:

# Also check what values are allowed for the setting
rg -A 20 "this.add\('Unread_Count_DM'" apps/meteor/server/settings/general.ts

Repository: RocketChat/Rocket.Chat

Length of output: 483


🏁 Script executed:

# Look for any comments or recent changes around the lines in question
sed -n '85,135p' apps/meteor/app/lib/server/lib/notifyUsersOnMessage.ts

Repository: RocketChat/Rocket.Chat

Length of output: 2186


🏁 Script executed:

# Get the exact function context around lines 50-58 to see the precedent
sed -n '48,59p' apps/meteor/app/lib/server/lib/notifyUsersOnMessage.ts

Repository: RocketChat/Rocket.Chat

Length of output: 820


🏁 Script executed:

# Verify the values parameter for Unread_Count_DM is complete
rg -A 15 "'mentions_only'" apps/meteor/server/settings/general.ts | head -20

Repository: RocketChat/Rocket.Chat

Length of output: 422


Unread_Count_DM setting is effectively bypassed for general unread increments on DM rooms

The room.t === 'd' guard at lines 118-120 and 130 unconditionally increments unread counts for all DM messages, overriding the Unread_Count_DM setting when configured to mentions_only. This creates an inconsistency: while user and group mention increments correctly treat DMs as a special case (lines 50-58 always return 1 for DMs), the general unread increment ignores the setting entirely for DM rooms.

This may be intentional per historical DM notification behavior, but since Unread_Count_DM remains configurable with two distinct options, confirm with the product team whether the setting should be fully ignored for the unread increment path in DMs, or whether a narrower condition (e.g., only bypass when unreadCount !== 'mentions_only') is intended.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/meteor/app/lib/server/lib/notifyUsersOnMessage.ts` around lines 118 -
120, The DM branch currently forces general unread increments by calling
Subscriptions.incUnreadForRoomIdExcludingUserIds when room.t === 'd', which
bypasses the Unread_Count_DM setting; update the condition (the if that uses
toAll, toHere, unreadAllMessages and room.t) to consult the Unread_Count_DM
value (e.g., unreadCount or however the setting is read in this module) and only
treat DMs as auto-incrementing when the setting is not 'mentions_only' (i.e.,
change the room.t === 'd' check to something like room.t === 'd' && unreadCount
!== 'mentions_only'), ensuring Subscriptions.incUnreadForRoomIdExcludingUserIds
is only called when the configured policy allows it.


Expand All @@ -127,12 +127,12 @@ async function updateUsersSubscriptions(message: IMessage, room: IRoom): Promise

subs.forEach((sub) => {
const hasUserMention = userIds.includes(sub.u._id);
const shouldIncUnread = hasUserMention || toAll || toHere || unreadAllMessages;
const shouldIncUnread = hasUserMention || toAll || toHere || unreadAllMessages || room.t === 'd';
void notifyOnSubscriptionChanged(
{
...sub,
alert: true,
open: true,
// open: true,
...(shouldIncUnread && { unread: sub.unread + 1 }),
...(hasUserMention && { userMentions: sub.userMentions + 1 }),
...((toAll || toHere) && { groupMentions: sub.groupMentions + 1 }),
Expand Down