stream-chat-react-native icon indicating copy to clipboard operation
stream-chat-react-native copied to clipboard

Channel unread count not reseting in <ChannelList> when message arrives when app is minimized.

Open jeffjvick opened this issue 5 years ago • 13 comments

Describe the bug We are using in our app in a fairly cookie cutter manner. It is correctly displaying the channels and the unread counts on each channel when new messages come in. We are seeing an issue though when new messages arrive when the app is minimized, you open the app and click on the channel and come back to the and the unread count isn't getting reset. If you send a message to the channel while the app is open and you click on the channel and exit back out the count always gets reset fine. The count only gets stuck if the messages come in while the app is minimized.

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:

  1. Open a page with
  2. Confirm unread count is not set on a given channel.
  3. Minimize app.
  4. On a different device/app, send a message to that channel.
  5. Open original app and see the unread count on that channel is now 1.
  6. Click on channel to read message.
  7. Close channel.
  8. Unread count is still 1.

Expected behavior Unread count in should be reset after viewing the channel.

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 is not correctly reseting its counts.

Screenshots See attached video.

https://user-images.githubusercontent.com/203289/129954937-0daed346-d750-4139-ad4a-fb18f50228df.mov

jeffjvick avatar Aug 18 '21 18:08 jeffjvick

Hey @jeffjvick could you please try upgrading to v3.9.0-next.6 and check?

vishalnarkhede avatar Sep 28 '21 13:09 vishalnarkhede

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?

jeffjvick avatar Sep 29 '21 17:09 jeffjvick

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?

vishalnarkhede avatar Sep 30 '21 07:09 vishalnarkhede

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?

jeffjvick avatar Oct 05 '21 05:10 jeffjvick

With that commit should not be fixed this issue? I still face the same issue on 3.9.0

Marcoo09 avatar Oct 21 '21 17:10 Marcoo09

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 avatar Oct 21 '21 20:10 vishalnarkhede

@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 avatar Oct 27 '21 19:10 jeffjvick

@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.

jehartzog avatar Oct 28 '21 13:10 jehartzog

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 :)

vishalnarkhede avatar Oct 28 '21 14:10 vishalnarkhede

@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.

jeffjvick avatar Oct 28 '21 18:10 jeffjvick

Thanks @jeffjvick ! We will investigate the issue on our side. But closing this ticket for now.

vishalnarkhede avatar Oct 28 '21 18:10 vishalnarkhede

@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.

lucaswhitman avatar Jan 03 '22 17:01 lucaswhitman

I'm closing this issue due to inactivity. If any questions arise, feel free to reach out!

vanGalilea avatar May 20 '22 18:05 vanGalilea