-
Notifications
You must be signed in to change notification settings - Fork 2k
Fix unread message counter not accounting for deleted messages #970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
or-else
merged 5 commits into
devel
from
copilot/fix-f4f37f1f-efcc-4cb4-9ff7-148964e37222
Nov 6, 2025
Merged
Fix unread message counter not accounting for deleted messages #970
or-else
merged 5 commits into
devel
from
copilot/fix-f4f37f1f-efcc-4cb4-9ff7-148964e37222
Nov 6, 2025
+266
−0
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Co-authored-by: or-else <[email protected]>
Co-authored-by: or-else <[email protected]>
Copilot
AI
changed the title
[WIP] Propose a solution to this bug: @tinode/chat/issues/898
Fix unread message counter not accounting for deleted messages
Aug 31, 2025
Copilot finished work on behalf of
or-else
August 31, 2025 13:05
or-else
reviewed
Nov 6, 2025
|
@copilot Please inplement fixes according to code review. |
…d hard delete test Co-authored-by: or-else <[email protected]>
Copilot finished work on behalf of
or-else
November 6, 2025 13:25
or-else
requested changes
Nov 6, 2025
…ateUnreadInRanges Co-authored-by: or-else <[email protected]>
Copilot finished work on behalf of
or-else
November 6, 2025 13:37
or-else
approved these changes
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Still weak, but OK, I'll clean it up later.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When a user deletes messages from a conversation, the unread message counters for other users are not updated to reflect that some of their unread messages have been deleted. This causes incorrect unread counts to be displayed in the UI.
Scenario:
This affects both online users and users who come back online later, and applies to both soft deletes and hard deletes.
Root Cause
The
handleNoteBroadcastfunction calculates unread counts using simple arithmetic (pud.readID - msg.Note.SeqId) without considering that some messages in the range may have been deleted. ThereplyDelMsgfunction successfully deletes messages but doesn't update unread counters for affected users.Solution
Added logic to update unread counters when messages are deleted:
Helper function
calculateUnreadInRanges: Efficiently calculates how many unread messages fall within given deletion ranges using intersection logic. Uses linear search to find the first relevant range (where rangeEnd > readID) and then iterates to sum up unread messages in the deleted ranges.Enhanced
replyDelMsg: After successful deletion, iterates through all users with read permissions and decreases their unread count by the number of unread messages that were deleted. This applies to:Minimal performance impact: Only runs during message deletion operations (rare events), not during normal read operations.
Technical Details
usersUpdateUnreadinfrastructure for consistencyTesting
calculateUnreadInRangescovering edge casesTestReplyDelMsgUpdatesUnreadCountersfor soft delete scenarioTestReplyDelMsgHardDeletefor hard delete scenarioExample calculation:
Fixes #898
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.