Comments

Here's an overview of how you can get started 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, and 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 EkoCommentRepository 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 EkoCommentRepository which is creating a comment as well as get a collection of comments. They all return a LiveCollection with the comment model.

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

val commentRepository: EkoCommentRepository = EkoClient.newCommentRepository()

Create Comment

EkoCommentRepository provides createComment() method to create comment. You can provide referenceId, parentId and text while creating a comment. parentId is an optional parameter, useful for replying a comment. The concept is similar to the EkoMessage where you can reply a message object with a parentId. For now, only text data is supported in the creation method.

commentRepository.createComment()
                 .contentId(contentId)
                 .with()
                 .text("Hello world!")
                 .build()
                 .send()
                 .subscribe()  

commentRepository.createComment()
                 .contentId(contentId)
                 .parentId(parentId)
                 .with()
                 .text("Hello world!")
                 .build()
                 .send()
                 .subscribe()

Comments Query

EkoCommentRepository provides getCommentCollection() 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 all first level comments, pass parentId = null
commentRepository.getCommentCollection()
                 .contentId(contentId)
                 .parentId(null)
                 .build()
                 .query()
                 .subscribe( { adapter.submitList(it) } )

// To query for replies on a comment, pass the commentId as a parentId
commentRepository.getCommentCollection()
                 .contentId(contentId)
                 .parentId(commentId)
                 .build()
                 .query()
                 .subscribe( { adapter.submitList(it) } )

// To query for all comments, omit parentId method                 
commentRepository.getCommentCollection()
                 .contentId(contentId)
                 .build()
                 .query()
                 .subscribe( { adapter.submitList(it) } )

View Comment

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

// text data
val data = comment.getData()
when(data) {
    is EkoComment.Data.Text -> {
        val text = data.getText()
    }
}

Edit Comment

Comment editing options depend on EkoComment data type.

On EkoComment.Data.Text model, there is an edit() method that initiates text data editing chain. The replacing text can be passed to text() method.

To delete a comment, the delete() method is available on the EkoComment model.

// text editing
val textData : EkoComment.Data.Text = ...
textData.edit()
        .text("Hello")
        .build()
        .apply()
        .subscribe()

// comment deletion
comment.delete().subscribe()

Flag Comment

On EkoCommentFlaggermodelflag() and unflag methods are available.

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

// Flag a comment
comment.report()
            .flag()
            .subscribe()

// Unflag a comment
comment.report()
            .unflag()
            .subscribe()

// Get comment's total flag count
val flagCount = comment.getFlagCount()

// Check whether comment has been flagged by the active user
val isFlaggedByMe = comment.isFlaggedByMe()

Reactions

EkoComment provides react() method to help instantiate EkoReactormodel.

In EkoReactormodeladdReaction() and removeReaction() methods are available.

EkoComment model provides info such as the reactions reactionCount: Int ,myReactions: List<String>, reactionMap: EkoReactionMapvia getReactionCount(), getMyReactions(), and getReactionMap() methods respectively.

// Add a reaction
comment.react()
            .addReaction("like")
            .subscribe()

// Remove a reaction
comment.react()
            .removeReaction("like")
            .subscribe()

// Get comment's total reaction count
val reactionCount = comment.getReactionCount()

// Get my reactions on the comment
val myReactions = comment.getMyReactions()

// Get comment's reaction map { "like": "10" }
val reactionMap = comment.getReactionMap()

Last updated