Retrieve List of Conversations
In other words, as a logged-in user, how do I retrieve the latest conversations that I’ve been a part of? In order to fetch the list of conversations, you can use theConversationsRequest class. To use this class i.e to create an object of the ConversationsRequest class, you need to use the ConversationsRequestBuilder class. The ConversationsRequestBuilder class allows you to set the parameters based on which the conversations are to be fetched.
The ConversationsRequestBuilder class allows you to set the below parameters:
Set Limit
This method sets the limit i.e. the number of conversations that should be fetched in a single iteration.- Java (Set Limit)
Set Conversation Type
This method can be used to fetch user or group conversations specifically. TheconversationType variable can hold one of the below two values:
- user - Only fetches user conversation.
- group - Only fetches group conversations.
- Java
build() method to get the object of the ConversationsRequest class.
Once you have the object of the ConversationsRequest class, you need to call the fetchNext() method. Calling this method will return a list of Conversation objects containing X number of conversations depending on the limit set.
A Maximum of only 50 Conversations can be fetched at once.
- Java
- Kotlin
Conversationobject consists of the below fields:
| Field | Information |
|---|---|
conversationId | ID of the conversation |
conversationType | Type of conversation (user/group) |
lastMessage | Last message the conversation |
conversationWith | User or Group object containing the details of the user or group |
unreadMessageCount | Unread message count for the conversation |
Retrieve Single Conversation
In other words, as a logged-in user, how do I retrieve a specific conversation? In order to fetch a specific conversation, you can use thegetConversation method. The getConversation method accepts two parameters.
conversationWith: UID/GUID of the user/group whose conversation you want to fetch.conversationType: TheconversationTypevariable can hold one of the below two values:
- user - Only fetches user conversation.
- group - Only fetches group conversations.
- Java
- Kotlin
Convert Messages to Conversations
As per our Receive Messages guide, for real-time messages, you will always receiveMessage objects and not Conversation objects. Thus, you will need a mechanism to convert the Message object to a Conversation object. You can use the getConversationFromMessage method for this purpose.
- Java
While converting a
Message object to Conversation object, the unreadMessagecount will not be available in the Conversation object. As this is for the real-time events, the unread message count needs to be managed in your client-side code.