Each comment is identified by an unique commentId, which is an immutable string. When creating a new comment, you do not need specify your own commentId, leave it to Eko to generate one for you. We also provide optimistic update on each comment. You also need to sent an referenceId which is a postId for current supported version. Before that you need to use EkoCommentRepository for doing an activity regarding comment, from doing an editing operation until flag a comment.

There are 2 methods in EkoCommentRepository which is creating a comment as well get a collection of comments. They all return a LiveObject with the complete comment model.

Comment management methods are contained in a EkoCommentRepository class. Before being able to call any comment method, you must initialize a repository instance using the EkoClient instance you created on setup:

let repository: EkoCommentRepository = EkoCommentRepository(client: client)

Create Comment

EkoCommentRepository provides one convenient methods to create comment. You can provide referenceId, parentId and text while creating a comment. parentId is optional parameters and useful for replying a comment. The concept is similar with the EkoMessage that you can reply a message object with a parentId. For now only text data that supported in the creation method.

var commentToken: EkoNotificationToken?
let commentObject: EkoObject<EkoComment> = repository.createComment(withReferenceId: postId!, parentId: parentCommentId, text: text)
commentToken = commentObject.observe { commentObject, error in
if let error = error {
// Handle comment create error
guard let comment = commentObject.object
print("Comment created: \(comment.commentId)")

The above code creates a comment and prints out the commentId once it has been successfully created. It first instantiates the EkoCommentRepository, a class that contain all comment related methods. Then it calls createComment: to obtain the LiveObject and observe it in order to obtain the final comment model.

The EkoNotificationToken returned by the observe is saved in self.commentToken, a strongly referenced property. This is needed in order to prevent the observe block to be released.

The parent parameter in createComment: is an optional.

The referenceId parameter in createComment: is a mandatory and only support EkoPost identifier.

Comments are created locally first and then synced with the server. You can check the syncState property of comment to see if it has been synced with the server or not.

Comments Query

The EkoCommentRepository provides method to get the query. Methods channelsForFilter(_:) and commentsWithReferenceId(_:) is method that return a LiveCollection of all the matching comments available. Like other LiveObjects, the collection returned will automatically update and notify you on any comment modifications (e.g. new comment, deleted comment, modified comment, flagged comment).

Use filterByParentId in case you only want the result from specific parentId, this case useful if you want to get specific comments per level. If you want to get all only parent level then you can use filterByParentId set to true without sending any parentId parameter, otherwise you will get all comments on all levels.

var commentCollection: EkoCollection<EkoComment>?
var commentCollectionToken: EkoNotificationToken?
commentCollection = commentRepository.comments(withReferenceId: postId!, filterByParentId: true, parentId: parentCommentId, orderBy: .descending, includeDeleted: false)
commentCollectionToken = commentCollection?.observe { [weak self] _, _, _ in
// Update datasource

You can order the comments in descending order (i.e latest comment first). In this case you will have to call previousPage() method to fetch more comments. Please look into method documentation for more details.

Edit Comment

For do any editing operation either update or delete a comment you can use EkoCommentEditor. EkoCommentEditor instantiate by using the selected commentId and the client. They have 2 methods which is editText:withCompletion: and deleteWithCompletion:

// The editor object
var editor: EkoCommentEditor? {
return EkoCommentEditor(client: client, commentId: commentId)
// For editing the data
editor?.editText(text, completion: { (success, error) in
// Do something with success
// For delete the comment
editor?.delete(completion: { (success, _) in
// Do something with success

Flag Comment

For do any flag operation either update or delete a comment you can use EkoCommentFlagger. EkoCommentFlagger instantiate by using the selected commentId and the client. They have 3 methods which is flagWithCompletion:, unflagWithCompletion: and isFlagByMeWithCompletion:

// The flagger object
var flagger: EkoCommentFlagger? {
return EkoCommentFlagger(client: client, commentId: commentId)
// For flagging the comment
flagger?.flag(completion: { (success, _) in
// Do something with success
// For unflag the comment
flagger?.unflag(completion: { (success, _) in
// Do something with success
// For get the flag status
flagger?.isFlagByMe(completion: { (isFlagged) in
// Do something with the flag status


EkoComment object includes information about the reactions for that post. Use myReactions property to get list of your reactions to the post, reactions property to get list of all reactions to the post and reactionsCount provides the total count of reactions on that post.

To add or remove reaction, please refer to documentation for EkoReactionRepository.