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)
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 inif let error = error {// Handle comment create errorreturn}guard let comment = commentObject.objectprint("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 theobserve
is saved inself.commentToken
, a strongly referenced property. This is needed in order to prevent the observe block to be released.The
parent
parameter increateComment:
is an optional.The
referenceId
parameter increateComment:
is a mandatory and only supportEkoPost
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.
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.
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 objectvar editor: EkoCommentEditor? {return EkoCommentEditor(client: client, commentId: commentId)}​// For editing the dataeditor?.editText(text, completion: { (success, error) in// Do something with success})​// For delete the commenteditor?.delete(completion: { (success, _) in// Do something with success})
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 objectvar flagger: EkoCommentFlagger? {return EkoCommentFlagger(client: client, commentId: commentId)}​// For flagging the commentflagger?.flag(completion: { (success, _) in// Do something with success})​// For unflag the commentflagger?.unflag(completion: { (success, _) in// Do something with success})​// For get the flag statusflagger?.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
.