Comments

Each comment is identified by a unique commentId, which is an immutable string. When creating a new comment, you do not need specify your own commentId, leave it to SDK to generate one for you. We also provide optimistic update on each comment. You also need to send a referenceId which is a contentId 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.

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 initialize a repository instance using the EkoClient instance 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 with the EkoMessage that 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

Comment collection

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, pass the commentId as the parentIdparentId = commentId . To only 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)
.sortBy(EkoCommentSortOption.FIRST_CREATED)
.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)
.sortBy(EkoCommentSortOption.FIRST_CREATED)
.build()
.query()
.subscribe( { adapter.submitList(it) } )
// To query for all comments, omit parentId method
commentRepository.getCommentCollection()
.contentId(contentId)
.sortBy(EkoCommentSortOption.LAST_CREATED)
.build()
.query()
.subscribe( { adapter.submitList(it) } )

Latest comment

EkoCommentRepository provides getLatestComment() method to query for the latest comment on the content. The query returns the latest non deleted EkoComment .

commentRepository.getLatestComment()
.contentId(contentId)
.build()
.query()
.subscribe( { it.getData() } )

View Comment

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

To get text data from a data type TEXT, call getData() on a EkoComment and validate that data is really an instance of EkoComment.Data.Text , and call getText() on the model.

// 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

EkoComment provides report() method to help instantiate EkoCommentFlaggermodel.

On EkoCommentFlaggermodelflag() and unflag methods are available.

The info such as flagCount: Int and isFlaggedByMe: Boolean are available on 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.

On 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()