Comments
Here's an overview of how you can start integrating comments into your applications.
Each comment is identified by a unique commentId, which is an immutable string. When creating a new comment, you do not need to specify your own commentId. You can leave it to SDK to generate. We also provide optimistic update on each comment. You will need to send a referenceId which is a contentId for current supported version. You need to use AmityCommentRepository before starting any activity with comments, such as editing an operation and/or flagging a comment.
In the future, we may support another referenceType and will be available in creation method.
There are 2 main methods in AmityCommentRepository which are creating a comment as well as getting a collection of comments. They all return a LiveCollection with the comment model.
Comment management methods are contained in AmityCommentRepository class. Before being able to call any comment method, you must initialize a repository instance using the AmitySocialClient instance, which you created on setup:

Comment Description

Name
Data Type
Description
Attributes
commentId
String
ID of the comment
userId
String
ID of the user who posted the comment
parentID
String
ID of a parent comment
rootId
String
ID of a root comment
refrenceId
String
ID of a reference
referenceType
String
Type of a reference
Enum: [post, content]
dataType
String
Type of the comment
Example: text
data
Object
Body of the comment
metadata
Object
Additional properties to support custom fields
childrenNumber
Number
Number of children comments
flagCount
Integer
Number of users who has read the comment
hashFlag
Object
Flag for checking internally if this comment is reported or not
reactions
Object
Mapping of reaction with reactionCounter
Example: OrderedMap { "like": 1 }
reactionsCount
Integer
Number of all reactions for the comment
myReactions
Array.<String>
List of my reactions to the comment
Example: "like"
isDeleted
Boolean
Flag that determines if comment is deleted
Default: false
editedAt
String($date-time)
Date/time when comment was edited
createdAt
String($date-time)
Date/time when comment was created
updatedAt
String($date-time)
Date/time when comment was updated or deleted
children
String
ID of the children comment
segmentNumber
Integer
required
Object

Comment reference type

A comment's referenceType can be:
  • post
  • content
A post type comment is a comment that is intended for a regular post. A content type comment on the other hand is intended for a content type post. A content type comment will automatically create a content post if the referenceId does not exist yet.

Create Comment

AmityCommentRepository provides createComment() method to create comment. You can provide contentId, parentId and text while creating a comment. parentId is an optional parameter, useful for replying to a comment. The concept is similar to the AmityMessage where you can reply to a message object with a parentId.
A comment should not exceed 20,000 characters in length. For now, only text data is supported in the creation method.

Comments Query

AmityCommentRepository provides getComments() method to query for comments. The query returns a LiveCollection of all the matching comments available.
To query for replies to a specific comment. You can pass the commentId as the parentIdparentId = commentId . To get parent level, pass parentId = null . Omitting parentId will get all comments on all levels.
To query for comments and replies that are deleted. You can pass true or false in aincludeDeleted(...) method.
The objects that return when you call the getComments() method are PageList<AmityComment>. If you want to know which comments are deleted, you can check from isDeleted() method in the AmityComment.
Note: If you use the includeDeleted(...) method, you don't need to check isDeleted() method in the AmityComment for deleted comments.

Pagination

When querying comments, you cannot set limit, skip, after, first, before, and last parameters. By default, the number of items in each page is 15. To handle pagination to load more comments, refer to Implementing feed pagination.

View Comment

Currently, AmityComment has one data type TEXT. Other types are coming soon.

Edit Comment

Comment editing options depend on AmityComment data type.
On AmityComment.Data.TEXT model, there is an edit() method that initiates text data editing chain. The replacing text can be passed to text() method.
Only the owner of the comment or an admin can update a comment.

Delete Comment

There are two kinds of comments deletion:
  1. 1.
    Soft delete
    The comment is only marked as deleted. This means that the comment still exists in the database but the isDeleted flag is set to true.
  2. 2.
    Hard delete
    The comment data, along with its reactions and replies, are removed from the database. Thus, all data related to the comment will be lost and irretrievable. Hard deleting children comments will not delete the parent comment.
    Hard delete is applicable for posts and comments only. You cannot hard delete Users and Communities.
    Hard deleting posts, as well as comments, is only supported via SDK. UIKit and Console support may be considered in the future.
To delete a comment, the delete() method is available on the AmityComment model. You need to pass the commentId and a boolean parameter. Set the boolean parameter to true for hard delete and false for soft delete.
Only the owner of the comment or an admin can delete a comment.

Flag Comment

On AmityCommentFlaggermodelflag() and unflag methods are available.
The info such as flagCount: Int and isFlaggedByMe: Boolean are also available in the AmityComment model via getFlagCount() and isFlaggedByMe() methods respectively.

Reactions

AmityComment provides react() method to help instantiate AmityReactormodel.
In AmityReactormodel,addReaction() and removeReaction() methods are available for adding and removing reaction to a comment respectively. Refer to Add Reaction and Remove Reaction for more details.
AmityComment model provides info such as the reactions reactionCount: Int ,myReactions: List<String>, reactionMap: AmityReactionMapvia getReactionCount(), getMyReactions(), and getReactionMap() methods respectively.
Export as PDF
Copy link
Outline
Comment Description
Comment reference type
Create Comment
Comments Query
Pagination
View Comment
Edit Comment
Delete Comment
Flag Comment
Reactions