Reactions

Let users react to messages, posts, and comments, which are visible to others.

Reactions are the interactions that user can perform with message, post or comment. The interactions can be anything such as like, dislike, love etc. It's up to the client to determine the type of reactions. EkoReactionRepository class provides convenient method to add, remove, and query reactions for any content. Currently reactions are supported for Posts, Messages & Comments.

let reactionRepository = EkoReactionRepository(client: client)

Query Reactions

You can fetch detailed information about reactions and the user who reacted to the post. EkoReactionRepository class provides two methods which gets detailed information about reactions to the post. Each information is provided though EkoReaction object.

You can fetch information about particular reaction name through getReactions method. This method requires reactionName, contentId and referenceType as a parameter and provide you with collections of EkoReaction. contentId as the reference id for Post, Message or Comment.

let reactionCollectionToken: EkoNotificationToken?

...

let reactionCollection = reactionRepository.getReactions("reference-id", referenceType: .reference-type, reactionName: "reaction-name")
reactionCollectionToken = reactionCollection?.observe({ (collection, change, error) in
    // React to changes here
})

You can also fetch information about all the reactions through getAllReactions method. This method requires only postId as a parameter and provide all reactions for particular message, post or comment.

let reactionCollectionToken: EkoNotificationToken?

...

reactionCollection = reactionRepository.getAllReactions("reference-id", referenceType: .reference-type )
reactionCollectionToken = reactionCollection?.observe({ (collection, _, error) in
    // React to changes here
})

Add Reaction

You can add any number of reactions to the given post. EkoReactionRepository provides addReaction method which accepts reaction name. Reaction name is case sensitive i.e "like" & "Like" are two different reactions.

reactionRepository.addReaction("reaction-name", referenceId: "reference-id", referenceType: .reference-type) { (isSuccess, error) in
    // React to completion handler here
}

Remove Reaction

You can remove any reactions added to the post. EkoReactionRepository provides removeReaction method which removes reaction name. Reaction name is case sensitive in this case too.

reactionRepository.removeReaction("reaction-name", referenceId: "reference-id", referenceType: .reference-type) { (isSuccess, error) in
    // React to completion handler here
}

Last updated