Skip to main content
Quick Reference - Send a threaded message and fetch thread replies:
// Send a text message in a thread
let textMessage = new CometChat.TextMessage("UID", "Hello", CometChat.RECEIVER_TYPE.USER);
textMessage.setParentMessageId(100);
CometChat.sendMessage(textMessage).then(
  message => console.log("Sent:", message),
  err => console.log("Error:", err)
);

// Fetch messages for a thread
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setLimit(30)
  .setParentMessageId(100)
  .build();
messagesRequest.fetchPrevious().then(
  messages => console.log("Thread messages:", messages),
  error => console.log("Error:", error)
);
Available via: SDK | REST API | UI Kits
Messages that are started from a particular message are called Threaded Messages or simply threads. Each thread is attached to a message which is the parent message for that thread.

Send Message in a Thread

As mentioned in the Send a Message section, you can either send a message to a user or a group based on the receiverType and the UID/GUID specified for the message. A message can belong to any of the following types:
  1. Text Message
  2. Media Message
  3. Custom Message
Any of the above messages can be sent in a thread. A thread is identified based on the parent message, so while sending a message the parentMessageId must be set to indicate that the message belongs to the thread with the specified parentMessageId. This can be achieved using the setParentMessageId() method provided by the object of the TextMessage, MediaMessage, and CustomMessage class. The id specified in the setParentMessageId() method maps the message sent to the particular thread.
The parentMessageId is dynamic and corresponds to the actual id of the parent message you want to reply to. In the code examples below, we use placeholder values like 100 or 1, but in practice, you’ll use the actual message ID obtained from your message list or real-time listener.
Example to send a text message in a thread in a user conversation:
let textMessage = new CometChat.TextMessage(UID, "Hello", CometChat.RECEIVER_TYPE.USER);
textMessage.setParentMessageId(100); // Replace with actual parent message ID

CometChat.sendMessage(textMessage).then(
  message => {
      console.log('Message sent successfully', message);
  }, err => {
      console.log('err', err);
  }
)
The above snippet shows how a message with the text “Hello” can be sent in the thread with parentMessageId 100. Similarly, using the setParentMessageId() method, Media and Custom Messages can be sent in threads too.
On SuccesssendMessage() returns the sent threaded message with parentMessageId:Message Object:
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25293"
conversationIdstringConversation identifier"cometchat-uid-6_user_cometchat-uid-7"
receiverIdstringReceiver’s UID"cometchat-uid-7"
receiverTypestringType of receiver"user"
typestringMessage type"text"
categorystringMessage category"message"
textstringMessage text content"Hello thread!"
sentAtnumberUnix timestamp when sent1771839799
updatedAtnumberUnix timestamp when updated1771839799
parentMessageIdstringID of the parent message this reply belongs to"25291"
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataSee below ↓
metadataobjectMessage metadataSee below ↓
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether current user is mentionedfalse

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-6"
namestringUser’s display name"Ronald Jerry"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771839550
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-7"
namestringUser’s display name"Henry Marino"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-7.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771839549
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

data Object:
ParameterTypeDescriptionSample Value
textstringMessage text"Hello thread!"
resourcestringSDK resource identifier"REACT_NATIVE-4_0_14-..."
entitiesobjectSender and receiver entitiesSee below ↓
metadataobjectInjected metadataSee below ↓
moderationobjectModeration status{"status": "pending"}

data.entities Object:
ParameterTypeDescriptionSample Value
senderobjectSender entity wrapperSee below ↓
receiverobjectReceiver entity wrapperSee below ↓

data.entities.sender Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.sender.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-6"
namestringUser’s display name"Ronald Jerry"
avatarstringUser’s avatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp"
rolestringUser’s role"default"
statusstringUser’s online status"online"
lastActiveAtnumberLast active timestamp1771839550
tagsarrayUser tags[]

data.entities.receiver Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.receiver.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-7"
namestringUser’s display name"Henry Marino"
avatarstringUser’s avatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-7.webp"
rolestringUser’s role"default"
statusstringUser’s online status"online"
lastActiveAtnumberLast active timestamp1771839549
conversationIdstringConversation identifier"cometchat-uid-6_user_cometchat-uid-7"
tagsarrayUser tags[]

data.metadata Object:
ParameterTypeDescriptionSample Value
@injectedobjectInjected extensions dataSee below ↓

data.metadata.@injected Object:
ParameterTypeDescriptionSample Value
extensionsobjectExtensions dataSee below ↓

data.metadata.@injected.extensions Object:
ParameterTypeDescriptionSample Value
link-previewobjectLink preview extensionSee below ↓

data.metadata.@injected.extensions.link-preview Object:
ParameterTypeDescriptionSample Value
linksarrayExtracted links[]

metadata Object:
ParameterTypeDescriptionSample Value
@injectedobjectInjected extensions dataSee below ↓

metadata.@injected Object:
ParameterTypeDescriptionSample Value
extensionsobjectExtensions dataSee below ↓

metadata.@injected.extensions Object:
ParameterTypeDescriptionSample Value
link-previewobjectLink preview extensionSee below ↓

metadata.@injected.extensions.link-preview Object:
ParameterTypeDescriptionSample Value
linksarrayExtracted links[]

Receiving Real-Time Messages

The procedure to receive real-time messages is exactly the same as mentioned in the Receive Messages section. This can be achieved using the MessageListener class provided by the SDK. To add a MessageListener, you can use the addMessageListener() method of the SDK. The only thing that needs to be checked is if the received message belongs to the active thread. This can be done using the parentMessageId field of the message object.
var listenerID = "UNIQUE_LISTENER_ID";
var activeThreadId = 100;

CometChat.addMessageListener(
listenerID,
new CometChat.MessageListener({
  onTextMessageReceived: textMessage => {
      if(textMessage.getParentMessageId() == activeThreadId) {
          console.log("Text message received for active thread.", textMessage);
      }
  },
  onMediaMessageReceived: mediaMessage => {
      if(mediaMessage.getParentMessageId() == activeThreadId) {
          console.log("Media message received for active thread.", textMessage);
      }
  },
  onCustomMessageReceived: customMessage => {
      if(customMessage.getParentMessageId() == activeThreadId) {
          console.log("Custom message received for active thread.", textMessage);
      }
  }
})
);
Remember to remove your listener on unmount. Always call CometChat.removeMessageListener("UNIQUE_LISTENER_ID") when the component unmounts (e.g., in a useEffect cleanup or componentWillUnmount) to avoid memory leaks and duplicate event handling.

Fetch All Messages for a Thread

You can fetch all the messages belonging to a particular thread by using the MessagesRequest class. To get an object of the MessagesRequest class, use the MessagesRequestBuilder class and call the setParentMessageId() method to inform the SDK that you only need the messages belonging to the thread with the specified parentMessageId. Once you have the object of the MessagesRequest class, call the fetchPrevious() method to get the latest messages in the thread. In one call, a maximum of 100 messages can be fetched. To fetch the next set of messages, call the fetchPrevious() method again on the same object.
let limit = 30;
let parentMessageId = 1; // Replace with actual parent message ID
let messagesRequest = new CometChat.MessagesRequestBuilder()
                      .setLimit(limit)
                      .setParentMessageId(parentMessageId)
                      .build();
     
messagesRequest.fetchPrevious().then(
  messages => {
      console.log("Messages for thread fetched successfully", messages);
  }, error => {
      console.log("Message fetching failed with error:", error);
  }
);
On SuccessfetchPrevious() returns an array of messages belonging to the thread:Message Object (per item in array):
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25293"
conversationIdstringConversation identifier"cometchat-uid-6_user_cometchat-uid-7"
receiverIdstringReceiver’s UID"cometchat-uid-7"
receiverTypestringType of receiver"user"
typestringMessage type"text"
categorystringMessage category"message"
textstringMessage text content"Hello thread!"
sentAtnumberUnix timestamp when sent1771839799
updatedAtnumberUnix timestamp when updated1771839799
parentMessageIdstringID of the parent message this reply belongs to"25291"
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataSee below ↓
metadataobjectMessage metadataSee below ↓
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether current user is mentionedfalse

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-6"
namestringUser’s display name"Ronald Jerry"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771839550
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-7"
namestringUser’s display name"Henry Marino"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-7.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771839549
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

data Object:
ParameterTypeDescriptionSample Value
textstringMessage text"Hello thread!"
resourcestringSDK resource identifier"REACT_NATIVE-4_0_14-..."
entitiesobjectSender and receiver entitiesSee below ↓
metadataobjectInjected metadataSee below ↓
moderationobjectModeration status{"status": "approved"}

data.entities Object:
ParameterTypeDescriptionSample Value
senderobjectSender entity wrapperSee below ↓
receiverobjectReceiver entity wrapperSee below ↓

data.entities.sender Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.sender.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-6"
namestringUser’s display name"Ronald Jerry"
avatarstringUser’s avatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp"
rolestringUser’s role"default"
statusstringUser’s online status"online"
lastActiveAtnumberLast active timestamp1771839550
tagsarrayUser tags[]

data.entities.receiver Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.receiver.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-7"
namestringUser’s display name"Henry Marino"
avatarstringUser’s avatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-7.webp"
rolestringUser’s role"default"
statusstringUser’s online status"online"
lastActiveAtnumberLast active timestamp1771839549
conversationIdstringConversation identifier"cometchat-uid-6_user_cometchat-uid-7"
tagsarrayUser tags[]

data.metadata Object:
ParameterTypeDescriptionSample Value
@injectedobjectInjected extensions dataSee below ↓

data.metadata.@injected Object:
ParameterTypeDescriptionSample Value
extensionsobjectExtensions dataSee below ↓

data.metadata.@injected.extensions Object:
ParameterTypeDescriptionSample Value
link-previewobjectLink preview extensionSee below ↓

data.metadata.@injected.extensions.link-preview Object:
ParameterTypeDescriptionSample Value
linksarrayExtracted links[]

metadata Object:
ParameterTypeDescriptionSample Value
@injectedobjectInjected extensions dataSee below ↓

metadata.@injected Object:
ParameterTypeDescriptionSample Value
extensionsobjectExtensions dataSee below ↓

metadata.@injected.extensions Object:
ParameterTypeDescriptionSample Value
link-previewobjectLink preview extensionSee below ↓

metadata.@injected.extensions.link-preview Object:
ParameterTypeDescriptionSample Value
linksarrayExtracted links[]

Avoid Threaded Messages in User/Group Conversations

While fetching messages for normal user/group conversations using the MessagesRequest, threaded messages will be included in the list by default. To exclude threaded messages from the list of user/group messages, use the hideReplies() method of the MessagesRequestBuilder class. This method takes a boolean argument which, when set to true, excludes messages belonging to threads from the list of messages.
Without hideReplies(true)fetchPrevious() returns all messages including thread replies (note the second message has parentMessageId):Message Object (per item in array):
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25291"
conversationIdstringConversation identifier"cometchat-uid-6_user_cometchat-uid-7"
receiverIdstringReceiver’s UID"cometchat-uid-6"
receiverTypestringType of receiver"user"
typestringMessage type"text"
categorystringMessage category"message"
textstringMessage text content"Hello"
sentAtnumberUnix timestamp when sent1771831336
deliveredAtnumberUnix timestamp when delivered1771832977
readAtnumberUnix timestamp when read1771832977
updatedAtnumberUnix timestamp when updated1771832977
replyCountnumberNumber of replies to this message1
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataSee below ↓
metadataobjectMessage metadataSee below ↓
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether current user is mentionedfalse
Thread replies in the same response will have a parentMessageId field linking them to their parent message.
sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-7"
namestringUser’s display name"Henry Marino"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-7.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771829868
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-6"
namestringUser’s display name"Ronald Jerry"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771829859
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

data Object:
ParameterTypeDescriptionSample Value
textstringMessage text"Hello"
resourcestringSDK resource identifier"REACT_NATIVE-4_0_14-..."
entitiesobjectSender and receiver entitiesSee below ↓
metadataobjectInjected metadataSee below ↓

data.entities Object:
ParameterTypeDescriptionSample Value
senderobjectSender entity wrapperSee below ↓
receiverobjectReceiver entity wrapperSee below ↓

data.entities.sender Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.sender.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-7"
namestringUser’s display name"Henry Marino"
avatarstringUser’s avatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-7.webp"
rolestringUser’s role"default"
statusstringUser’s online status"online"
lastActiveAtnumberLast active timestamp1771829868
tagsarrayUser tags[]

data.entities.receiver Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.receiver.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-6"
namestringUser’s display name"Ronald Jerry"
avatarstringUser’s avatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp"
rolestringUser’s role"default"
statusstringUser’s online status"online"
lastActiveAtnumberLast active timestamp1771829859
conversationIdstringConversation identifier"cometchat-uid-6_user_cometchat-uid-7"
tagsarrayUser tags[]

data.metadata Object:
ParameterTypeDescriptionSample Value
@injectedobjectInjected extensions dataSee below ↓

data.metadata.@injected Object:
ParameterTypeDescriptionSample Value
extensionsobjectExtensions dataSee below ↓

data.metadata.@injected.extensions Object:
ParameterTypeDescriptionSample Value
link-previewobjectLink preview extensionSee below ↓

data.metadata.@injected.extensions.link-preview Object:
ParameterTypeDescriptionSample Value
linksarrayExtracted links[]

metadata Object:
ParameterTypeDescriptionSample Value
@injectedobjectInjected extensions dataSee below ↓

metadata.@injected Object:
ParameterTypeDescriptionSample Value
extensionsobjectExtensions dataSee below ↓

metadata.@injected.extensions Object:
ParameterTypeDescriptionSample Value
link-previewobjectLink preview extensionSee below ↓

metadata.@injected.extensions.link-preview Object:
ParameterTypeDescriptionSample Value
linksarrayExtracted links[]
let UID = "UID";
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
                      .setUID(UID)
                      .setLimit(limit)
                      .hideReplies(true)
                      .build();
     
messagesRequest.fetchPrevious().then(
  messages => {
      console.log("Messages for thread fetched successfully", messages);
  }, error => {
      console.log("Message fetching failed with error:", error);
  }
);
On SuccessfetchPrevious() returns messages excluding thread replies (note: parent messages with replyCount are included, but their replies are not):Message Object (per item in array):
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25291"
conversationIdstringConversation identifier"cometchat-uid-6_user_cometchat-uid-7"
receiverIdstringReceiver’s UID"cometchat-uid-6"
receiverTypestringType of receiver"user"
typestringMessage type"text"
categorystringMessage category"message"
textstringMessage text content"Hello"
sentAtnumberUnix timestamp when sent1771831336
deliveredAtnumberUnix timestamp when delivered1771832977
readAtnumberUnix timestamp when read1771832977
updatedAtnumberUnix timestamp when updated1771832977
replyCountnumberNumber of replies to this message1
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataSee below ↓
metadataobjectMessage metadataSee below ↓
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether current user is mentionedfalse

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-7"
namestringUser’s display name"Henry Marino"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-7.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771829868
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-6"
namestringUser’s display name"Ronald Jerry"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1771829859
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

data Object:
ParameterTypeDescriptionSample Value
textstringMessage text"Hello"
resourcestringSDK resource identifier"REACT_NATIVE-4_0_14-..."
entitiesobjectSender and receiver entitiesSee below ↓
metadataobjectInjected metadataSee below ↓

data.entities Object:
ParameterTypeDescriptionSample Value
senderobjectSender entity wrapperSee below ↓
receiverobjectReceiver entity wrapperSee below ↓

data.entities.sender Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.sender.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-7"
namestringUser’s display name"Henry Marino"
avatarstringUser’s avatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-7.webp"
rolestringUser’s role"default"
statusstringUser’s online status"online"
lastActiveAtnumberLast active timestamp1771829868
tagsarrayUser tags[]

data.entities.receiver Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.receiver.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-6"
namestringUser’s display name"Ronald Jerry"
avatarstringUser’s avatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp"
rolestringUser’s role"default"
statusstringUser’s online status"online"
lastActiveAtnumberLast active timestamp1771829859
conversationIdstringConversation identifier"cometchat-uid-6_user_cometchat-uid-7"
tagsarrayUser tags[]

data.metadata Object:
ParameterTypeDescriptionSample Value
@injectedobjectInjected extensions dataSee below ↓

data.metadata.@injected Object:
ParameterTypeDescriptionSample Value
extensionsobjectExtensions dataSee below ↓

data.metadata.@injected.extensions Object:
ParameterTypeDescriptionSample Value
link-previewobjectLink preview extensionSee below ↓

data.metadata.@injected.extensions.link-preview Object:
ParameterTypeDescriptionSample Value
linksarrayExtracted links[]

metadata Object:
ParameterTypeDescriptionSample Value
@injectedobjectInjected extensions dataSee below ↓

metadata.@injected Object:
ParameterTypeDescriptionSample Value
extensionsobjectExtensions dataSee below ↓

metadata.@injected.extensions Object:
ParameterTypeDescriptionSample Value
link-previewobjectLink preview extensionSee below ↓

metadata.@injected.extensions.link-preview Object:
ParameterTypeDescriptionSample Value
linksarrayExtracted links[]
The above snippet will return messages between the logged-in user and cometchat-uid-1 excluding all the threaded messages belonging to the same conversation.

Best Practices and Troubleshooting

Every message object has a parentMessageId field. If this field is set (non-zero), the message is part of a thread. Use message.getParentMessageId() to retrieve the parent message ID and match it against the active thread.
By default, MessagesRequest includes threaded messages. Use the hideReplies(true) method on MessagesRequestBuilder when fetching messages for the main conversation to exclude thread replies.
You can fetch a maximum of 100 messages per fetchPrevious() call. Use the setLimit() method on MessagesRequestBuilder to control the number of messages returned. To load more messages, call fetchPrevious() again on the same MessagesRequest object.
Yes. The setParentMessageId() method is available on TextMessage, MediaMessage, and CustomMessage objects. Set the parent message ID before calling CometChat.sendMessage() to send any message type within a thread.

Next Steps