Find unread items

I can get number of unread messages per channel with something like /users/{userId}/my_group_channels?limit=20&query_type=OR&unread_filter=unread_message
Iand get response containing something like
unread_message_count: 8} , how can I then collect the 8 unread messages ?

Hello @bengt.svensson and welcome to the Sendbird community!

Within your channel response for the user you have a user_last_read timestamp, which is when the user last read messages in the channel, "user_last_read": 1651594168929.

You can use the messages endpoint to get messages after that timestamp. The following would return the next 15 messages after the user last read messages in the channel.

Hi and thanks for the response
I have one follow up question , so say I have unread_message_count set to 40 and then collect 15 as you showed I still have 25 unread messages
But when I run my request above “user_last_read” will be the same as before , should that not have been updated or how do I that so the “user_last_read” will change to the most recent message collected ?

@bengt.svensson That is correct, user_last_read only changes when markAsRead() is called from a chat SDK, here is our documentation regarding this for the iOS SDK, Group channel: Advanced | Chat iOS SDK | Sendbird Docs.

In your example you could run the query again, changing the message_ts to be the timestamp of the last message received from the previous query.

However the Platform API should only be used server side and any client side functionality like messaging and getting unread message should be handled by one of the client side chat SDKs.

Why are you trying to get a user’s unread messages using the Platform API? I might be able to provide a better solution if I understand your use case.

Hi , We are using the Client side chat SDK for the vast majority of our clients , but we will also have a few 3rd party users that won’t have access to that therefor we are trying to give them access through our API which will use your API , it’s working all fine with the exception of the unread flag
I’ve seen there is a general ( for all channels ) unread flag that can be used , so our problem occur when we need to split up (paginate) the request ie to many unread message . So if you have an idea how to solve it we would be grateful

Hi again , have you had a time to think about an alternative solution ?

Hi @bengt.svensson, unfortunately there is not a good way to achieve that with the Platform API since it is not meant to be used from the client side.
As you can see there is no way to paginate messages so the best way would probably be to use timestamp of the last message retrieved through listing messages, List messages | Chat Platform API | Sendbird Docs, and use that message timestamp as the message_ts in the next query to get the next set of messages.