stream-chat-js icon indicating copy to clipboard operation
stream-chat-js copied to clipboard

Calling channelA.markRead() causes channelB.state.unreadCount to become 0

Open linhewinner opened this issue 2 years ago • 3 comments

Assuming channelA and channelB both have unread messages. Both of them have .state.unreadCount > 0. Now when I call channelA.markRead(), channelB.state.unreadCount is reset to 0.

This causes a couple of problems:

  1. I have some UI code that uses channel.state.unreadCount to render ... and my UI is wrong.
  2. In stream-chat-react, markRead is only called if state.unreadCount > 0

https://github.com/GetStream/stream-chat-react/blob/85855608582b7535f1e1fe1e36971aedf6d5b4cd/src/components/Channel/Channel.tsx#L394

I am running into a bug where a channel has unread message, but selecting it won't mark it as read because state.unreadCount is erroneously set to 0.

This is happening because in client.ts, the code appears to explicitly set .state.unreadCount to zero for ALL channels whenever "notification.mark_read" fires: https://github.com/GetStream/stream-chat-js/blob/c7679f243f25e387445327b18045fb5194001e46/src/client.ts#L1197-L1200

This is weird because "notification.mark_read" is fired when I call channelA.markRead() ... it is meant to mark ONE channel as read not ALL channels. The event's payload even has a "cid" field on it ....

Can someone explain what's going on here? Is "notification.mark_read" meant to be scoped to one channel or all channels?

linhewinner avatar Apr 01 '22 03:04 linhewinner

We have a similar issue, as multiple channels unreadCount goes to 0 when a single channel is opened. The other channels should keep their own unreadCount independently. Any ideas @vishalnarkhede ? Thanks.

baptistebriel avatar Sep 20 '22 11:09 baptistebriel

Hi @linhewinner, to narrow down the scope of this issue, can you please forward your request to [email protected] sharing the following information:

  1. App id at Stream;
  2. The SDK and version that you're working on.
  3. Describe the steps to reproduce the issue;
  4. A code snippet on how you're calling markRead;

Thanks and feel free to include any additional information or questions you have.

Regards, Guilherme Stream Support Engineer

gc0rtes avatar Sep 26 '22 09:09 gc0rtes

Hi @baptistebriel I got your ticket on support. As you have mentioned you're not using React Native. Let's keep this conversation over there.

Regards, Guilherme Stream Support Engineer

gc0rtes avatar Sep 26 '22 09:09 gc0rtes

@baptistebriel thanks for reaching out. We have contacted you via our customer supported and provided a solution by upgrading to v6.5.0 that contains a fix to the issue you encountered.

I'll be closing this issue for now. Please don't hesitate to contact us in the future if this issue or any questions arise.

vanGalilea avatar Nov 01 '22 10:11 vanGalilea