fix: hidden system messages being counted on discussions
Proposed changes (including videos or screenshots)
The issue is that we are not filtering out from the discussion's message count those system messages that are intended to be 'hidden', either from the global Hide_System_Messages setting or from the room preferences.
So, to address this:
Backend-side
Messages.ts Added countVisibleByRoomIdContainingTypes model method to subtract that number to the overall room messages count. Also refreshDiscussionMetadata was modified to update the discussion metadata only if the parent message has a dlm (discussion last message timestamp) earlier than the room lm, avoiding race conditions with stale data.
saveRoomSettings.ts Added broadcast to update discussion metadata when the changed room has prid, meaning it's a discussion.
updateAndNotifyParentRoomWithParentMessage.ts After the extraction to a 'lib' file on the parent branch (see https://github.com/RocketChat/Rocket.Chat/pull/41702) the updateAndNotifyParentRoomWithParentMessage method logic was changed to filter out hidden system messages.
propagateDiscussionMetadata.ts sysMes property was added to the projection object, since it's needed for filtering them out from the overall message count in updateAndNotifyParentRoomWithParentMessage.
service.ts I've only added sysMes to the projection, since we need that property to update the parent message count correctly in line 220, taking into account those hidden types.
Client-side:
EditRoomInfo.tsx Added a hint on the 'Hide System Messages' option, as accorded with design and product team.
en.i18n.json Added the key for the hint.
Issue(s)
SUP-1080 Discussion Message Count Includes Hidden System Messages
Steps to test or reproduce
Known Limitations
- If you modify the
Hide system messagesglobal option (not the room-specific one) under Manage -> Settings -> Messages, you will notice the discussion count with those kind of system messages will not immediately update. Instead, you will have to send a regular message to recompute the count value, which is a reasonable trade-off, given that the global setting is usually configured once and adding a watcher for it to update each discussion parent message with the proper count would be a too expensive operation. Important to clarify that this doesn't happen with the room-specific setting. - Discussions previously with a mismatched count won't be fixed. Existing discussions will only correct their message count if the room-specific 'Hide system messages' option is updated or if a message is sent to the room.
Summary by CodeRabbit
Summary by CodeRabbit
- New Features
- Discussion message counts now exclude system messages hidden globally or within the discussion.
- Counts and latest-message timestamps update when hidden-message settings change.
- Added an explanatory hint to the room edit panel describing hidden-message counting.
- Bug Fixes
- Corrected discussion metadata synchronization after system-message visibility settings are updated.
- Tests
- Expanded coverage for visible, room-hidden, and globally hidden system messages.