CometChat.markAsRead not working

Hi
I got all the functions working, listener, get message count, get all messages.
However, I’m trying to set the messages as read using
CometChat.markAsRead(lastmessageID, friendID, “user”);
I get the last messageID by taking the id of the last message in that conversation
the friendID is the id of the user with the chat is
I get no error but the count unread count stays the same - CometChat.getUnreadMessageCountForUser(friendID);

Any suggestions?

Hello @icordoba,

markAsRead accepts three parameters:

  1. messageId: Id of the message you want to mark as read.
  2. receiverId: receiverId is the sender of the message for one-to-one and guid for group conversation.
  3. receiverType: user/group

Please make sure you are not marking your own messages as read. I have tested this on my end and it is working as expected. Can you please check once if you are sending appropriate values?

1 Like

Hi
I have checked all the data and they are correct. I even entered them manually instead of through variables. I tried setting it in several different screens. I even ported my project to another folder with latest versions of react native, react and expo. I consistently found the following, whenever I call, for example
CometChat.markAsRead(“41”, “5e2cab11b6daca62a89e3418”, “user”);

I get the following warning
[Unhandled promise rejection: Error: INVALID_STATE_ERR]

  • node_modules/react-native/Libraries/WebSocket/WebSocket.js:168:22 in send

  • node_modules/@cometchat-pro/react-native-chat/CometChat.js:1:200290 in u.Websocket.prototype._onIdle

  • node_modules/@cometchat-pro/react-native-chat/CometChat.js:1:184984 in g.Connection.prototype._onIdle

  • node_modules/@cometchat-pro/react-native-chat/CometChat.js:1:172927 in g.Connection.prototype.send

  • node_modules/@cometchat-pro/react-native-chat/CometChat.js:1:201367 in u.Websocket.prototype._reqToData

  • node_modules/@cometchat-pro/react-native-chat/CometChat.js:1:172789 in g.Connection.prototype.send

  • node_modules/@cometchat-pro/react-native-chat/CometChat.js:1:131638 in _.getJidFromUid.then$argument_0

  • node_modules/promise/setimmediate/core.js:37:14 in tryCallOne

  • node_modules/promise/setimmediate/core.js:123:25 in setImmediate$argument_0

  • node_modules/react-native/Libraries/Core/Timers/JSTimers.js:146:14 in _callTimer

  • node_modules/react-native/Libraries/Core/Timers/JSTimers.js:194:17 in _callImmediatesPass

  • node_modules/react-native/Libraries/Core/Timers/JSTimers.js:458:30 in callImmediates

  • [native code]:null in callImmediates
  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:407:6 in __callImmediates

  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:143:6 in __guard$argument_0

  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:384:10 in __guard

  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:142:17 in __guard$argument_0

  • [native code]:null in flushedQueue

  • [native code]:null in invokeCallbackAndReturnFlushedQueue

Everything else is working perfect except this function. If I can’t resolve this, I will have to abandon cometchat and look for another solution

1 Like

Ok, the error/warning is now gone and the markRead works
I was calling init of comet chat in my index with an unsubscribe function with componentDidMount as I needed to display the unread messages count in the tab badge. It seems that doing that caused an issue with the state. I’m now initializing the chat in the login screen without unsubscribe function

So, the only issue I have now is how to display the unread count as this needs to be done at the index level. But that’s not a cometchat question. I may have to use redux

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.