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

# Edit A Message

> Edit text and custom messages, listen for real-time edit events, and retrieve missed edits using the CometChat React Native SDK.

<Info>
  **Quick Reference** - Edit a text message:

  ```javascript theme={null}
  let receiverID = "RECEIVER_UID";
  let messageText = "Updated message text";
  let receiverType = CometChat.RECEIVER_TYPE.USER;
  let textMessage = new CometChat.TextMessage(receiverID, messageText, receiverType);
  textMessage.setId(MESSAGE_ID);

  CometChat.editMessage(textMessage).then(
    message => console.log("Message Edited", message),
    error => console.log("Edit failed:", error)
  );
  ```
</Info>

<Note>
  **Available via:** [SDK](/sdk/react-native/edit-message) | [REST API](/rest-api/messages/update-message) | [UI Kits](/ui-kits/react-native/overview)
</Note>

While [editing a message](/sdk/react-native/edit-message#edit-a-message) is straightforward, receiving events for edited messages with CometChat has two parts:

1. Adding a listener to receive [real-time message edits](/sdk/react-native/edit-message#real-time-message-edit-events) when your app is running.
2. Calling a method to retrieve [missed message edits](/sdk/react-native/edit-message#missed-message-edit-events) when your app was not running.

## Edit a Message

*In other words, as a sender, how do I edit a message?*

To edit a message, you can use the `editMessage()` method. This method takes an object of the `BaseMessage` class. At the moment, you are only allowed to edit `TextMessage` and `CustomMessage`. Thus, the `BaseMessage` object must either be a Text or a Custom Message.

### Add/Update Tags

While editing a message, you can update the tags associated with the message. Use the `setTags()` method to do so. The tags added while editing a message will replace the tags set when the message was sent.

<Tabs>
  <Tab title="JavaScript (Text)">
    ```javascript theme={null}
    let tags = ["pinnedMessage"];

    textMessage.setTags(tags);
    ```
  </Tab>

  <Tab title="JavaScript (Custom)">
    ```javascript theme={null}
    let tags = ["pinnedMessage"];

    customMessage.setTags(tags);
    ```
  </Tab>

  <Tab title="TypeScript (Text)">
    ```typescript theme={null}
    let tags: Array<String> = ["pinnedMessage"];

    textMessage.setTags(tags);
    ```
  </Tab>

  <Tab title="TypeScript (Custom)">
    ```typescript theme={null}
    let tags: Array<String> = ["pinnedMessage"];

    customMessage.setTags(tags);
    ```
  </Tab>
</Tabs>

Once the message object is ready, you can use the `editMessage()` method and pass the message object to it.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    let receiverID = "RECEIVER_UID";
    let messageText = "Hello world!";
    let receiverType = CometChat.RECEIVER_TYPE.USER;
    let messageId = "MESSAGE_ID_OF_THE_MESSAGE_TO_BE_EDITED";
    let textMessage = new CometChat.TextMessage(receiverID, messageText, receiverType);

    textMessage.setId(messageId);

    CometChat.editMessage(textMessage).then(
    message => {
      console.log("Message Edited", message);
    }, error => {
      console.log("Message editing failed with error:", error);
    }
    );
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let receiverID: string = "RECEIVER_UID";
    let messageText: string = "Hello world!";
    let receiverType: string = CometChat.RECEIVER_TYPE.USER;
    let messageId: number = 1;
    let textMessage: CometChat.TextMessage = new CometChat.TextMessage(receiverID, messageText, receiverType);

    textMessage.setId(messageId);

    CometChat.editMessage(textMessage).then(
      (message: CometChat.TextMessage) => {
          console.log("Message Edited", message);
      }, (error: CometChat.CometChatException) => {
          console.log("Message editing failed with error:", error);
      }
    );
    ```
  </Tab>
</Tabs>

<Accordion title="Response">
  **On Success** — `editMessage()` returns the edited message object with `editedAt` and `editedBy` fields:

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

  **Message Object:**

  | Parameter        | Type    | Description                         | Sample Value                                 |
  | ---------------- | ------- | ----------------------------------- | -------------------------------------------- |
  | `id`             | string  | Unique message identifier           | `"25652"`                                    |
  | `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  | Edited message text content         | `"Nice, Any Update?"`                        |
  | `sentAt`         | number  | Unix timestamp when originally sent | `1772446840`                                 |
  | `editedAt`       | number  | Unix timestamp when edited          | `1772446861`                                 |
  | `editedBy`       | string  | UID of user who edited the message  | `"cometchat-uid-6"`                          |
  | `deliveredAt`    | number  | Unix timestamp when delivered       | `1772446841`                                 |
  | `readAt`         | number  | Unix timestamp when read            | `1772446841`                                 |
  | `updatedAt`      | number  | Unix timestamp when updated         | `1772446841`                                 |
  | `sender`         | object  | Sender user details                 | [See below ↓](#edit-message-sender-object)   |
  | `receiver`       | object  | Receiver user details               | [See below ↓](#edit-message-receiver-object) |
  | `data`           | object  | Additional message data             | [See below ↓](#edit-message-data-object)     |
  | `metadata`       | object  | Message metadata                    | [See below ↓](#edit-message-metadata-object) |
  | `reactions`      | array   | Message reactions                   | `[]`                                         |
  | `mentionedUsers` | array   | Users mentioned in message          | `[]`                                         |
  | `mentionedMe`    | boolean | Whether current user is mentioned   | `false`                                      |

  ***

  <span id="edit-message-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                  | `1772446655`                                                            |
  | `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="edit-message-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                  | `1772446782`                                                            |
  | `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="edit-message-data-object" style={{scrollMarginTop: '100px'}} />

  **`data` Object:**

  | Parameter    | Type   | Description                  | Sample Value                                      |
  | ------------ | ------ | ---------------------------- | ------------------------------------------------- |
  | `text`       | string | Message text                 | `"Nice, Any Update?"`                             |
  | `resource`   | string | SDK resource identifier      | `"REACT_NATIVE-4_0_14-..."`                       |
  | `entities`   | object | Sender and receiver entities | [See below ↓](#edit-message-data-entities-object) |
  | `metadata`   | object | Injected metadata            | [See below ↓](#edit-message-data-metadata-object) |
  | `moderation` | object | Moderation status            | `{"status": "approved"}`                          |

  ***

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

  **`data.entities` Object:**

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

  ***

  <span id="edit-message-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 ↓](#edit-message-data-entities-sender-entity-object) |

  ***

  <span id="edit-message-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    | `1772446655`                                                            |
  | `tags`         | array  | User tags                | `[]`                                                                    |

  ***

  <span id="edit-message-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 ↓](#edit-message-data-entities-receiver-entity-object) |

  ***

  <span id="edit-message-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    | `1772446782`                                                            |
  | `conversationId` | string | Conversation identifier  | `"cometchat-uid-6_user_cometchat-uid-7"`                                |
  | `tags`           | array  | User tags                | `[]`                                                                    |

  ***

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

  **`data.metadata` Object:**

  | Parameter | Type    | Description                  | Sample Value |
  | --------- | ------- | ---------------------------- | ------------ |
  | `edited`  | boolean | Indicates message was edited | `true`       |

  ***

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

  **`metadata` Object:**

  | Parameter | Type    | Description                  | Sample Value |
  | --------- | ------- | ---------------------------- | ------------ |
  | `edited`  | boolean | Indicates message was edited | `true`       |
</Accordion>

The object of the edited message will be returned in the `onSuccess()` callback method of the listener. The message object will contain the `editedAt` field set with the timestamp of the time the message was edited. This will help you identify if the message was edited while iterating through the list of messages. The `editedBy` field is also set to the UID of the user who edited the message.

By default, CometChat allows certain roles to edit a message.

| User Role       | Conversation Type       | Edit Capabilities          |
| --------------- | ----------------------- | -------------------------- |
| Message Sender  | One-on-One Conversation | Messages they have sent.   |
| Message Sender  | Group Conversation      | Messages they have sent.   |
| Group Owner     | Group Conversation      | All messages in the group. |
| Group Moderator | Group Conversation      | All messages in the group. |

## Real-time Message Edit Events

*In other words, as a recipient, how do I know when someone has edited their message when my app is running?*

To receive real-time events for a message being edited, you need to override the `onMessageEdited()` method of the `MessageListener` class.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    var listenerID = "UNIQUE_LISTENER_ID";

    CometChat.addMessageListener(
    listenerID,
    new CometChat.MessageListener({
      onMessageEdited: message => {
        console.log("Edited Message", message);
      }
    })
    );  
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let listenerID: string = "UNIQUE_LISTENER_ID";

    CometChat.addMessageListener(
    listenerID,
    new CometChat.MessageListener({
      onMessageEdited: (message: CometChat.BaseMessage) => {
        console.log("Edited Message", message);
      }
    })
    );
    ```
  </Tab>
</Tabs>

<Accordion title="Response">
  **On Event** — `onMessageEdited` callback receives the edited message object:

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

  **Message Object:**

  | Parameter        | Type    | Description                         | Sample Value                                      |
  | ---------------- | ------- | ----------------------------------- | ------------------------------------------------- |
  | `id`             | string  | Unique message identifier           | `"25652"`                                         |
  | `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  | Edited message text content         | `"Nice, Any Update?"`                             |
  | `sentAt`         | number  | Unix timestamp when originally sent | `1772446840`                                      |
  | `editedAt`       | number  | Unix timestamp when edited          | `1772446861`                                      |
  | `editedBy`       | string  | UID of user who edited the message  | `"cometchat-uid-6"`                               |
  | `deliveredAt`    | number  | Unix timestamp when delivered       | `1772446841`                                      |
  | `readAt`         | number  | Unix timestamp when read            | `1772446841`                                      |
  | `updatedAt`      | number  | Unix timestamp when updated         | `1772446841`                                      |
  | `sender`         | object  | Sender user details                 | [See below ↓](#on-message-edited-sender-object)   |
  | `receiver`       | object  | Receiver user details               | [See below ↓](#on-message-edited-receiver-object) |
  | `data`           | object  | Additional message data             | [See below ↓](#on-message-edited-data-object)     |
  | `metadata`       | object  | Message metadata                    | [See below ↓](#on-message-edited-metadata-object) |
  | `reactions`      | array   | Message reactions                   | `[]`                                              |
  | `mentionedUsers` | array   | Users mentioned in message          | `[]`                                              |
  | `mentionedMe`    | boolean | Whether current user is mentioned   | `false`                                           |

  ***

  <span id="on-message-edited-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                  | `1772446655`                                                            |
  | `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="on-message-edited-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                  | `1772446782`                                                            |
  | `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="on-message-edited-data-object" style={{scrollMarginTop: '100px'}} />

  **`data` Object:**

  | Parameter    | Type   | Description                  | Sample Value                                           |
  | ------------ | ------ | ---------------------------- | ------------------------------------------------------ |
  | `text`       | string | Message text                 | `"Nice, Any Update?"`                                  |
  | `resource`   | string | SDK resource identifier      | `"REACT_NATIVE-4_0_14-..."`                            |
  | `entities`   | object | Sender and receiver entities | [See below ↓](#on-message-edited-data-entities-object) |
  | `metadata`   | object | Injected metadata            | [See below ↓](#on-message-edited-data-metadata-object) |
  | `moderation` | object | Moderation status            | `{"status": "approved"}`                               |

  ***

  <span id="on-message-edited-data-entities-object" style={{scrollMarginTop: '100px'}} />

  **`data.entities` Object:**

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

  ***

  <span id="on-message-edited-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 ↓](#on-message-edited-data-entities-sender-entity-object) |

  ***

  <span id="on-message-edited-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    | `1772446655`                                                            |
  | `tags`         | array  | User tags                | `[]`                                                                    |

  ***

  <span id="on-message-edited-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 ↓](#on-message-edited-data-entities-receiver-entity-object) |

  ***

  <span id="on-message-edited-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    | `1772446782`                                                            |
  | `conversationId` | string | Conversation identifier  | `"cometchat-uid-6_user_cometchat-uid-7"`                                |
  | `tags`           | array  | User tags                | `[]`                                                                    |

  ***

  <span id="on-message-edited-data-metadata-object" style={{scrollMarginTop: '100px'}} />

  **`data.metadata` Object:**

  | Parameter | Type    | Description                  | Sample Value |
  | --------- | ------- | ---------------------------- | ------------ |
  | `edited`  | boolean | Indicates message was edited | `true`       |

  ***

  <span id="on-message-edited-metadata-object" style={{scrollMarginTop: '100px'}} />

  **`metadata` Object:**

  | Parameter | Type    | Description                  | Sample Value |
  | --------- | ------- | ---------------------------- | ------------ |
  | `edited`  | boolean | Indicates message was edited | `true`       |
</Accordion>

<Warning>
  Always remove your message listeners when the component unmounts to prevent memory leaks and unexpected behavior. Call `CometChat.removeMessageListener("UNIQUE_LISTENER_ID")` in your cleanup function (e.g., in a `useEffect` return or `componentWillUnmount`).
</Warning>

## Missed Message Edit Events

*In other words, as a recipient, how do I know when someone edited their message when my app was not running?*

When you retrieve the list of previous messages, for the message that was edited, the `editedAt` and the `editedBy` fields will be set. Also, for example, if the total number of messages for a conversation is 100, and the message with message ID 50 was edited, the message with ID 50 will have the `editedAt` and the `editedBy` fields set whenever it is pulled from the history. Additionally, the 101st message will be an \[Action] message informing you that the message with ID 50 has been edited.

<Accordion title="Response">
  **When fetching message history** — edited messages have `editedAt` and `editedBy` fields set:

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

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

  | Parameter        | Type    | Description                         | Sample Value                                |
  | ---------------- | ------- | ----------------------------------- | ------------------------------------------- |
  | `id`             | string  | Unique message identifier           | `"25652"`                                   |
  | `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  | Edited message text content         | `"Nice, Any Update?"`                       |
  | `sentAt`         | number  | Unix timestamp when originally sent | `1772446840`                                |
  | `editedAt`       | number  | Unix timestamp when edited          | `1772446861`                                |
  | `editedBy`       | string  | UID of user who edited the message  | `"cometchat-uid-6"`                         |
  | `deliveredAt`    | number  | Unix timestamp when delivered       | `1772446841`                                |
  | `readAt`         | number  | Unix timestamp when read            | `1772446841`                                |
  | `updatedAt`      | number  | Unix timestamp when updated         | `1772446841`                                |
  | `sender`         | object  | Sender user details                 | [See below ↓](#missed-edit-sender-object)   |
  | `receiver`       | object  | Receiver user details               | [See below ↓](#missed-edit-receiver-object) |
  | `data`           | object  | Additional message data             | [See below ↓](#missed-edit-data-object)     |
  | `metadata`       | object  | Message metadata                    | [See below ↓](#missed-edit-metadata-object) |
  | `reactions`      | array   | Message reactions                   | `[]`                                        |
  | `mentionedUsers` | array   | Users mentioned in message          | `[]`                                        |
  | `mentionedMe`    | boolean | Whether current user is mentioned   | `false`                                     |

  ***

  <span id="missed-edit-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                  | `1772446655`                                                            |
  | `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="missed-edit-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                  | `1772446782`                                                            |
  | `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="missed-edit-data-object" style={{scrollMarginTop: '100px'}} />

  **`data` Object:**

  | Parameter    | Type   | Description                  | Sample Value                                     |
  | ------------ | ------ | ---------------------------- | ------------------------------------------------ |
  | `text`       | string | Message text                 | `"Nice, Any Update?"`                            |
  | `resource`   | string | SDK resource identifier      | `"REACT_NATIVE-4_0_14-..."`                      |
  | `entities`   | object | Sender and receiver entities | [See below ↓](#missed-edit-data-entities-object) |
  | `metadata`   | object | Injected metadata            | [See below ↓](#missed-edit-data-metadata-object) |
  | `moderation` | object | Moderation status            | `{"status": "approved"}`                         |

  ***

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

  **`data.entities` Object:**

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

  ***

  <span id="missed-edit-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 ↓](#missed-edit-data-entities-sender-entity-object) |

  ***

  <span id="missed-edit-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    | `1772446655`                                                            |
  | `tags`         | array  | User tags                | `[]`                                                                    |

  ***

  <span id="missed-edit-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 ↓](#missed-edit-data-entities-receiver-entity-object) |

  ***

  <span id="missed-edit-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    | `1772446782`                                                            |
  | `conversationId` | string | Conversation identifier  | `"cometchat-uid-6_user_cometchat-uid-7"`                                |
  | `tags`           | array  | User tags                | `[]`                                                                    |

  ***

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

  **`data.metadata` Object:**

  | Parameter | Type    | Description                  | Sample Value |
  | --------- | ------- | ---------------------------- | ------------ |
  | `edited`  | boolean | Indicates message was edited | `true`       |

  ***

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

  **`metadata` Object:**

  | Parameter | Type    | Description                  | Sample Value |
  | --------- | ------- | ---------------------------- | ------------ |
  | `edited`  | boolean | Indicates message was edited | `true`       |
</Accordion>

For the message edited event, in the `Action` object received, the following fields can help you get the relevant information:

1. `action` - `edited`
2. `actionOn` - Updated message object with the edited details.
3. `actionBy` - User object containing the details of the user who has edited the message.
4. `actionFor` - User/group object having the details of the receiver to which the message was sent.

<Note>
  To edit a message, you need to be either the sender of the message or the admin/moderator of the group in which the message was sent.
</Note>

<AccordionGroup>
  <Accordion title="Best Practices">
    * Always verify the message type (`TextMessage` or `CustomMessage`) before attempting an edit, as other message types are not supported.
    * Use the `editedAt` and `editedBy` fields to display edit indicators in your UI so users know a message has been modified.
    * Register your message edit listener early in the component lifecycle to avoid missing real-time edit events.
    * When updating tags via `setTags()`, remember that the new tags fully replace any previously set tags — merge existing tags manually if you need to preserve them.
  </Accordion>

  <Accordion title="Troubleshooting">
    * **Edit fails with permission error**: Ensure the current user is the message sender, or a group owner/moderator for group messages.
    * **`onMessageEdited` not firing**: Confirm that `CometChat.addMessageListener()` has been called with a unique listener ID and that the listener has not been removed prematurely.
    * **Edited message not reflected in history**: After editing, re-fetch or update the local message list. The `editedAt` field on the message object confirms the edit was applied.
    * **Tags not updating**: Make sure you call `setTags()` on the message object before passing it to `editMessage()`. Tags set during editing replace all previous tags.
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Delete a Message" icon="trash" href="/sdk/react-native/delete-message">
    Remove messages from conversations for users or groups.
  </Card>

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

  <Card title="Receive Messages" icon="inbox" href="/sdk/react-native/receive-messages">
    Listen for incoming messages in real time and fetch missed messages.
  </Card>

  <Card title="Threaded Messages" icon="comments" href="/sdk/react-native/threaded-messages">
    Send and receive replies within message threads.
  </Card>
</CardGroup>
