Reactions

Reactions are the interactions that user can perform with message, post or comments. The interactions can be anything such as like, dislike, love etc. It's upto the client to determine the type of reactions. EkoReactionRepository class provides convenient method to add, remove, query reactions for any content. Currently reactions are supported for Post, Message & 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 method 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 parameter and provides you with collection of EkoReaction. contentId is 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 reactions through getAllReactions method. This method requires only postId as parameter and provides information about 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
}