Unread message API not working as expected

Hello,

We are again experiencing issues with the unread message counter - we are using the APIs to get the unread messages and then are just counting them (we decided to go this route vs the SDK option, because for a long time this was the most reliable option, the SDK functionality was not working as expected).

Error Scenario #1:

  • user 2 is not online
  • user 1 calls user 2, but because no one is picking up user 1 cancels the call
  • user 2 logs into the app and we expect to see 2 unread messages but sees nothing - the CometChat Api returns an empty array of messages
    NOTE: If a user has no unread messages and misses calls, the API will return nothing for all of those missed calls, regardless of how many missed calls there are (be it 1 or be it 6)

Error Scenario #2:

  • user 2 is not online
  • user 1 calls user 2, but because no one is picking up user 1 cancels the call
  • user 2 logs in, goes in the chat area (without entering the conversation, so the “mark message as read” is not triggered) and sees no unread messages (up until this point this is Scenario #1) although there should be messages (the CometChat Api returns an empty array)
  • user 1 send a message to user 2
  • now all of the sudden user 2 sees unread messages - 3 to be exact for this test (so the expected number, 2 for the call and 1 for the actual message)
    NOTE: if the user has no unread messages, but receives calls that are missed, there will be no indicator of the missed calls until an actual text message is sent, when the text message is sent all of the missed calls are returned as well (so if the user has 6 missed call, the unread message array is empty but when the first unread message is received the array will have 13 items = 6*2 for the calls + 1 for the text message)

This item is related to this one https://forum.cometchat.com/t/unread-messages-counter-problem-on-all-plaforms/2436 (for additional details about the used API and SDKs)

Best regards,
Mihaela

Hello,

Do you have any updates for us?

Best,
Mihaela

Hello @MihaelaCazan,

Thank you for reporting this issue. We have identified the issue at our end and are working on the fix. I have created an issue in our internal tracker and will keep you updated on the same.

However, I would like to know why you are fetching the unread messages and not the unread message count directly?

Also, I would advise you to use the SDK method CometChat.getUnreadMessagesCount(), this method will return an Object which will have the UID/GUID as the key and the unread message count as the value. This will give you a correct unread count.

If you still wish to use the API, please send one more query param for fetching the count (count=true), this should give you an appropriate count of unread messages.

Also, as I mentioned in the reply to this forum post. The unread message count only counts the messages with the category message. Call messages won’t be counted in the unread message count.

I have created a feature request for fetching missed calls & call logs in the SDKs & APIs. I have added you to the feature request. You will get an update via email if/when the product team decides to take this up.

You can check the feature request here.

Warm Regards,

CometChat Pro
Mayur Bhandari

Hello @mayur.bhandari,

Thank you for looking into this and for working on a fix!

Also, thank you for the suggestions, we know of the SDK method existence but it was quite buggy for a long time (even some weeks/days back when we reported Unread messages counter problem on all plaforms - after the fix the API was back to the initial format but the method was still no OK when we tested it) and by means of multiple tests we discovered that the API version gave us a more stable flow and a lot more control (we could see the actual messages and analyze them, decide what to ignore vs just a number that might not reflect our needs).

Also, as I mentioned in the reply to this forum post. The unread message count only counts the messages with the category message. Call messages won’t be counted in the unread message count.

I miss to understand why the missed calls are not counted as unread messages and what the fix will be in this case (both Skype and WhatsApp count missed calls as unread messages) - my expectation is that the missed messages will be displayed + the missed calls in the unread messages. I also miss to see the explanation about the unread message count, if it is this part “I checked with the team internally and it was considered a bug that unread message count included missed calls incorrectly in the count” please give us additional details as it seems that your implementation and our expectations do not align.

Best regards,
Mihaela

Hello @MihaelaCazan,

You can fetch the unread messages using the SDK as well. You can use the MessagesRequestBuilder to fetch unread messages. To fetch unread messages you need to use the setUnread(true) method of the MessagesRequestBuilder(). You can read more about this method here.

To overcome this issue, we were working on a feature wherein if you want a call or custom message to be reflected in unread message count you will have to send a key in the metadata. If that key is present in the metadata then & only then that call or custom message will be used while calculating the unread message count. The key you need to send in the metadata is incrementUnreadCount. The value of this key can be either a true or 1.

I understand your concern here. Initially, the call messages were counted as unread messages and also reflected in the unread message count. But we found an issue where the call messages were not being counted accurately in the unread message count due to a bug, so we decided to remove the call messages from being counted in the unread message count because it was buggy and not 100% accurate. As you reported that the call messages appear as unread messages in the API response after you send a normal text message. We are working on a fix for the same.

Note: The unread messages & the unread message count will only take into account messages with the category message. Also, if you send the incrementUnreadCount key in the metadata of the message with category custom or call. It will only be used to calculate the unread message count and it will not be returned in the unread messages API.

Warm Regards,

CometChat Pro
Mayur Bhandari

Hello @mayur.bhandari ,

Thank you for clarifying the situation and for explaining your upcoming features.

Best regards,
Mihaela

1 Like