Channel unread count not reseting in <ChannelList> when message arrives when app is minimized.
Describe the bug
We are using
Dev environment info (please complete/provide the following information):
- Package version: stream-chat-react-native 3.7.2
- react-native: 63.4
- Device/Emulator: iOS 14.4 both simulator and actual device. Android 10 actual device.
To Reproduce Steps to reproduce the behavior:
- Open a page with
- Confirm unread count is not set on a given channel.
- Minimize app.
- On a different device/app, send a message to that channel.
- Open original app and see the unread count on that channel is now 1.
- Click on channel to read message.
- Close channel.
- Unread count is still 1.
Expected behavior
Unread count in
Additional context
We are also watching events on the same channel in the app and we see the message.read event come in and we are catching this and running channel.countUnread() and it's correctly returning 0. It's just that
Screenshots See attached video.
https://user-images.githubusercontent.com/203289/129954937-0daed346-d750-4139-ad4a-fb18f50228df.mov
Hey @jeffjvick could you please try upgrading to v3.9.0-next.6 and check?
Hi @vishalnarkhede. Sorry I hadn't updated this issue but I had "fixed" the problem by manually adding channel.watch() to all the of the channels I received from client.queryChannels(). I was under the impression that by default the query option 'watch' is set to true when I queryChannels based on the docs: https://getstream.io/chat/docs/react-native/query_channels/?language=javascript and that I didn't need to manually watch them.
I'm also finding that I need to "re-watch" the channel every time the app comes back to the foreground or my unread counts to update properly. I'm not sure if that is required or a "hack" to get around some underling issues. I'm also in general not really sure "watching" does internally.
Does this v3.9.0-next.6 fix some known issue related to this? Should I test this while also removing all the watches?
Hey @jeffjvick you don't need to manually add watch on channels. watch is added by default in queryChannels call - https://github.com/GetStream/stream-chat-js/blob/master/src/client.ts#L1766
Could you please confirm if you wait for client.connectUser() to succeed before rendering the Chat components?
Yes I await client.connectUser() before rending chat components. I don't need to do that every time the app goes to the foreground though do I?
With that commit should not be fixed this issue? I still face the same issue on 3.9.0
Hey @Marcoo09 We tested this on our TypescriptMessaging example app, and unfortunately couldn't reproduce. We would really appreciate if you could try the same and help us reproducing the issue on this example app.
@vishalnarkhede I updated our app to 3.9.1 and the issue persists. I see the change @Marcoo09 pointed out but that doesn't seem to address the issue as I can change that code to just force a markRead() anytime the channel is shown (regardless of scrolling or unreadCount) and the issue still persists.
I then decided to play around with TypscriptMessaging example app and like you said, it does not exhibit this behavior, however looking closer at it I was able to see what is different compared to our implementation and by making a small change I can replicate the issue on the example app.
I see you are providing the following options to the ChannelList:
const options = {
presence: true,
state: true,
watch: true,
};
Like so:
<ChannelList<
LocalAttachmentType,
LocalChannelType,
LocalCommandType,
LocalEventType,
LocalMessageType,
LocalResponseType,
LocalUserType
>
filters={memoizedFilters}
onSelect={(channel) => {
setChannel(channel);
navigation.navigate('Channel');
}}
options={options}
sort={sort}
/>
If I comment out these options, then the issue is exhibited. I then tested the specific options and it's the watch one that is the issue, if I leave that out, the issue is exhibited. This would likely explain why I was "fixing" the issue by manually issuing a watch.
I was not aware these options existed. They are not mentioned in the Tutorial. Is this documented somewhere that I missed? Is watching not the default behavior of the ChannelList?
@jeffjvick Some of the options are mentioned here in the docs, and the TypeScript files have what seems to be more details.
/**
* Object containing channel query options
* @see See [Channel query documentation](https://getstream.io/chat/docs/query_channels) for a list of available option fields
* */
options?: ChannelOptions;
export type ChannelOptions = {
last_message_ids?: { [key: string]: string };
limit?: number;
message_limit?: number;
offset?: number;
presence?: boolean;
recovery?: boolean;
state?: boolean;
user_id?: string;
watch?: boolean;
};
Seems like watch is supposed to be default, but like you we see significant issues with stream state not staying in sync, so we will try setting watch to true and see if that helps. Thanks for the post.
Hey @jeffjvick watch: true is a default behaviour of ChannelList - https://github.com/GetStream/stream-chat-js/blob/master/src/client.ts#L1769
Seems like its missing from the documentation and thanks for pointing it out. We will add it to docs soonish :)
@jehartzog thanks for pointing out the docs. I hope it helps your issue. It solved my problem.
@vishalnarkhede as @jehartzog pointed out, despite this being the default, I was experiencing issues in the unread counts not getting cleared if messages came in while the app is minimized (see my original post). There seems to be some issue with the defaults that forcing watch true in the optionals fixes. This is not just a documentation issue.
Thanks @jeffjvick ! We will investigate the issue on our side. But closing this ticket for now.
@vishalnarkhede is there any outcome from the investigation on your end? Unfortunately we're still seeing the issue for our users, still struggling to find a non-production repro though.
I'm closing this issue due to inactivity. If any questions arise, feel free to reach out!