Query Comment
Last updated
Was this helpful?
Last updated
Was this helpful?
The ability to query comments and their replies is essential for creating a robust and user-friendly commenting experience. By using the getComments()
method and passing in the appropriate parameters, you can retrieve the comments and replies that are most relevant to your users.
The query returns a LiveCollection of all matching comments available. To retrieve replies to a specific comment, you can pass the commentId
as the parentId
. If you want to retrieve parent-level comments, pass parentId = null
. If you omit the parentId
, you'll receive all comments on all levels.
You can also use the includeDeleted()
method to query for deleted comments and their replies. By passing true
or false
to this method, you can include or exclude deleted comments from the results.
Note that if you use the includeDeleted()
method, you don't need to check the isDeleted()
method in the AmityComment
object for deleted comments.
The referenceType
parameter specifies where the comment is made and helps filter the comments based on the type of content. Possible values include:
post
: Comments on posts.
story
: Comments on stories.
content
: Comments on other types of content (e.g., images, videos, etc.).
To query comments, provide the referenceType
and referenceId
. You can also include additional filters like parentId
, includeDeleted
, and orderBy
to control the results.
To query comments for a post (including replies and excluding deleted comments):
To query for image comments only, you can use the dataTypes
parameter and pass the value TEXT
, IMAGE
, or both. There are two options for the dataTypes
parameter: any
and exact
.
any
- When you use the any
option, the retrieved comments will include any comment that contains at least one of the specified data types. For example, if you pass [image, text]
, the retrieved comments may contain only image content, only text content, or both image and text content.
exact
- On the other hand, when you use the exact
option, the retrieved comments will include only comments that contain all of the specified data types. For example, if you pass [image, text]
, the retrieved comments must contain both image and text content. If you pass [image]
, the retrieved comments must contain only image content.
To query for comments containing only image content:
Using exact filer parameter:
Using any filter parameter:
Refer to the following Limitations on the use of images in comments.
Refer to for a more detailed explanation of the referenceType
parameter.