Description
When marking a thread as read via channel.markRead({ thread_id }), the resulting message.read event incorrectly resets channelState.unreadCount = 0, even though only the thread was marked as read, not the channel.
Location
|
if (isOwnEvent) { |
|
channelState.unreadCount = 0; |
|
client.syncDeliveredCandidates([this]); |
|
} |
if (isOwnEvent) {
channelState.unreadCount = 0;
client.syncDeliveredCandidates([this]);
}
Steps to Reproduce
- User A sends a message M1 to User B in a 1:1 DM channel
- User A replies in a thread to M1 (creates thread T1)
- User B has: 1 unread channel message (M1) + 1 unread thread (T1)
- User B marks thread T1 as read via
channel.markRead({ thread_id: T1.id })
- Bug:
channel.state.unreadCount becomes 0, even though M1 is still unread
Expected Behavior
channel.state.unreadCount should remain unchanged when marking a thread as read. The channel unread count should only reset when the channel itself is marked as read (i.e., when markRead() is called without a thread_id).
Suggested Fix
Check if the message.read event is for a thread (via event.thread) before resetting the channel unread count:
case 'message.read':
if (event.user?.id && event.created_at) {
// ... existing read state update code ...
const isOwnEvent = event.user?.id === client.user?.id;
const isThreadRead = Boolean(event.thread);
if (isOwnEvent && !isThreadRead) { // ← Add thread check
channelState.unreadCount = 0;
client.syncDeliveredCandidates([this]);
}
}
break;
Impact
This bug affects any application that:
- Uses threads alongside channel messages
- Displays separate unread counts for channels and threads
- Expects marking a thread as read to NOT affect channel unread state
Workaround
We're currently working around this by maintaining our own lastRead timestamp that only updates on channel reads (not thread reads), and manually calculating unread count from messages.
Environment
stream-chat version: Latest (verified bug exists in current main branch)
Description
When marking a thread as read via
channel.markRead({ thread_id }), the resultingmessage.readevent incorrectly resetschannelState.unreadCount = 0, even though only the thread was marked as read, not the channel.Location
stream-chat-js/src/channel.ts
Lines 1947 to 1950 in 32705e1
Steps to Reproduce
channel.markRead({ thread_id: T1.id })channel.state.unreadCountbecomes 0, even though M1 is still unreadExpected Behavior
channel.state.unreadCountshould remain unchanged when marking a thread as read. The channel unread count should only reset when the channel itself is marked as read (i.e., whenmarkRead()is called without athread_id).Suggested Fix
Check if the
message.readevent is for a thread (viaevent.thread) before resetting the channel unread count:Impact
This bug affects any application that:
Workaround
We're currently working around this by maintaining our own
lastReadtimestamp that only updates on channel reads (not thread reads), and manually calculating unread count from messages.Environment
stream-chatversion: Latest (verified bug exists in currentmainbranch)