> ## Documentation Index
> Fetch the complete documentation index at: https://learn.social.plus/llms.txt
> Use this file to discover all available pages before exploring further.

# Edit Comment

> Update comment text, metadata, mentions, links, and image attachments with the comment update APIs.

Use comment update APIs when a user edits a comment or replaces its image attachments. The SDK sends the update to the server; permission, ownership, and moderation rules are enforced by the backend and surfaced as SDK errors.

## Update Fields

| Field             | TypeScript            | iOS                                | Android              | Flutter                                  |
| ----------------- | --------------------- | ---------------------------------- | -------------------- | ---------------------------------------- |
| Text              | `data: { text }`      | `AmityCommentUpdateOptions(text:)` | `.text(...)`         | `.text(...)`                             |
| Metadata          | `metadata`            | `metadata`                         | `.metadata(...)`     | `.metadata(...)`                         |
| Mentions          | `mentionees`          | `mentioneesBuilder`                | `.mentionUsers(...)` | `.mentionUsers(...)`                     |
| Links             | `links`               | `links`                            | `.links(...)`        | Not exposed on the public update builder |
| Image attachments | `attachments` payload | `attachments`                      | `.attachments(...)`  | `.attachments(...)`                      |

<Info>
  Upload image files first, then pass the uploaded file IDs to the update API. Passing local file paths to comment update is not supported.
</Info>

## Parameters

| Operation                | Parameter                   | Required | Description                                                 |
| ------------------------ | --------------------------- | -------- | ----------------------------------------------------------- |
| Update text              | `commentId`                 | Yes      | Comment ID to update.                                       |
| Update text              | `text`                      | Yes      | Replacement text body for the comment.                      |
| Update image attachments | `commentId`                 | Yes      | Comment ID to update.                                       |
| Update image attachments | Uploaded image file ID      | Yes      | Uploaded image file ID to keep on the comment.              |
| Update optional fields   | `metadata`, mentions, links | No       | Optional editable fields where the target SDK exposes them. |

## Update Text

Update text and other editable fields by loading the comment ID and applying the platform-specific update call.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { CommentRepository } from "@amityco/ts-sdk";

  const { data: updatedComment } = await CommentRepository.updateComment(
    commentId,
    {
      data: {
        text: "Updated comment text",
      },
    },
  );

  renderResults(updatedComment);
  ```

  ```swift iOS theme={null}
  let options = AmityCommentUpdateOptions(
      text: "Updated comment text"
  )

  let updatedComment = try await commentRepository.editComment(
      withId: "comment-id",
      options: options
  )

  showSuccessMessage(updatedComment.commentId)
  ```

  ```kotlin Android theme={null}
  AmitySocialClient.newCommentRepository()
      .editComment(commentId = commentId)
      .text(text = "Updated comment text")
      .build()
      .apply()
      .subscribe(
          { updatedComment -> showSuccessMessage(updatedComment.getCommentId()) },
          { error -> handleGeneralError(error) }
      )
  ```

  ```dart Flutter theme={null}
  await AmitySocialClient.newCommentRepository()
      .updateComment(commentId: commentId)
      .text('Updated comment text')
      .build()
      .update();
  ```
</CodeGroup>

## Update Image Attachments

Set the attachment list to the full list you want the comment to keep. To preserve an existing image, include its uploaded file ID in the update payload.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { CommentRepository } from "@amityco/ts-sdk";

  const patch: Parameters<typeof CommentRepository.createComment>[0] = {
    referenceId: postId,
    referenceType: "post",
    data: {
      text: "Updated with an image",
    },
    attachments: [
      {
        type: "image",
        fileId: imageFileId,
      },
    ],
  };

  const { data: updatedComment } = await CommentRepository.updateComment(
    commentId,
    patch,
  );

  renderResults(updatedComment);
  ```

  ```swift iOS theme={null}
  let options = AmityCommentUpdateOptions(
      text: "Updated with an image",
      attachments: [
          .image(fileId: "uploaded-image-id")
      ]
  )

  let updatedComment = try await commentRepository.editComment(
      withId: "comment-id",
      options: options
  )

  showSuccessMessage(updatedComment.commentId)
  ```

  ```kotlin Android theme={null}
  val imageAttachment = AmityComment.Attachment.IMAGE(
      fileId = fileId,
      image = null
  )

  AmitySocialClient.newCommentRepository()
      .editComment(commentId = commentId)
      .text(text = "Updated with an image")
      .attachments(imageAttachment)
      .build()
      .apply()
      .subscribe(
          { updatedComment -> showSuccessMessage(updatedComment.getCommentId()) },
          { error -> handleGeneralError(error) }
      )
  ```

  ```dart Flutter theme={null}
  await AmitySocialClient.newCommentRepository()
      .updateComment(commentId: commentId)
      .text('Updated with an image')
      .attachments([
        CommentImageAttachment(fileId: fileId),
      ])
      .build()
      .update();
  ```
</CodeGroup>

## Clear Optional Fields

Different SDKs distinguish between "leave this field unchanged" and "replace this field with an empty value."

| Change                           | Pattern                                                                       |
| -------------------------------- | ----------------------------------------------------------------------------- |
| Leave text unchanged             | Do not set the text field in the update options                               |
| Remove text from a media comment | Set text to an empty string                                                   |
| Leave attachments unchanged      | Do not set the attachments field                                              |
| Remove all attachments           | Set attachments to an empty list where the platform exposes that update shape |
| Remove metadata                  | Set metadata to an empty object/dictionary                                    |
| Remove links                     | Set links to an empty list where the platform exposes link updates            |

## Notes

* For TypeScript image attachment updates, build the attachment payload using the same uploaded-file shape as comment creation.
* For iOS, Android, and Flutter, `nil` / unset attachment fields leave existing attachments unchanged; an explicit empty list removes attachments.
* Rebuild mention and link payloads from the edited text before updating a comment.
* Handle permission, not-found, and moderation errors from the SDK call rather than relying only on client-side checks.

## Related Topics

<CardGroup cols={2}>
  <Card title="Delete Comment" href="/social-plus-sdk/social/content-management/comments/actions/delete-comment" icon="trash">
    Soft delete or permanently delete comments where supported.
  </Card>

  <Card title="Query Comments" href="/social-plus-sdk/social/content-management/comments/retrieval/query-comments" icon="search">
    Query comments and include deleted comments when needed.
  </Card>

  <Card title="Image Comment" href="/social-plus-sdk/social/content-management/comments/creation/image-comment" icon="image">
    Upload images before attaching them to comments.
  </Card>

  <Card title="Text Comment" href="/social-plus-sdk/social/content-management/comments/creation/text-comment" icon="message-square">
    Create top-level comments and replies.
  </Card>
</CardGroup>
