fix(thread): handle notification.mark_unread event#1778
Open
TabishRiazBajwa wants to merge 1 commit into
Open
Conversation
## Summary
Fixes #3076
`Thread` currently subscribes to `message.read` events to keep its read
state up to date, but never subscribes to `notification.mark_unread`
events. This means that when a user marks a thread as unread, the
`Thread`'s local state never reflects it — `unreadMessageCount` stays
stale until the thread is reloaded.
## Root cause
`Channel` already has a working handler for `notification.mark_unread`
(see `channel.ts`), and `Thread` already has all the state infrastructure
needed (`ThreadUserReadState` with `unreadMessageCount`, `lastReadAt`,
`lastReadMessageId`) — it was just never wired up to this event.
## Changes
- Added `subscribeRepliesMarkUnread()` to `Thread`, following the same
`.on()` + filter pattern as the existing `subscribeRepliesRead()`
- Registered the new subscription in `registerSubscriptions()`
- Added 3 new test cases in `threads.test.ts`:
- Ignores events from other threads (filtered by `parent_message_id`)
- Ignores events for other users (only updates the current user's state)
- Correctly updates `unreadMessageCount`, `lastReadAt`, and
`lastReadMessageId` for the current user
## Testing
All existing tests in `threads.test.ts` pass (87/87), including the 3 new
ones added for this fix.
## Notes
- Did not add `first_unread_message_id` tracking since `ThreadUserReadState`
doesn't currently have an equivalent field (unlike `ChannelState`) —
happy to add this in a follow-up if desired.
- Did not call `messageReceiptsTracker`, consistent with the existing
`subscribeRepliesRead()` handler, since thread delivery receipts aren't
supported yet.
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
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.
Summary
Fixes #3076
Threadcurrently subscribes tomessage.readevents to keep its read state up to date, but never subscribes tonotification.mark_unreadevents. This means that when a user marks a thread as unread, theThread's local state never reflects it —unreadMessageCountstays stale until the thread is reloaded.Root cause
Channelalready has a working handler fornotification.mark_unread(seechannel.ts), andThreadalready has all the state infrastructure needed (ThreadUserReadStatewithunreadMessageCount,lastReadAt,lastReadMessageId) — it was just never wired up to this event.Changes
subscribeRepliesMarkUnread()toThread, following the same.on()+ filter pattern as the existingsubscribeRepliesRead()registerSubscriptions()threads.test.ts:parent_message_id)unreadMessageCount,lastReadAt, andlastReadMessageIdfor the current userTesting
All existing tests in
threads.test.tspass (87/87), including the 3 new ones added for this fix.Notes
first_unread_message_idtracking sinceThreadUserReadStatedoesn't currently have an equivalent field (unlikeChannelState) — happy to add this in a follow-up if desired.messageReceiptsTracker, consistent with the existingsubscribeRepliesRead()handler, since thread delivery receipts aren't supported yet.CLA
Description of the changes, What, Why and How?
Changelog