Skip to main content

Documentation Index

Fetch the complete documentation index at: https://cometchat-22654f5b-docs-android-v6-beta2.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

// Build filtered message request
val messagesRequest = MessagesRequestBuilder()
    .setUID("user_uid")                    // User conversation
    .setLimit(50)                          // Max 100 per request
    .setCategories(listOf("message"))      // Filter by category
    .setTypes(listOf("text", "image"))     // Filter by type
    .setUnread(true)                       // Only unread messages
    .hideDeletedMessages(true)             // Exclude deleted
    .hideReplies(true)                     // Exclude threaded messages
    .build()

// Fetch messages
messagesRequest.fetchNext(callback)
messagesRequest.fetchPrevious(callback)
The MessagesRequest class fetches messages based on various parameters using the Builder design pattern. To fetch messages:
  1. Create a MessagesRequestBuilder object
  2. Set your desired parameters
  3. Call build() to get a MessagesRequest object
  4. Call fetchNext() or fetchPrevious() to retrieve messages
MethodDescription
fetchNext()Returns messages after the specified parameters
fetchPrevious()Returns messages before the specified parameters
Messages are paginated with a maximum of 100 per request. Call fetchPrevious()/fetchNext() repeatedly on the same object to get subsequent pages.

Filter Reference

MethodDescriptionDefault
setUID(uid)Fetch messages for a one-on-one conversation
setGUID(guid)Fetch messages for a group conversation
setLimit(n)Number of messages per request (max 100)
setMessageId(id)Fetch messages before/after a message ID
setTimestamp(ts)Fetch messages before/after a Unix timestamp
setUnread(bool)Fetch only unread messagesfalse
setCategories(list)Filter by message categoriesall
setTypes(list)Filter by message typesall
setParentMessageId(id)Fetch messages in a specific thread
hideReplies(bool)Exclude threaded messagesfalse
hideDeletedMessages(bool)Exclude deleted messagesfalse
hideQuotedMessages(bool)Exclude quoted messagesfalse
hideMessagesFromBlockedUsers(bool)Exclude messages from blocked usersfalse
setUpdatedAfter(ts)Fetch messages updated after a timestamp
updatesOnly(bool)Only updated messages (use with setUpdatedAfter)false
setTags(list)Filter by message tags
withTags(bool)Include tag data in responsefalse
hasLinks(bool)Only messages with links (Advanced Search)false
hasAttachments(bool)Only messages with attachments (Advanced Search)false
hasReactions(bool)Only messages with reactions (Advanced Search)false
hasMentions(bool)Only messages with mentions (Advanced Search)false
setMentionedUIDs(list)Only messages mentioning specific users (Advanced Search)
setAttachmentTypes(list)Only messages with specific attachment types (Advanced Search)

Number of messages fetched

Set the number of messages to fetch per request using setLimit(). Maximum is 100.
String UID = "cometchat-uid-1";

MessagesRequest messagesRequest = new MessagesRequest.MessagesRequestBuilder()
.setLimit(50)
.setUID(UID)
.build();

Messages for a user conversation

Use setUID() to fetch messages between the logged-in user and a specific user.
MessagesRequest messagesRequest = new MessagesRequest.MessagesRequestBuilder()
.setUID("cometchat-uid-1")
.setLimit(50)
.build();

Messages for a group conversation

Use setGUID() to fetch messages from a group. The logged-in user must be a member of the group.
MessagesRequest messagesRequest = new MessagesRequest.MessagesRequestBuilder()
.setGUID("cometchat-guid-1")
.setLimit(50)
.build();

Messages before/after a message

Use setMessageId() to fetch messages before or after a specific message ID. Use fetchNext() to get messages after, or fetchPrevious() to get messages before.
String UID = "cometchat-uid-1";

MessagesRequest messagesRequest = new MessagesRequest.MessagesRequestBuilder()
  .setMessageId(100)
  .setLimit(50)
  .setUID(UID)
  .build();
This method can be combined with setUID() or setGUID() to fetch messages around a specific message in a conversation.

Messages before/after a given time

Use setTimestamp() with a Unix timestamp to fetch messages before or after a specific time.
String UID = "cometchat-uid-1";

MessagesRequest messagesRequest = new MessagesRequest.MessagesRequestBuilder()
  .setTimestamp(1512687363)
  .setLimit(50)
  .setUID(UID)
  .build();
This method can be combined with setUID() or setGUID() to fetch messages around a specific time in a conversation.

Unread messages

Use setUnread(true) to fetch only unread messages.
String UID = "cometchat-uid-1";

MessagesRequest messagesRequest = new MessagesRequest.MessagesRequestBuilder()
  .setUnread(true)
  .setLimit(50)
  .setUID(UID)
  .build();
This method along with setGUID() or setUID() can be used to fetch unread messages for a particular group or user conversation respectively.

Exclude messages from blocked users

Use hideMessagesFromBlockedUsers(true) to exclude messages from users you’ve blocked. Default is false.
String UID = "cometchat-uid-1";

MessagesRequest messagesRequest = new MessagesRequest.MessagesRequestBuilder()
  .hideMessagesFromBlockedUsers(true)
  .setUID(UID)
  .setLimit(50)
  .build(); 
This also works in group conversations where both users are members.

Updated and received messages

Use setUpdatedAfter() with a Unix timestamp to fetch messages that were sent or updated after a specific time. Updated messages include those marked as read/delivered, edited, or deleted.
String UID = "cometchat-uid-1";

MessagesRequest messagesRequest = new MessagesRequest.MessagesRequestBuilder()
  .setUpdatedAfter(1514321321)
  .setLimit(50)
  .setUID(UID)
  .build();
Useful for syncing messages with a local database — fetch only what’s changed since your last sync.

Updated messages only

Use updatesOnly(true) with setUpdatedAfter() to fetch only updated messages (not newly received ones). This method must be used together with setUpdatedAfter().
String UID = "cometchat-uid-1";

MessagesRequest messagesRequest = new MessagesRequest.MessagesRequestBuilder()
  .setUpdatedAfter(1514321321)
  .updatesOnly(true)
  .setLimit(50)
  .setUID(UID)
  .build();

Messages for multiple categories

Use setCategories() with a list of category names to filter by message category. See Message structure and hierarchy for available categories.
String GUID = "cometchat-guid-1";
List<String> categories = new ArrayList<>();
categories.add("message");
categories.add("custom");

MessagesRequest messagesRequest = new MessagesRequest.MessagesRequestBuilder()
  .setCategories(categories)
  .setLimit(50)
  .setGUID(GUID)
  .build();
The above snippet fetches only messages in the message and custom categories. Use this to exclude categories like call and action.

Messages for multiple types

Use setTypes() with a list of type names to filter by message type. See Message structure and hierarchy for available types.
String UID = "cometchat-uid-1";
List<String> categories = new ArrayList<>();
categories.add("message");
List<String> types = new ArrayList<>();
types.add("image");
types.add("video");
types.add("audio");
types.add("file");

MessagesRequest messagesRequest = new MessagesRequest.MessagesRequestBuilder()
  .setCategories(categories)
  .setTypes(types)
  .setLimit(50)
  .setUID(UID)
  .build();
The above snippet fetches all media messages (image, video, audio, file).

Messages for a specific thread

Use setParentMessageId() to fetch messages belonging to a specific thread.
String UID = "cometchat-uid-1";

MessagesRequest messagesRequest = new MessagesRequest.MessagesRequestBuilder()
  .setLimit(50)
  .setUID(UID)
  .setParentMessageId(100)
  .build();
The above code snippet returns the messages that belong to the thread with parent id 100.

Hide threaded messages in user/group conversations

Use hideReplies(true) to exclude threaded messages from the main conversation. Default is false.
String UID = "cometchat-uid-1";

MessagesRequest messagesRequest = new MessagesRequest.MessagesRequestBuilder()
  .setLimit(50)
  .hideReplies(true)
  .setUID(UID)
  .build();

Hide deleted messages in user/group conversations

Use hideDeletedMessages(true) to exclude deleted messages. Default is false.
String UID = "cometchat-uid-1";

MessagesRequest messagesRequest = new MessagesRequest.MessagesRequestBuilder()
  .setLimit(50)
  .setUID(UID)
  .hideDeletedMessages(true)
  .build();

Hide quoted messages in user/group conversations

Use hideQuotedMessages(true) to exclude quoted messages. Default is false.
String UID = "cometchat-uid-1";

MessagesRequest messagesRequest = new MessagesRequest.MessagesRequestBuilder()
  .setLimit(50)
  .setUID(UID)
  .hideQuotedMessages(true)
  .build();

Messages by tags

Use setTags() with a list of tag names to fetch only messages with those tags.
String UID = "cometchat-uid-1";
List<String> tags = new ArrayList<>();
tags.add("pinned");

MessagesRequest messagesRequest = new MessagesRequest.MessagesRequestBuilder()
  .setLimit(50)
  .setUID(UID)
  .setTags(tags)
  .build();

Messages with tags

Use withTags(true) to include tag information in the response. Default is false. When withTags(true) is set, each message’s tags field will be populated. Access tags using getTags().
Additional FieldGetterReturn TypeDescription
tagsgetTags()List<String>Tags associated with the message
String UID = "cometchat-uid-1";

MessagesRequest messagesRequest = new MessagesRequest.MessagesRequestBuilder()
  .setLimit(50)
  .setUID(UID)
  .withTags(true)
  .build();
Use hasLinks(true) to fetch only messages containing links. Default is false.
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)
String UID = "cometchat-uid-1";

MessagesRequest messagesRequest = new MessagesRequest.MessagesRequestBuilder()
  .setLimit(50)
  .setUID(UID)
  .hasLinks(true)
  .build();

Messages with attachments

Use hasAttachments(true) to fetch only messages with attachments (image, audio, video, or file). Default is false.
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)
String UID = "cometchat-uid-1";

MessagesRequest messagesRequest = new MessagesRequest.MessagesRequestBuilder()
  .setLimit(50)
  .setUID(UID)
  .hasAttachments(true)
  .build();

Messages with reactions

Use hasReactions(true) to fetch only messages that have reactions. Default is false.
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)
String UID = "cometchat-uid-1";

MessagesRequest messagesRequest = new MessagesRequest.MessagesRequestBuilder()
  .setLimit(50)
  .setUID(UID)
  .hasReactions(true)
  .build();

Messages with mentions

Use hasMentions(true) to fetch only messages that contain mentions. Default is false.
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)
String UID = "cometchat-uid-1";

MessagesRequest messagesRequest = new MessagesRequest.MessagesRequestBuilder()
  .setLimit(50)
  .setUID(UID)
  .hasMentions(true)
  .build();

Messages with particular user mentions

Use setMentionedUIDs() with a list of UIDs to fetch only messages that mention those specific users.
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)
String UID = "cometchat-uid-1";
List<String> mentionedUIDs = new ArrayList<>();
mentionedUIDs.add("cometchat-uid-1");

MessagesRequest messagesRequest = new MessagesRequest.MessagesRequestBuilder()
  .setLimit(50)
  .setUID(UID)
  .setMentionedUIDs(mentionedUIDs)
  .build();

Messages with specific attachment types

Use setAttachmentTypes() with a list of AttachmentType enum values to fetch only messages with specific attachment types.
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)
String UID = "cometchat-uid-1";
  List<AttachmentType> attachmentTypes = new ArrayList<>();
  attachmentTypes.add(AttachmentType.IMAGE);
  attachmentTypes.add(AttachmentType.FILE);

  MessagesRequest messagesRequest = new MessagesRequest.MessagesRequestBuilder()
      .setLimit(50)
      .setUID("UID")
      .setAttachmentTypes(attachmentTypes)
      .build();

Next Steps

Receive Messages

Handle incoming messages with message listeners

Message Structure

Understand message categories and types

Threaded Messages

Implement threaded conversations with parent messages

Retrieve Conversations

Fetch conversation list with unread counts