API To Retrieve Unread Count For More Then One Room At A Time


#1

I’ve seen this feature, or similar, requested in a lot of places, but for some reason they keep getting closed and pointed elsewhere stating that it is achievable via various methods. After some thorough investigation it seems that there is no easy way to do this without creating multiple requests.

Scenario: I want to show a list of all the DMs for a given user and have a notification icon if the DM has unread messages.

For now I need to call:
/dm.list : once
/dm.counters : for each DM returned, so if a user has 10 DMs open, thats 10 additional API requests that need to be handled. I’m sure you can see how this can get out of hand very quickly.

I tried using the lastMessage feature in /dm.list , but there is no way to indicate if the message is unread or not.

I’m not sure what the solution is, but possibly one of the following.

  • In the API Request /dm.list and an unread counter for each dm returned (Optimal)
  • In the API Request /dm.counters , allow us to retrieve counters via array of roomIds , and not just one (Most Viable)
  • In the API Request /dm.list with adding lastMessage , indicate weather the message is unread or not. (Will get the job done)

Maybe I’m doing it wrong, but if this is in fact unachievable right now, I believe it to be a vital part of the REST API

Thanks,


#2

What you actually want to do is use the subscriptions api. As each user has a subscription to the rooms which they are part of, thus all of the unread information resides on that user’s subscription object for a particular room.

https://rocket.chat/docs/developer-guides/rest-api/subscriptions/get/


#4

@bradley.hilton I just tried the subscription.get method but it doesn’t seem to be working well…
All I noticed is that if an user added a message to a channel of another user, the unread would not change but, if the user mentions the other one, the unread and userMentions would both change…

How can we get the non mentioned unread messages?


#5

Great question, either @rodrigo.nascimento or @diego.sampaio should be able to help you with that.


#6

I also noticed this issue on Github but it is closed and only says that was resolved on the chat (but does not say how)


#7

Thanks to @diego.sampaio, I just found out that the unreads count is controlled through the Administration on General => Unread Count :slight_smile: