Create Comment
Here's an overview of how you can start integrating comments into your applications
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.
A comment should not exceed 20,000 characters in length.
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.
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:
Upload the image to obtain a
fileId
.Provide the
fileId
in theattachments
parameter along with the requiredreferenceId
andreferenceType
.
The SDK automatically generates a unique commentId
for the image comment and handles the creation process optimistically.
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:
Specify the parent comment's
commentId
using theparentId
parameter.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.
Reply to Comments with an Image
Last updated
Was this helpful?