# Create Comment

social.plus SDK's comment creation is designed to handle comments efficiently and reliably across your application. Each comment is assigned a unique, immutable `commentId`, and the SDK includes an optimistic update feature to enhance user experience.

To work with comments, you'll need to use the `CommentRepository`.

With the SDK's optimistic creation feature, you don’t need to manually create a `commentId`. Instead, the SDK generates one automatically. However, you must provide the `referenceId` and `referenceType` parameters. This feature enables the app to display the comment immediately while assuming it will be successfully added, reducing perceived latency for users.

The `referenceType` parameter specifies the type of content the comment is associated with. Supported values are:

* `post`: Create a comment on a post.
* `story`: Create a comment on a story.
* `content`: Create a comment on other content types.

{% hint style="info" %}
A comment should not exceed 20,000 characters in length.
{% endhint %}

{% tabs %}
{% tab title="iOS" %}
{% embed url="<https://gist.github.com/amythee/e1c3ad53511f589105776e2b32265b40>" %}

The `AmityNotificationToken` returned by the `observeOnceWithBlock:` is saved in `self.token`, a strongly referenced property. This is needed to prevent the observed block from being released.

The `parentId` parameter in `createComment:` is optional.

The `referenceId` parameter in `createComment:` is mandatory and will only support `AmityPost` identifier.
{% endtab %}

{% tab title="Android" %}
{% embed url="<https://gist.github.com/amythee/8b3044e1449499522f3259828e7b22f2#file-amitycommentcreate-kt>" %}
{% endtab %}

{% tab title="JavaScript" %}
{% embed url="<https://gist.github.com/amythee/73a5a476abada38f33bf0ba6613b8a6c#file-createcomment-js>" %}
{% endtab %}

{% tab title="TypeScript" %}
{% embed url="<https://gist.github.com/2e38f085497fa8cec7177976edb8b549>" %}
{% endtab %}

{% tab title="Flutter" %}
{% embed url="<https://gist.github.com/amythee/99d02516b7f851d06100cfcfe9e3e177#file-amityposttextcreation-dart>" %}
{% endtab %}
{% endtabs %}

## Create a Comment with an Image

social.plus SDK also allows you to create comments with images. This feature works seamlessly with the SDK’s optimistic creation mechanism, ensuring the same fast and responsive user experience as with text comments.

The `referenceType` parameter determines the content type the image comment is associated with. Supported values are:

* `post`: Create a comment on a post.
* `story`: Create a comment on a story.
* `content`: Create a comment on other content types.

To create an image comment, you’ll need to:

1. Upload the image to obtain a `fileId`.
2. Provide the `fileId` in the `attachments` parameter along with the required `referenceId` and `referenceType`.

The SDK automatically generates a unique `commentId` for the image comment and handles the creation process optimistically.

{% tabs %}
{% tab title="iOS" %}
{% embed url="<https://gist.github.com/amythee/19486c590680aa6df4240b32af143248>" %}
{% endtab %}

{% tab title="Android" %}
{% embed url="<https://gist.github.com/amythee/b00f8ce59d581ac05a9b0ab17a1916e3>" %}
{% endtab %}

{% tab title="TypeScript" %}
{% embed url="<https://gist.github.com/fc5ad48dcad539ec59fe6d33223564bf>" %}
{% endtab %}

{% tab title="Flutter" %}
The functionality isn't currently supported by this SDK.
{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Limitations:**

1. Users can use a maximum of 10 images per comment.
2. The supported file types with the image moderation feature is enabled are jpg/jpeg + png.
3. The supported file types when the image moderation feature is not enabled are jpg/jpeg + webp
4. The maximum file size per image is 1 GB.
   {% endhint %}

## Reply to a Comment

In addition to creating top-level comments, social.plus SDK enables you to reply to existing comments in addition to creating top-level comments.

To reply to a comment, you must:

1. Specify the **parent comment's** `commentId` using the `parentId` parameter.
2. Provide the `referenceId`, `referenceType`, and the reply’s text content.

The `referenceType` parameter also supports replies to comments on stories. To reply to a story comment:

* Set `referenceType` to `.story`.
* Provide the corresponding `referenceId` for the story.

Similar to top-level comments, replies leverage the SDK's optimistic creation feature. You don’t need to provide a unique `commentId` for the reply, the SDK generates it automatically while associating it with the parent comment.

{% tabs %}
{% tab title="iOS" %}
{% embed url="<https://gist.github.com/amythee/72615abf8c6bc53d1f4fc307ea630f5c>" %}
{% endtab %}

{% tab title="Android" %}
{% embed url="<https://gist.github.com/amythee/106136159a8fb36a811782b22ddbc7cb>" %}
{% endtab %}

{% tab title="TypeScript" %}
{% embed url="<https://gist.github.com/48391c1ec8f9055a9da508c76476a111>" %}
{% endtab %}

{% tab title="Flutter" %}
{% embed url="<https://gist.github.com/amythee/99d02516b7f851d06100cfcfe9e3e177#file-amityposttextcreation-dart>" %}
{% endtab %}
{% endtabs %}

### Reply to Comments with an Image

{% tabs %}
{% tab title="iOS" %}
{% embed url="<https://gist.github.com/amythee/b6a4f1f190552246334f228cc856e339>" %}
{% endtab %}

{% tab title="Android" %}
{% embed url="<https://gist.github.com/amythee/1ad226283e7c5e1b4cf36e41b531a029>" %}
{% endtab %}

{% tab title="TypeScript" %}
{% embed url="<https://gist.github.com/93ae3275f1133d3580d00b9ae0110f3d>" %}
{% endtab %}

{% tab title="Flutter" %}
The functionality isn't currently supported by this SDK.
{% endtab %}
{% endtabs %}
