markAsRead not working


I can send chat messages to multiple users on several devices using group channels.
When the app resumes and when a new message is received, I use channel.markAsRead();

If I put a breakpoint in that method on the line await _sdk.cmdManager.sendCommand(cmd); I can see it triggers the breakpoint.

But onReadReceiptUpdated is not called (or very sporadically, might as well be never) on the other devices.
onMessageReceived does work.

My onMessageReceived looks like this

  void onMessageReceived(BaseChannel channel, BaseMessage message) async {
    print('NEW: ${message.message}');

      types.User(id: message.sender!.userId),
      id: message.messageId,
      createdAt: message.createdAt,
      skipState: false,

The message is shown, so that code works, only markAsRead is not doing anything.
I have tested on Android, iPad and web.

On Android I implemented push notifications, if I put the app in the background I get a push with the messages I missed.

Am I doing something wrong?

Thanks in advance

Okay, I figured out what I was doing wrong.
When the app goes in the background, or for other reasons, the connection can be dropped.
You can only mark messages as read when the connection is open.

So I needed to implement ConnectionEventHandler to check when the connection is working again.
sendbird.addConnectionEventHandler(kConnectionEventHandler, this);

I also mark as read after getting the channel:

channel = await GroupChannel.getChannel(tecClientSession.text);

Implementation of this handler:

  void onReconnectionSucceeded() {

  void _sendMarkAsRead() {
    if (sendbird.getConnectionState() == {
1 Like