> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-v6-beta2-flutter-uikit.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Threaded Messages

> Send, receive, and fetch threaded messages (replies) in user and group conversations using the CometChat React Native SDK.

<Info>
  **Quick Reference** - Send a threaded message and fetch thread replies:

  ```javascript theme={null}
  // 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)
  );
  ```
</Info>

<Note>
  **Available via:** [SDK](/sdk/react-native/threaded-messages) | [REST API](/rest-api/messages/list-threaded-messages) | [UI Kits](/ui-kit/react-native/core-features#threaded-conversations)
</Note>

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](/sdk/react-native/send-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.

<Note>
  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.
</Note>

**Example to send a text message in a thread in a user conversation:**

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    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);
      }
    )
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let receiverId = "UID",
      receiverType: string = CometChat.RECEIVER_TYPE.USER,
      textMessage: CometChat.TextMessage = new CometChat.TextMessage(receiverId, "Hello", receiverType),
      messageId: number = 100; // Replace with actual parent message ID

    textMessage.setParentMessageId(messageId);

    CometChat.sendMessage(textMessage).then(
      (message: CometChat.TextMessage) => {
          console.log('Message sent successfully', message);
      }, (error: CometChat.CometChatException) => {
          console.log('Message sending failed', error);
      }
    );
    ```
  </Tab>
</Tabs>

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.

<Accordion title="Response">
  **On Success** — `sendMessage()` returns the sent threaded message with `parentMessageId`:

  <span id="send-thread-message-object" style={{scrollMarginTop: '100px'}} />

  **Message Object:**

  | Parameter         | Type    | Description                                    | Sample Value                                |
  | ----------------- | ------- | ---------------------------------------------- | ------------------------------------------- |
  | `id`              | string  | Unique message identifier                      | `"25293"`                                   |
  | `conversationId`  | string  | Conversation identifier                        | `"cometchat-uid-6_user_cometchat-uid-7"`    |
  | `receiverId`      | string  | Receiver's UID                                 | `"cometchat-uid-7"`                         |
  | `receiverType`    | string  | Type of receiver                               | `"user"`                                    |
  | `type`            | string  | Message type                                   | `"text"`                                    |
  | `category`        | string  | Message category                               | `"message"`                                 |
  | `text`            | string  | Message text content                           | `"Hello thread!"`                           |
  | `sentAt`          | number  | Unix timestamp when sent                       | `1771839799`                                |
  | `updatedAt`       | number  | Unix timestamp when updated                    | `1771839799`                                |
  | `parentMessageId` | string  | ID of the parent message this reply belongs to | `"25291"`                                   |
  | `sender`          | object  | Sender user details                            | [See below ↓](#send-thread-sender-object)   |
  | `receiver`        | object  | Receiver user details                          | [See below ↓](#send-thread-receiver-object) |
  | `data`            | object  | Additional message data                        | [See below ↓](#send-thread-data-object)     |
  | `metadata`        | object  | Message metadata                               | [See below ↓](#send-thread-metadata-object) |
  | `reactions`       | array   | Message reactions                              | `[]`                                        |
  | `mentionedUsers`  | array   | Users mentioned in message                     | `[]`                                        |
  | `mentionedMe`     | boolean | Whether current user is mentioned              | `false`                                     |

  ***

  <span id="send-thread-sender-object" style={{scrollMarginTop: '100px'}} />

  **`sender` Object:**

  | Parameter       | Type    | Description                            | Sample Value                                                            |
  | --------------- | ------- | -------------------------------------- | ----------------------------------------------------------------------- |
  | `uid`           | string  | User's unique identifier               | `"cometchat-uid-6"`                                                     |
  | `name`          | string  | User's display name                    | `"Ronald Jerry"`                                                        |
  | `avatar`        | string  | URL to user's avatar                   | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp"` |
  | `status`        | string  | User's online status                   | `"online"`                                                              |
  | `role`          | string  | User's role                            | `"default"`                                                             |
  | `lastActiveAt`  | number  | Last active timestamp                  | `1771839550`                                                            |
  | `hasBlockedMe`  | boolean | Whether user has blocked current user  | `false`                                                                 |
  | `blockedByMe`   | boolean | Whether current user blocked this user | `false`                                                                 |
  | `deactivatedAt` | number  | Deactivation timestamp (0 if active)   | `0`                                                                     |
  | `tags`          | array   | User tags                              | `[]`                                                                    |

  ***

  <span id="send-thread-receiver-object" style={{scrollMarginTop: '100px'}} />

  **`receiver` Object:**

  | Parameter       | Type    | Description                            | Sample Value                                                            |
  | --------------- | ------- | -------------------------------------- | ----------------------------------------------------------------------- |
  | `uid`           | string  | User's unique identifier               | `"cometchat-uid-7"`                                                     |
  | `name`          | string  | User's display name                    | `"Henry Marino"`                                                        |
  | `avatar`        | string  | URL to user's avatar                   | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-7.webp"` |
  | `status`        | string  | User's online status                   | `"online"`                                                              |
  | `role`          | string  | User's role                            | `"default"`                                                             |
  | `lastActiveAt`  | number  | Last active timestamp                  | `1771839549`                                                            |
  | `hasBlockedMe`  | boolean | Whether user has blocked current user  | `false`                                                                 |
  | `blockedByMe`   | boolean | Whether current user blocked this user | `false`                                                                 |
  | `deactivatedAt` | number  | Deactivation timestamp (0 if active)   | `0`                                                                     |
  | `tags`          | array   | User tags                              | `[]`                                                                    |

  ***

  <span id="send-thread-data-object" style={{scrollMarginTop: '100px'}} />

  **`data` Object:**

  | Parameter    | Type   | Description                  | Sample Value                                     |
  | ------------ | ------ | ---------------------------- | ------------------------------------------------ |
  | `text`       | string | Message text                 | `"Hello thread!"`                                |
  | `resource`   | string | SDK resource identifier      | `"REACT_NATIVE-4_0_14-..."`                      |
  | `entities`   | object | Sender and receiver entities | [See below ↓](#send-thread-data-entities-object) |
  | `metadata`   | object | Injected metadata            | [See below ↓](#send-thread-data-metadata-object) |
  | `moderation` | object | Moderation status            | `{"status": "pending"}`                          |

  ***

  <span id="send-thread-data-entities-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities` Object:**

  | Parameter  | Type   | Description             | Sample Value                                              |
  | ---------- | ------ | ----------------------- | --------------------------------------------------------- |
  | `sender`   | object | Sender entity wrapper   | [See below ↓](#send-thread-data-entities-sender-object)   |
  | `receiver` | object | Receiver entity wrapper | [See below ↓](#send-thread-data-entities-receiver-object) |

  ***

  <span id="send-thread-data-entities-sender-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.sender` Object:**

  | Parameter    | Type   | Description         | Sample Value                                                   |
  | ------------ | ------ | ------------------- | -------------------------------------------------------------- |
  | `entityType` | string | Type of entity      | `"user"`                                                       |
  | `entity`     | object | User entity details | [See below ↓](#send-thread-data-entities-sender-entity-object) |

  ***

  <span id="send-thread-data-entities-sender-entity-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.sender.entity` Object:**

  | Parameter      | Type   | Description              | Sample Value                                                            |
  | -------------- | ------ | ------------------------ | ----------------------------------------------------------------------- |
  | `uid`          | string | User's unique identifier | `"cometchat-uid-6"`                                                     |
  | `name`         | string | User's display name      | `"Ronald Jerry"`                                                        |
  | `avatar`       | string | User's avatar URL        | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp"` |
  | `role`         | string | User's role              | `"default"`                                                             |
  | `status`       | string | User's online status     | `"online"`                                                              |
  | `lastActiveAt` | number | Last active timestamp    | `1771839550`                                                            |
  | `tags`         | array  | User tags                | `[]`                                                                    |

  ***

  <span id="send-thread-data-entities-receiver-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.receiver` Object:**

  | Parameter    | Type   | Description         | Sample Value                                                     |
  | ------------ | ------ | ------------------- | ---------------------------------------------------------------- |
  | `entityType` | string | Type of entity      | `"user"`                                                         |
  | `entity`     | object | User entity details | [See below ↓](#send-thread-data-entities-receiver-entity-object) |

  ***

  <span id="send-thread-data-entities-receiver-entity-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.receiver.entity` Object:**

  | Parameter        | Type   | Description              | Sample Value                                                            |
  | ---------------- | ------ | ------------------------ | ----------------------------------------------------------------------- |
  | `uid`            | string | User's unique identifier | `"cometchat-uid-7"`                                                     |
  | `name`           | string | User's display name      | `"Henry Marino"`                                                        |
  | `avatar`         | string | User's avatar URL        | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-7.webp"` |
  | `role`           | string | User's role              | `"default"`                                                             |
  | `status`         | string | User's online status     | `"online"`                                                              |
  | `lastActiveAt`   | number | Last active timestamp    | `1771839549`                                                            |
  | `conversationId` | string | Conversation identifier  | `"cometchat-uid-6_user_cometchat-uid-7"`                                |
  | `tags`           | array  | User tags                | `[]`                                                                    |

  ***

  <span id="send-thread-data-metadata-object" style={{scrollMarginTop: '100px'}} />

  **`data.metadata` Object:**

  | Parameter   | Type   | Description              | Sample Value                                              |
  | ----------- | ------ | ------------------------ | --------------------------------------------------------- |
  | `@injected` | object | Injected extensions data | [See below ↓](#send-thread-data-metadata-injected-object) |

  ***

  <span id="send-thread-data-metadata-injected-object" style={{scrollMarginTop: '100px'}} />

  **`data.metadata.@injected` Object:**

  | Parameter    | Type   | Description     | Sample Value                                                |
  | ------------ | ------ | --------------- | ----------------------------------------------------------- |
  | `extensions` | object | Extensions data | [See below ↓](#send-thread-data-metadata-extensions-object) |

  ***

  <span id="send-thread-data-metadata-extensions-object" style={{scrollMarginTop: '100px'}} />

  **`data.metadata.@injected.extensions` Object:**

  | Parameter      | Type   | Description            | Sample Value                                                 |
  | -------------- | ------ | ---------------------- | ------------------------------------------------------------ |
  | `link-preview` | object | Link preview extension | [See below ↓](#send-thread-data-metadata-linkpreview-object) |

  ***

  <span id="send-thread-data-metadata-linkpreview-object" style={{scrollMarginTop: '100px'}} />

  **`data.metadata.@injected.extensions.link-preview` Object:**

  | Parameter | Type  | Description     | Sample Value |
  | --------- | ----- | --------------- | ------------ |
  | `links`   | array | Extracted links | `[]`         |

  ***

  <span id="send-thread-metadata-object" style={{scrollMarginTop: '100px'}} />

  **`metadata` Object:**

  | Parameter   | Type   | Description              | Sample Value                                         |
  | ----------- | ------ | ------------------------ | ---------------------------------------------------- |
  | `@injected` | object | Injected extensions data | [See below ↓](#send-thread-metadata-injected-object) |

  ***

  <span id="send-thread-metadata-injected-object" style={{scrollMarginTop: '100px'}} />

  **`metadata.@injected` Object:**

  | Parameter    | Type   | Description     | Sample Value                                           |
  | ------------ | ------ | --------------- | ------------------------------------------------------ |
  | `extensions` | object | Extensions data | [See below ↓](#send-thread-metadata-extensions-object) |

  ***

  <span id="send-thread-metadata-extensions-object" style={{scrollMarginTop: '100px'}} />

  **`metadata.@injected.extensions` Object:**

  | Parameter      | Type   | Description            | Sample Value                                            |
  | -------------- | ------ | ---------------------- | ------------------------------------------------------- |
  | `link-preview` | object | Link preview extension | [See below ↓](#send-thread-metadata-linkpreview-object) |

  ***

  <span id="send-thread-metadata-linkpreview-object" style={{scrollMarginTop: '100px'}} />

  **`metadata.@injected.extensions.link-preview` Object:**

  | Parameter | Type  | Description     | Sample Value |
  | --------- | ----- | --------------- | ------------ |
  | `links`   | array | Extracted links | `[]`         |
</Accordion>

### Receiving Real-Time Messages

The procedure to receive real-time messages is exactly the same as mentioned in the [Receive Messages](/sdk/react-native/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.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    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);
          }
      }
    })
    );
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    var listenerID: string = "UNIQUE_LISTENER_ID",
      activeThreadId: number = 100;

    CometChat.addMessageListener(
      listenerID,
      new CometChat.MessageListener({
          onTextMessageReceived: (textMessage: CometChat.TextMessage) => {
              if (textMessage.getParentMessageId() == activeThreadId) {
                  console.log("Text message received for active thread.", textMessage);
              }
          },
          onMediaMessageReceived: (mediaMessage: CometChat.MediaMessage) => {
              if (mediaMessage.getParentMessageId() == activeThreadId) {
                  console.log("Media message received for active thread.", mediaMessage);
              }
          },
          onCustomMessageReceived: (customMessage: CometChat.CustomMessage) => {
              if (customMessage.getParentMessageId() == activeThreadId) {
                  console.log("Custom message received for active thread.", customMessage);
              }
          }
      })
    ); 
    ```
  </Tab>
</Tabs>

<Warning>
  **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.
</Warning>

### 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.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    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);
      }
    );
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let limit: number = 30,
      parentMessageId: number = 1, // Replace with actual parent message ID
      messagesRequest: CometChat.MessagesRequest = new CometChat.MessagesRequestBuilder()
          .setLimit(limit)
          .setParentMessageId(parentMessageId)
          .build();

    messagesRequest.fetchPrevious().then(
      (messages: CometChat.BaseMessage[]) => {
          console.log("Messages for thread fetched successfully", messages);
      }, (error: CometChat.CometChatException) => {
          console.log("Message fetching failed with error:", error);
      }
    );
    ```
  </Tab>
</Tabs>

<Accordion title="Response">
  **On Success** — `fetchPrevious()` returns an array of messages belonging to the thread:

  <span id="fetch-thread-message-object" style={{scrollMarginTop: '100px'}} />

  **Message Object (per item in array):**

  | Parameter         | Type    | Description                                    | Sample Value                                 |
  | ----------------- | ------- | ---------------------------------------------- | -------------------------------------------- |
  | `id`              | string  | Unique message identifier                      | `"25293"`                                    |
  | `conversationId`  | string  | Conversation identifier                        | `"cometchat-uid-6_user_cometchat-uid-7"`     |
  | `receiverId`      | string  | Receiver's UID                                 | `"cometchat-uid-7"`                          |
  | `receiverType`    | string  | Type of receiver                               | `"user"`                                     |
  | `type`            | string  | Message type                                   | `"text"`                                     |
  | `category`        | string  | Message category                               | `"message"`                                  |
  | `text`            | string  | Message text content                           | `"Hello thread!"`                            |
  | `sentAt`          | number  | Unix timestamp when sent                       | `1771839799`                                 |
  | `updatedAt`       | number  | Unix timestamp when updated                    | `1771839799`                                 |
  | `parentMessageId` | string  | ID of the parent message this reply belongs to | `"25291"`                                    |
  | `sender`          | object  | Sender user details                            | [See below ↓](#fetch-thread-sender-object)   |
  | `receiver`        | object  | Receiver user details                          | [See below ↓](#fetch-thread-receiver-object) |
  | `data`            | object  | Additional message data                        | [See below ↓](#fetch-thread-data-object)     |
  | `metadata`        | object  | Message metadata                               | [See below ↓](#fetch-thread-metadata-object) |
  | `reactions`       | array   | Message reactions                              | `[]`                                         |
  | `mentionedUsers`  | array   | Users mentioned in message                     | `[]`                                         |
  | `mentionedMe`     | boolean | Whether current user is mentioned              | `false`                                      |

  ***

  <span id="fetch-thread-sender-object" style={{scrollMarginTop: '100px'}} />

  **`sender` Object:**

  | Parameter       | Type    | Description                            | Sample Value                                                            |
  | --------------- | ------- | -------------------------------------- | ----------------------------------------------------------------------- |
  | `uid`           | string  | User's unique identifier               | `"cometchat-uid-6"`                                                     |
  | `name`          | string  | User's display name                    | `"Ronald Jerry"`                                                        |
  | `avatar`        | string  | URL to user's avatar                   | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp"` |
  | `status`        | string  | User's online status                   | `"online"`                                                              |
  | `role`          | string  | User's role                            | `"default"`                                                             |
  | `lastActiveAt`  | number  | Last active timestamp                  | `1771839550`                                                            |
  | `hasBlockedMe`  | boolean | Whether user has blocked current user  | `false`                                                                 |
  | `blockedByMe`   | boolean | Whether current user blocked this user | `false`                                                                 |
  | `deactivatedAt` | number  | Deactivation timestamp (0 if active)   | `0`                                                                     |
  | `tags`          | array   | User tags                              | `[]`                                                                    |

  ***

  <span id="fetch-thread-receiver-object" style={{scrollMarginTop: '100px'}} />

  **`receiver` Object:**

  | Parameter       | Type    | Description                            | Sample Value                                                            |
  | --------------- | ------- | -------------------------------------- | ----------------------------------------------------------------------- |
  | `uid`           | string  | User's unique identifier               | `"cometchat-uid-7"`                                                     |
  | `name`          | string  | User's display name                    | `"Henry Marino"`                                                        |
  | `avatar`        | string  | URL to user's avatar                   | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-7.webp"` |
  | `status`        | string  | User's online status                   | `"online"`                                                              |
  | `role`          | string  | User's role                            | `"default"`                                                             |
  | `lastActiveAt`  | number  | Last active timestamp                  | `1771839549`                                                            |
  | `hasBlockedMe`  | boolean | Whether user has blocked current user  | `false`                                                                 |
  | `blockedByMe`   | boolean | Whether current user blocked this user | `false`                                                                 |
  | `deactivatedAt` | number  | Deactivation timestamp (0 if active)   | `0`                                                                     |
  | `tags`          | array   | User tags                              | `[]`                                                                    |

  ***

  <span id="fetch-thread-data-object" style={{scrollMarginTop: '100px'}} />

  **`data` Object:**

  | Parameter    | Type   | Description                  | Sample Value                                      |
  | ------------ | ------ | ---------------------------- | ------------------------------------------------- |
  | `text`       | string | Message text                 | `"Hello thread!"`                                 |
  | `resource`   | string | SDK resource identifier      | `"REACT_NATIVE-4_0_14-..."`                       |
  | `entities`   | object | Sender and receiver entities | [See below ↓](#fetch-thread-data-entities-object) |
  | `metadata`   | object | Injected metadata            | [See below ↓](#fetch-thread-data-metadata-object) |
  | `moderation` | object | Moderation status            | `{"status": "approved"}`                          |

  ***

  <span id="fetch-thread-data-entities-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities` Object:**

  | Parameter  | Type   | Description             | Sample Value                                               |
  | ---------- | ------ | ----------------------- | ---------------------------------------------------------- |
  | `sender`   | object | Sender entity wrapper   | [See below ↓](#fetch-thread-data-entities-sender-object)   |
  | `receiver` | object | Receiver entity wrapper | [See below ↓](#fetch-thread-data-entities-receiver-object) |

  ***

  <span id="fetch-thread-data-entities-sender-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.sender` Object:**

  | Parameter    | Type   | Description         | Sample Value                                                    |
  | ------------ | ------ | ------------------- | --------------------------------------------------------------- |
  | `entityType` | string | Type of entity      | `"user"`                                                        |
  | `entity`     | object | User entity details | [See below ↓](#fetch-thread-data-entities-sender-entity-object) |

  ***

  <span id="fetch-thread-data-entities-sender-entity-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.sender.entity` Object:**

  | Parameter      | Type   | Description              | Sample Value                                                            |
  | -------------- | ------ | ------------------------ | ----------------------------------------------------------------------- |
  | `uid`          | string | User's unique identifier | `"cometchat-uid-6"`                                                     |
  | `name`         | string | User's display name      | `"Ronald Jerry"`                                                        |
  | `avatar`       | string | User's avatar URL        | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp"` |
  | `role`         | string | User's role              | `"default"`                                                             |
  | `status`       | string | User's online status     | `"online"`                                                              |
  | `lastActiveAt` | number | Last active timestamp    | `1771839550`                                                            |
  | `tags`         | array  | User tags                | `[]`                                                                    |

  ***

  <span id="fetch-thread-data-entities-receiver-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.receiver` Object:**

  | Parameter    | Type   | Description         | Sample Value                                                      |
  | ------------ | ------ | ------------------- | ----------------------------------------------------------------- |
  | `entityType` | string | Type of entity      | `"user"`                                                          |
  | `entity`     | object | User entity details | [See below ↓](#fetch-thread-data-entities-receiver-entity-object) |

  ***

  <span id="fetch-thread-data-entities-receiver-entity-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.receiver.entity` Object:**

  | Parameter        | Type   | Description              | Sample Value                                                            |
  | ---------------- | ------ | ------------------------ | ----------------------------------------------------------------------- |
  | `uid`            | string | User's unique identifier | `"cometchat-uid-7"`                                                     |
  | `name`           | string | User's display name      | `"Henry Marino"`                                                        |
  | `avatar`         | string | User's avatar URL        | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-7.webp"` |
  | `role`           | string | User's role              | `"default"`                                                             |
  | `status`         | string | User's online status     | `"online"`                                                              |
  | `lastActiveAt`   | number | Last active timestamp    | `1771839549`                                                            |
  | `conversationId` | string | Conversation identifier  | `"cometchat-uid-6_user_cometchat-uid-7"`                                |
  | `tags`           | array  | User tags                | `[]`                                                                    |

  ***

  <span id="fetch-thread-data-metadata-object" style={{scrollMarginTop: '100px'}} />

  **`data.metadata` Object:**

  | Parameter   | Type   | Description              | Sample Value                                               |
  | ----------- | ------ | ------------------------ | ---------------------------------------------------------- |
  | `@injected` | object | Injected extensions data | [See below ↓](#fetch-thread-data-metadata-injected-object) |

  ***

  <span id="fetch-thread-data-metadata-injected-object" style={{scrollMarginTop: '100px'}} />

  **`data.metadata.@injected` Object:**

  | Parameter    | Type   | Description     | Sample Value                                                 |
  | ------------ | ------ | --------------- | ------------------------------------------------------------ |
  | `extensions` | object | Extensions data | [See below ↓](#fetch-thread-data-metadata-extensions-object) |

  ***

  <span id="fetch-thread-data-metadata-extensions-object" style={{scrollMarginTop: '100px'}} />

  **`data.metadata.@injected.extensions` Object:**

  | Parameter      | Type   | Description            | Sample Value                                                  |
  | -------------- | ------ | ---------------------- | ------------------------------------------------------------- |
  | `link-preview` | object | Link preview extension | [See below ↓](#fetch-thread-data-metadata-linkpreview-object) |

  ***

  <span id="fetch-thread-data-metadata-linkpreview-object" style={{scrollMarginTop: '100px'}} />

  **`data.metadata.@injected.extensions.link-preview` Object:**

  | Parameter | Type  | Description     | Sample Value |
  | --------- | ----- | --------------- | ------------ |
  | `links`   | array | Extracted links | `[]`         |

  ***

  <span id="fetch-thread-metadata-object" style={{scrollMarginTop: '100px'}} />

  **`metadata` Object:**

  | Parameter   | Type   | Description              | Sample Value                                          |
  | ----------- | ------ | ------------------------ | ----------------------------------------------------- |
  | `@injected` | object | Injected extensions data | [See below ↓](#fetch-thread-metadata-injected-object) |

  ***

  <span id="fetch-thread-metadata-injected-object" style={{scrollMarginTop: '100px'}} />

  **`metadata.@injected` Object:**

  | Parameter    | Type   | Description     | Sample Value                                            |
  | ------------ | ------ | --------------- | ------------------------------------------------------- |
  | `extensions` | object | Extensions data | [See below ↓](#fetch-thread-metadata-extensions-object) |

  ***

  <span id="fetch-thread-metadata-extensions-object" style={{scrollMarginTop: '100px'}} />

  **`metadata.@injected.extensions` Object:**

  | Parameter      | Type   | Description            | Sample Value                                             |
  | -------------- | ------ | ---------------------- | -------------------------------------------------------- |
  | `link-preview` | object | Link preview extension | [See below ↓](#fetch-thread-metadata-linkpreview-object) |

  ***

  <span id="fetch-thread-metadata-linkpreview-object" style={{scrollMarginTop: '100px'}} />

  **`metadata.@injected.extensions.link-preview` Object:**

  | Parameter | Type  | Description     | Sample Value |
  | --------- | ----- | --------------- | ------------ |
  | `links`   | array | Extracted links | `[]`         |
</Accordion>

## 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.

<Accordion title="Default Behavior (without hideReplies) - Thread replies included">
  **Without `hideReplies(true)`** — `fetchPrevious()` returns all messages including thread replies (note the second message has `parentMessageId`):

  <span id="default-behavior-message-object" style={{scrollMarginTop: '100px'}} />

  **Message Object (per item in array):**

  | Parameter        | Type    | Description                       | Sample Value                                     |
  | ---------------- | ------- | --------------------------------- | ------------------------------------------------ |
  | `id`             | string  | Unique message identifier         | `"25291"`                                        |
  | `conversationId` | string  | Conversation identifier           | `"cometchat-uid-6_user_cometchat-uid-7"`         |
  | `receiverId`     | string  | Receiver's UID                    | `"cometchat-uid-6"`                              |
  | `receiverType`   | string  | Type of receiver                  | `"user"`                                         |
  | `type`           | string  | Message type                      | `"text"`                                         |
  | `category`       | string  | Message category                  | `"message"`                                      |
  | `text`           | string  | Message text content              | `"Hello"`                                        |
  | `sentAt`         | number  | Unix timestamp when sent          | `1771831336`                                     |
  | `deliveredAt`    | number  | Unix timestamp when delivered     | `1771832977`                                     |
  | `readAt`         | number  | Unix timestamp when read          | `1771832977`                                     |
  | `updatedAt`      | number  | Unix timestamp when updated       | `1771832977`                                     |
  | `replyCount`     | number  | Number of replies to this message | `1`                                              |
  | `sender`         | object  | Sender user details               | [See below ↓](#default-behavior-sender-object)   |
  | `receiver`       | object  | Receiver user details             | [See below ↓](#default-behavior-receiver-object) |
  | `data`           | object  | Additional message data           | [See below ↓](#default-behavior-data-object)     |
  | `metadata`       | object  | Message metadata                  | [See below ↓](#default-behavior-metadata-object) |
  | `reactions`      | array   | Message reactions                 | `[]`                                             |
  | `mentionedUsers` | array   | Users mentioned in message        | `[]`                                             |
  | `mentionedMe`    | boolean | Whether current user is mentioned | `false`                                          |

  Thread replies in the same response will have a `parentMessageId` field linking them to their parent message.

  ***

  <span id="default-behavior-sender-object" style={{scrollMarginTop: '100px'}} />

  **`sender` Object:**

  | Parameter       | Type    | Description                            | Sample Value                                                            |
  | --------------- | ------- | -------------------------------------- | ----------------------------------------------------------------------- |
  | `uid`           | string  | User's unique identifier               | `"cometchat-uid-7"`                                                     |
  | `name`          | string  | User's display name                    | `"Henry Marino"`                                                        |
  | `avatar`        | string  | URL to user's avatar                   | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-7.webp"` |
  | `status`        | string  | User's online status                   | `"online"`                                                              |
  | `role`          | string  | User's role                            | `"default"`                                                             |
  | `lastActiveAt`  | number  | Last active timestamp                  | `1771829868`                                                            |
  | `hasBlockedMe`  | boolean | Whether user has blocked current user  | `false`                                                                 |
  | `blockedByMe`   | boolean | Whether current user blocked this user | `false`                                                                 |
  | `deactivatedAt` | number  | Deactivation timestamp (0 if active)   | `0`                                                                     |
  | `tags`          | array   | User tags                              | `[]`                                                                    |

  ***

  <span id="default-behavior-receiver-object" style={{scrollMarginTop: '100px'}} />

  **`receiver` Object:**

  | Parameter       | Type    | Description                            | Sample Value                                                            |
  | --------------- | ------- | -------------------------------------- | ----------------------------------------------------------------------- |
  | `uid`           | string  | User's unique identifier               | `"cometchat-uid-6"`                                                     |
  | `name`          | string  | User's display name                    | `"Ronald Jerry"`                                                        |
  | `avatar`        | string  | URL to user's avatar                   | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp"` |
  | `status`        | string  | User's online status                   | `"online"`                                                              |
  | `role`          | string  | User's role                            | `"default"`                                                             |
  | `lastActiveAt`  | number  | Last active timestamp                  | `1771829859`                                                            |
  | `hasBlockedMe`  | boolean | Whether user has blocked current user  | `false`                                                                 |
  | `blockedByMe`   | boolean | Whether current user blocked this user | `false`                                                                 |
  | `deactivatedAt` | number  | Deactivation timestamp (0 if active)   | `0`                                                                     |
  | `tags`          | array   | User tags                              | `[]`                                                                    |

  ***

  <span id="default-behavior-data-object" style={{scrollMarginTop: '100px'}} />

  **`data` Object:**

  | Parameter  | Type   | Description                  | Sample Value                                          |
  | ---------- | ------ | ---------------------------- | ----------------------------------------------------- |
  | `text`     | string | Message text                 | `"Hello"`                                             |
  | `resource` | string | SDK resource identifier      | `"REACT_NATIVE-4_0_14-..."`                           |
  | `entities` | object | Sender and receiver entities | [See below ↓](#default-behavior-data-entities-object) |
  | `metadata` | object | Injected metadata            | [See below ↓](#default-behavior-data-metadata-object) |

  ***

  <span id="default-behavior-data-entities-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities` Object:**

  | Parameter  | Type   | Description             | Sample Value                                                   |
  | ---------- | ------ | ----------------------- | -------------------------------------------------------------- |
  | `sender`   | object | Sender entity wrapper   | [See below ↓](#default-behavior-data-entities-sender-object)   |
  | `receiver` | object | Receiver entity wrapper | [See below ↓](#default-behavior-data-entities-receiver-object) |

  ***

  <span id="default-behavior-data-entities-sender-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.sender` Object:**

  | Parameter    | Type   | Description         | Sample Value                                                        |
  | ------------ | ------ | ------------------- | ------------------------------------------------------------------- |
  | `entityType` | string | Type of entity      | `"user"`                                                            |
  | `entity`     | object | User entity details | [See below ↓](#default-behavior-data-entities-sender-entity-object) |

  ***

  <span id="default-behavior-data-entities-sender-entity-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.sender.entity` Object:**

  | Parameter      | Type   | Description              | Sample Value                                                            |
  | -------------- | ------ | ------------------------ | ----------------------------------------------------------------------- |
  | `uid`          | string | User's unique identifier | `"cometchat-uid-7"`                                                     |
  | `name`         | string | User's display name      | `"Henry Marino"`                                                        |
  | `avatar`       | string | User's avatar URL        | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-7.webp"` |
  | `role`         | string | User's role              | `"default"`                                                             |
  | `status`       | string | User's online status     | `"online"`                                                              |
  | `lastActiveAt` | number | Last active timestamp    | `1771829868`                                                            |
  | `tags`         | array  | User tags                | `[]`                                                                    |

  ***

  <span id="default-behavior-data-entities-receiver-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.receiver` Object:**

  | Parameter    | Type   | Description         | Sample Value                                                          |
  | ------------ | ------ | ------------------- | --------------------------------------------------------------------- |
  | `entityType` | string | Type of entity      | `"user"`                                                              |
  | `entity`     | object | User entity details | [See below ↓](#default-behavior-data-entities-receiver-entity-object) |

  ***

  <span id="default-behavior-data-entities-receiver-entity-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.receiver.entity` Object:**

  | Parameter        | Type   | Description              | Sample Value                                                            |
  | ---------------- | ------ | ------------------------ | ----------------------------------------------------------------------- |
  | `uid`            | string | User's unique identifier | `"cometchat-uid-6"`                                                     |
  | `name`           | string | User's display name      | `"Ronald Jerry"`                                                        |
  | `avatar`         | string | User's avatar URL        | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp"` |
  | `role`           | string | User's role              | `"default"`                                                             |
  | `status`         | string | User's online status     | `"online"`                                                              |
  | `lastActiveAt`   | number | Last active timestamp    | `1771829859`                                                            |
  | `conversationId` | string | Conversation identifier  | `"cometchat-uid-6_user_cometchat-uid-7"`                                |
  | `tags`           | array  | User tags                | `[]`                                                                    |

  ***

  <span id="default-behavior-data-metadata-object" style={{scrollMarginTop: '100px'}} />

  **`data.metadata` Object:**

  | Parameter   | Type   | Description              | Sample Value                                                   |
  | ----------- | ------ | ------------------------ | -------------------------------------------------------------- |
  | `@injected` | object | Injected extensions data | [See below ↓](#default-behavior-data-metadata-injected-object) |

  ***

  <span id="default-behavior-data-metadata-injected-object" style={{scrollMarginTop: '100px'}} />

  **`data.metadata.@injected` Object:**

  | Parameter    | Type   | Description     | Sample Value                                                     |
  | ------------ | ------ | --------------- | ---------------------------------------------------------------- |
  | `extensions` | object | Extensions data | [See below ↓](#default-behavior-data-metadata-extensions-object) |

  ***

  <span id="default-behavior-data-metadata-extensions-object" style={{scrollMarginTop: '100px'}} />

  **`data.metadata.@injected.extensions` Object:**

  | Parameter      | Type   | Description            | Sample Value                                                      |
  | -------------- | ------ | ---------------------- | ----------------------------------------------------------------- |
  | `link-preview` | object | Link preview extension | [See below ↓](#default-behavior-data-metadata-linkpreview-object) |

  ***

  <span id="default-behavior-data-metadata-linkpreview-object" style={{scrollMarginTop: '100px'}} />

  **`data.metadata.@injected.extensions.link-preview` Object:**

  | Parameter | Type  | Description     | Sample Value |
  | --------- | ----- | --------------- | ------------ |
  | `links`   | array | Extracted links | `[]`         |

  ***

  <span id="default-behavior-metadata-object" style={{scrollMarginTop: '100px'}} />

  **`metadata` Object:**

  | Parameter   | Type   | Description              | Sample Value                                              |
  | ----------- | ------ | ------------------------ | --------------------------------------------------------- |
  | `@injected` | object | Injected extensions data | [See below ↓](#default-behavior-metadata-injected-object) |

  ***

  <span id="default-behavior-metadata-injected-object" style={{scrollMarginTop: '100px'}} />

  **`metadata.@injected` Object:**

  | Parameter    | Type   | Description     | Sample Value                                                |
  | ------------ | ------ | --------------- | ----------------------------------------------------------- |
  | `extensions` | object | Extensions data | [See below ↓](#default-behavior-metadata-extensions-object) |

  ***

  <span id="default-behavior-metadata-extensions-object" style={{scrollMarginTop: '100px'}} />

  **`metadata.@injected.extensions` Object:**

  | Parameter      | Type   | Description            | Sample Value                                                 |
  | -------------- | ------ | ---------------------- | ------------------------------------------------------------ |
  | `link-preview` | object | Link preview extension | [See below ↓](#default-behavior-metadata-linkpreview-object) |

  ***

  <span id="default-behavior-metadata-linkpreview-object" style={{scrollMarginTop: '100px'}} />

  **`metadata.@injected.extensions.link-preview` Object:**

  | Parameter | Type  | Description     | Sample Value |
  | --------- | ----- | --------------- | ------------ |
  | `links`   | array | Extracted links | `[]`         |
</Accordion>

<Tabs>
  <Tab title="To User">
    ```javascript theme={null}
    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);
      }
    );
    ```
  </Tab>

  <Tab title="To Group">
    ```javascript theme={null}
    let GUID = "GUID";
    let limit = 30;
    let messagesRequest = new CometChat.MessagesRequestBuilder()
                          .setGUID(GUID)
                          .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);
      }
    );
    ```
  </Tab>

  <Tab title="TypeScript (User)">
    ```typescript theme={null}
    let UID: string = "UID",
      limit: number = 30,
      messagesRequest: CometChat.MessagesRequest = new CometChat.MessagesRequestBuilder()
          .setUID(UID)
          .setLimit(limit)
          .hideReplies(true)
          .build();

    messagesRequest.fetchPrevious().then(
      (messages: CometChat.BaseMessage[]) => {
          console.log("Messages fetched successfully", messages);
      }, (error: CometChat.CometChatException) => {
          console.log("Message fetching failed with error:", error);
      }
    );
    ```
  </Tab>

  <Tab title="TypeScript (Group)">
    ```typescript theme={null}
    let GUID: string = "GUID",
      limit: number = 30,
      messagesRequest: CometChat.MessagesRequest = new CometChat.MessagesRequestBuilder()
          .setGUID(GUID)
          .setLimit(limit)
          .hideReplies(true)
          .build();

    messagesRequest.fetchPrevious().then(
      (messages: CometChat.BaseMessage[]) => {
          console.log("Messages fetched successfully", messages);
      }, (error: CometChat.CometChatException) => {
          console.log("Message fetching failed with error:", error);
      }
    );
    ```
  </Tab>
</Tabs>

<Accordion title="Response">
  **On Success** — `fetchPrevious()` returns messages excluding thread replies (note: parent messages with `replyCount` are included, but their replies are not):

  <span id="hide-replies-message-object" style={{scrollMarginTop: '100px'}} />

  **Message Object (per item in array):**

  | Parameter        | Type    | Description                       | Sample Value                                 |
  | ---------------- | ------- | --------------------------------- | -------------------------------------------- |
  | `id`             | string  | Unique message identifier         | `"25291"`                                    |
  | `conversationId` | string  | Conversation identifier           | `"cometchat-uid-6_user_cometchat-uid-7"`     |
  | `receiverId`     | string  | Receiver's UID                    | `"cometchat-uid-6"`                          |
  | `receiverType`   | string  | Type of receiver                  | `"user"`                                     |
  | `type`           | string  | Message type                      | `"text"`                                     |
  | `category`       | string  | Message category                  | `"message"`                                  |
  | `text`           | string  | Message text content              | `"Hello"`                                    |
  | `sentAt`         | number  | Unix timestamp when sent          | `1771831336`                                 |
  | `deliveredAt`    | number  | Unix timestamp when delivered     | `1771832977`                                 |
  | `readAt`         | number  | Unix timestamp when read          | `1771832977`                                 |
  | `updatedAt`      | number  | Unix timestamp when updated       | `1771832977`                                 |
  | `replyCount`     | number  | Number of replies to this message | `1`                                          |
  | `sender`         | object  | Sender user details               | [See below ↓](#hide-replies-sender-object)   |
  | `receiver`       | object  | Receiver user details             | [See below ↓](#hide-replies-receiver-object) |
  | `data`           | object  | Additional message data           | [See below ↓](#hide-replies-data-object)     |
  | `metadata`       | object  | Message metadata                  | [See below ↓](#hide-replies-metadata-object) |
  | `reactions`      | array   | Message reactions                 | `[]`                                         |
  | `mentionedUsers` | array   | Users mentioned in message        | `[]`                                         |
  | `mentionedMe`    | boolean | Whether current user is mentioned | `false`                                      |

  ***

  <span id="hide-replies-sender-object" style={{scrollMarginTop: '100px'}} />

  **`sender` Object:**

  | Parameter       | Type    | Description                            | Sample Value                                                            |
  | --------------- | ------- | -------------------------------------- | ----------------------------------------------------------------------- |
  | `uid`           | string  | User's unique identifier               | `"cometchat-uid-7"`                                                     |
  | `name`          | string  | User's display name                    | `"Henry Marino"`                                                        |
  | `avatar`        | string  | URL to user's avatar                   | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-7.webp"` |
  | `status`        | string  | User's online status                   | `"online"`                                                              |
  | `role`          | string  | User's role                            | `"default"`                                                             |
  | `lastActiveAt`  | number  | Last active timestamp                  | `1771829868`                                                            |
  | `hasBlockedMe`  | boolean | Whether user has blocked current user  | `false`                                                                 |
  | `blockedByMe`   | boolean | Whether current user blocked this user | `false`                                                                 |
  | `deactivatedAt` | number  | Deactivation timestamp (0 if active)   | `0`                                                                     |
  | `tags`          | array   | User tags                              | `[]`                                                                    |

  ***

  <span id="hide-replies-receiver-object" style={{scrollMarginTop: '100px'}} />

  **`receiver` Object:**

  | Parameter       | Type    | Description                            | Sample Value                                                            |
  | --------------- | ------- | -------------------------------------- | ----------------------------------------------------------------------- |
  | `uid`           | string  | User's unique identifier               | `"cometchat-uid-6"`                                                     |
  | `name`          | string  | User's display name                    | `"Ronald Jerry"`                                                        |
  | `avatar`        | string  | URL to user's avatar                   | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp"` |
  | `status`        | string  | User's online status                   | `"online"`                                                              |
  | `role`          | string  | User's role                            | `"default"`                                                             |
  | `lastActiveAt`  | number  | Last active timestamp                  | `1771829859`                                                            |
  | `hasBlockedMe`  | boolean | Whether user has blocked current user  | `false`                                                                 |
  | `blockedByMe`   | boolean | Whether current user blocked this user | `false`                                                                 |
  | `deactivatedAt` | number  | Deactivation timestamp (0 if active)   | `0`                                                                     |
  | `tags`          | array   | User tags                              | `[]`                                                                    |

  ***

  <span id="hide-replies-data-object" style={{scrollMarginTop: '100px'}} />

  **`data` Object:**

  | Parameter  | Type   | Description                  | Sample Value                                      |
  | ---------- | ------ | ---------------------------- | ------------------------------------------------- |
  | `text`     | string | Message text                 | `"Hello"`                                         |
  | `resource` | string | SDK resource identifier      | `"REACT_NATIVE-4_0_14-..."`                       |
  | `entities` | object | Sender and receiver entities | [See below ↓](#hide-replies-data-entities-object) |
  | `metadata` | object | Injected metadata            | [See below ↓](#hide-replies-data-metadata-object) |

  ***

  <span id="hide-replies-data-entities-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities` Object:**

  | Parameter  | Type   | Description             | Sample Value                                               |
  | ---------- | ------ | ----------------------- | ---------------------------------------------------------- |
  | `sender`   | object | Sender entity wrapper   | [See below ↓](#hide-replies-data-entities-sender-object)   |
  | `receiver` | object | Receiver entity wrapper | [See below ↓](#hide-replies-data-entities-receiver-object) |

  ***

  <span id="hide-replies-data-entities-sender-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.sender` Object:**

  | Parameter    | Type   | Description         | Sample Value                                                    |
  | ------------ | ------ | ------------------- | --------------------------------------------------------------- |
  | `entityType` | string | Type of entity      | `"user"`                                                        |
  | `entity`     | object | User entity details | [See below ↓](#hide-replies-data-entities-sender-entity-object) |

  ***

  <span id="hide-replies-data-entities-sender-entity-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.sender.entity` Object:**

  | Parameter      | Type   | Description              | Sample Value                                                            |
  | -------------- | ------ | ------------------------ | ----------------------------------------------------------------------- |
  | `uid`          | string | User's unique identifier | `"cometchat-uid-7"`                                                     |
  | `name`         | string | User's display name      | `"Henry Marino"`                                                        |
  | `avatar`       | string | User's avatar URL        | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-7.webp"` |
  | `role`         | string | User's role              | `"default"`                                                             |
  | `status`       | string | User's online status     | `"online"`                                                              |
  | `lastActiveAt` | number | Last active timestamp    | `1771829868`                                                            |
  | `tags`         | array  | User tags                | `[]`                                                                    |

  ***

  <span id="hide-replies-data-entities-receiver-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.receiver` Object:**

  | Parameter    | Type   | Description         | Sample Value                                                      |
  | ------------ | ------ | ------------------- | ----------------------------------------------------------------- |
  | `entityType` | string | Type of entity      | `"user"`                                                          |
  | `entity`     | object | User entity details | [See below ↓](#hide-replies-data-entities-receiver-entity-object) |

  ***

  <span id="hide-replies-data-entities-receiver-entity-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities.receiver.entity` Object:**

  | Parameter        | Type   | Description              | Sample Value                                                            |
  | ---------------- | ------ | ------------------------ | ----------------------------------------------------------------------- |
  | `uid`            | string | User's unique identifier | `"cometchat-uid-6"`                                                     |
  | `name`           | string | User's display name      | `"Ronald Jerry"`                                                        |
  | `avatar`         | string | User's avatar URL        | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp"` |
  | `role`           | string | User's role              | `"default"`                                                             |
  | `status`         | string | User's online status     | `"online"`                                                              |
  | `lastActiveAt`   | number | Last active timestamp    | `1771829859`                                                            |
  | `conversationId` | string | Conversation identifier  | `"cometchat-uid-6_user_cometchat-uid-7"`                                |
  | `tags`           | array  | User tags                | `[]`                                                                    |

  ***

  <span id="hide-replies-data-metadata-object" style={{scrollMarginTop: '100px'}} />

  **`data.metadata` Object:**

  | Parameter   | Type   | Description              | Sample Value                                               |
  | ----------- | ------ | ------------------------ | ---------------------------------------------------------- |
  | `@injected` | object | Injected extensions data | [See below ↓](#hide-replies-data-metadata-injected-object) |

  ***

  <span id="hide-replies-data-metadata-injected-object" style={{scrollMarginTop: '100px'}} />

  **`data.metadata.@injected` Object:**

  | Parameter    | Type   | Description     | Sample Value                                                 |
  | ------------ | ------ | --------------- | ------------------------------------------------------------ |
  | `extensions` | object | Extensions data | [See below ↓](#hide-replies-data-metadata-extensions-object) |

  ***

  <span id="hide-replies-data-metadata-extensions-object" style={{scrollMarginTop: '100px'}} />

  **`data.metadata.@injected.extensions` Object:**

  | Parameter      | Type   | Description            | Sample Value                                                  |
  | -------------- | ------ | ---------------------- | ------------------------------------------------------------- |
  | `link-preview` | object | Link preview extension | [See below ↓](#hide-replies-data-metadata-linkpreview-object) |

  ***

  <span id="hide-replies-data-metadata-linkpreview-object" style={{scrollMarginTop: '100px'}} />

  **`data.metadata.@injected.extensions.link-preview` Object:**

  | Parameter | Type  | Description     | Sample Value |
  | --------- | ----- | --------------- | ------------ |
  | `links`   | array | Extracted links | `[]`         |

  ***

  <span id="hide-replies-metadata-object" style={{scrollMarginTop: '100px'}} />

  **`metadata` Object:**

  | Parameter   | Type   | Description              | Sample Value                                          |
  | ----------- | ------ | ------------------------ | ----------------------------------------------------- |
  | `@injected` | object | Injected extensions data | [See below ↓](#hide-replies-metadata-injected-object) |

  ***

  <span id="hide-replies-metadata-injected-object" style={{scrollMarginTop: '100px'}} />

  **`metadata.@injected` Object:**

  | Parameter    | Type   | Description     | Sample Value                                            |
  | ------------ | ------ | --------------- | ------------------------------------------------------- |
  | `extensions` | object | Extensions data | [See below ↓](#hide-replies-metadata-extensions-object) |

  ***

  <span id="hide-replies-metadata-extensions-object" style={{scrollMarginTop: '100px'}} />

  **`metadata.@injected.extensions` Object:**

  | Parameter      | Type   | Description            | Sample Value                                             |
  | -------------- | ------ | ---------------------- | -------------------------------------------------------- |
  | `link-preview` | object | Link preview extension | [See below ↓](#hide-replies-metadata-linkpreview-object) |

  ***

  <span id="hide-replies-metadata-linkpreview-object" style={{scrollMarginTop: '100px'}} />

  **`metadata.@injected.extensions.link-preview` Object:**

  | Parameter | Type  | Description     | Sample Value |
  | --------- | ----- | --------------- | ------------ |
  | `links`   | array | Extracted links | `[]`         |
</Accordion>

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

<AccordionGroup>
  <Accordion title="How do I identify which thread a message belongs to?">
    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.
  </Accordion>

  <Accordion title="Why am I receiving thread messages in my main conversation list?">
    By default, `MessagesRequest` includes threaded messages. Use the `hideReplies(true)` method on `MessagesRequestBuilder` when fetching messages for the main conversation to exclude thread replies.
  </Accordion>

  <Accordion title="What is the maximum number of messages I can fetch per request?">
    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.
  </Accordion>

  <Accordion title="Can I send media or custom messages in a thread?">
    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.
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Send a Message" icon="paper-plane" href="/sdk/react-native/send-message">
    Learn how to send text, media, and custom messages to users and groups.
  </Card>

  <Card title="Receive Messages" icon="inbox" href="/sdk/react-native/receive-messages">
    Set up real-time message listeners and fetch message history.
  </Card>

  <Card title="Message Filtering" icon="filter" href="/sdk/react-native/additional-message-filtering">
    Filter messages by type, category, tags, timestamps, and more.
  </Card>

  <Card title="Message Structure" icon="sitemap" href="/sdk/react-native/message-structure-and-hierarchy">
    Understand message categories, types, and the message hierarchy.
  </Card>
</CardGroup>
