Skip to main content
Quick Reference for AI Agents & Developers
// Fetch conversations with filters
val conversationsRequest = ConversationsRequestBuilder()
    .setLimit(50)
    .setConversationType(CometChatConstants.CONVERSATION_TYPE_USER)
    .build()

conversationsRequest.fetchNext(object : CallbackListener<List<Conversation>>() {
    override fun onSuccess(conversations: List<Conversation>) { }
    override fun onError(e: CometChatException) { }
})

// Get specific conversation
CometChat.getConversation("UID_or_GUID", "user", callback)
Available via: SDK | REST API | UI Kits
Conversations provide the last messages for every one-on-one and group conversation the logged-in user is a part of. This makes it easy for you to build a Recent Chat list.

Retrieve List of Conversations

How do I retrieve the latest conversations that I’ve been a part of? To fetch the list of conversations, use the ConversationsRequest class. 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 fetched. The ConversationsRequestBuilder class allows you to set the following parameters:

Set Limit

This method sets the limit i.e. the number of conversations that should be fetched in a single iteration.
ConversationsRequest conversationRequest = new ConversationsRequest.ConversationsRequestBuilder()
  .setLimit(100)
  .build();

Set Conversation Type

This method can be used to fetch user or group conversations specifically. The conversationType variable can hold one of the below two values:
  • user - Only fetches user conversation.
  • group - Only fetches group conversations.
If none is set, the list of conversations will include both user and group conversations.
ConversationsRequest conversationsRequest = new ConversationsRequest.ConversationsRequestBuilder()
  .setLimit(50)
  .setConversationType(CometChatConstants.CONVERSATION_TYPE_USER)
  .build();

With User and Group Tags

This method can be used to fetch the user/group tags in the Conversation Object. By default the value is false.
ConversationsRequest conversationsRequest = new ConversationsRequest.ConversationsRequestBuilder()
  .setLimit(50)
  .withUserAndGroupTags(true)
  .build();

Set User Tags

This method fetches user conversations that have the specified tags.
List<String> tags = new ArrayList<>();
tags.add("tag_1");
conversationsRequest = new ConversationsRequest.ConversationsRequestBuilder()
  .setLimit(10)
  .setUserTags(tags)
  .build();

Set Group Tags

List<String> tags = new ArrayList<>();
tags.add("tag_1");
conversationsRequest = new ConversationsRequest.ConversationsRequestBuilder()
  .setLimit(10)
  .setGroupTags(tags)
  .build();
This method fetches group conversations that have the specified tags.

With Tags

This method makes sure that the tags associated with the conversations are returned along with the other details of the conversations. The default value for this parameter is false
ConversationsRequest conversationsRequest = new ConversationsRequest.ConversationsRequestBuilder()
  .setLimit(50)
  .withTags(true)
  .build();

Set Tags

This method helps you fetch the conversations based on the specified tags.
List<String> tags = new ArrayList<>();
tags.add("archived");
ConversationsRequest conversationsRequest = new ConversationsRequest.ConversationsRequestBuilder()
  .setLimit(50)
  .setTags(tags)
  .build();

Include Blocked Users

This method helps you fetch the conversations of users whom the logged-in user has blocked.
ConversationsRequest conversationsRequest = new ConversationsRequest.ConversationsRequestBuilder()
  .setLimit(50)
  .includeBlockedUsers(true)
  .build();

With Blocked Info

This method helps you fetch the conversations of users whom the logged-in user has blocked.
ConversationsRequest conversationsRequest = new ConversationsRequest.ConversationsRequestBuilder()
  .setLimit(50)
  .withBlockedInfo(true)
  .build();

Search Conversations

This method helps you search a conversation based on User or Group name.
This feature is only available with Conversation & Advanced Search. The Conversation & Advanced Search is only available in Advanced & Custom plans. If you’re already on one of these plans, please enable the Conversation & Advanced Search from CometChat Dashboard (Open your app, navigate to Chats -> Settings -> General Configuration)
ConversationsRequest conversationsRequest = new ConversationsRequest.ConversationsRequestBuilder()
  .setLimit(50)
  .setSearchKeyword("Hiking")
  .build();

Unread Conversations

This method helps you fetch unread conversations.
This feature is only available with Conversation & Advanced Search. The Conversation & Advanced Search is only available in Advanced & Custom plans. If you’re already on one of these plans, please enable the Conversation & Advanced Search from CometChat Dashboard (Open your app, navigate to Chats -> Settings -> General Configuration)
ConversationsRequest conversationsRequest = new ConversationsRequest.ConversationsRequestBuilder()
  .setLimit(50)
  .setUnread(true)
  .build();
Finally, once all the parameters are set to the builder class, you need to call the 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.
ConversationsRequest conversationsRequest = new ConversationsRequest.ConversationsRequestBuilder().setLimit(50).build();

conversationsRequest.fetchNext(new CometChat.CallbackListener<List<Conversation>>() {
  @Override
  public void onSuccess(List<Conversation> conversations) {
    // Hanlde list of conversations

  }

  @Override
  public void onError(CometChatException e) {
    // Hanlde failure
  }
});
The Conversation object consists of the following fields:
FieldInformation
conversationIdID of the conversation
conversationTypeType of conversation (user/group)
lastMessageLast message the conversation
conversationWithUser or Group object containing the details of the user or group
unreadMessageCountUnread message count for the conversation

Tag Conversation

How do I tag a conversation? To tag a specific conversation, use the tagConversation() method. The tagConversation() method accepts three parameters.
  1. conversationWith: UID/GUID of the user/group whose conversation you want to fetch.
  2. conversationType: The conversationType variable can hold one of the below two values:
    1. user - Only fetches user conversation.
    2. group - Only fetches group conversations.
  3. tags: The tags variable will be a list of tags you want to add to a conversation.
String id = "cometchat-uid-1"; //id of the user/group
String conversationType = "user";
List<String> tags = new ArrayList<>();
tags.add("archived");

CometChat.tagConversation(id, conversationWith, tags, new CometChat.CallbackListener<Conversation>() {
  @Override
  public void onSuccess(Conversation conversation) {
    Log.d(TAG, conversation.toString());
  }

  @Override
  public void onError(CometChatException e) {
    Log.d(TAG, e.getMessage());
  }
});
The tags for conversations are one-way. This means that if user A tags a conversation with user B, that tag will be applied to that conversation only for user A.

Retrieve Single Conversation

How do I retrieve a specific conversation? To fetch a specific conversation, use the getConversation method. The getConversation method accepts two parameters.
  1. conversationWith: UID/GUID of the user/group whose conversation you want to fetch.
  2. conversationType: The conversationType variable can hold one of the below two values:
  • user - Only fetches user conversation.
  • group - Only fetches group conversations.
CometChat.getConversation(conversationWith, conversationType, new CometChat.CallbackListener<Conversation>() {
  @Override
  public void onSuccess(Conversation conversation) {
    // Handle getConversation success
  }

  @Override
  public void onError(CometChatException e) {
    // Handle getConversation error
  }
});

Convert Messages to Conversations

As per our Receive Messages guide, for real-time messages, you will always receive Message 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.
Conversation conversation = CometChatHelper.getConversationFromMessage(message);
While converting a Message object to a Conversation object, the unreadMessageCount & tags will not be available in the Conversation object. The unread message count needs to be managed in your client-side code.

Best Practices

Set a reasonable limit (30-50) and fetch conversations in batches. Maximum limit is 50 conversations per request.
Use setConversationType() to fetch only user or group conversations when building separate tabs or views.
Enable “Conversation & Advanced Search” in Dashboard and use setSearchKeyword() for better user experience with many conversations.
Tag conversations (e.g., “archived”, “pinned”, “important”) to organize and filter conversations based on user preferences.
When converting messages to conversations, manage unread counts in your app since they’re not included in the conversion.

Troubleshooting

Symptom: fetchNext() returns an empty list even though conversations exist.Cause: User hasn’t sent or received any messages, or filters are too restrictive.Solution: Remove filters temporarily to verify conversations exist. Check if the user has participated in any chats.
Symptom: setSearchKeyword() doesn’t filter conversations.Cause: “Conversation & Advanced Search” feature not enabled in Dashboard.Solution: Enable the feature in CometChat Dashboard under Chats → Settings → General Configuration. Available in Advanced & Custom plans only.
Symptom: setUnread(true) doesn’t filter unread conversations.Cause: “Conversation & Advanced Search” feature not enabled.Solution: Enable the feature in Dashboard. This is a premium feature available in Advanced & Custom plans.

Next Steps