To maximize engagement on the content of your application, you can use reactions on messages, posts, or comments. The reaction is similar to the Facebook Like. While a user can add many reactions to a model, it can only add each reaction one time only.
Each model which can be reacted upon will carry a set of properties useful to display its reactions. You will find:
reactions
: an object containing the name of the reactions as key, and their count as value (ex: { like: 1, love: 1 }
)
reactionCount
: the sum of all the counts for all the reactions
myReactions
: an array containing the current's users reactions
const liveObject = messageRepo.findById('exampleMessageId')const messageModel = liveObject.model​console.log(messageModel.reactions) // { like: 1, love: 4, care: 3 }console.log(messageModel.reactionCount) // 8console.log(messageModel.myReactions) // ['love', 'care']
First, simply import the ReactorRepository
and pass in the message you want to react upon.
import { ReactorRepository } from 'eko-sdk';const reactorRepo = new ReactorRepository(messageModel);
Then call for addReaction()
and pass along the identifier for your reaction.
reactorRepo.addReaction('love')
Just as you did for adding a reaction, you can call removeReaction()
to remove a reaction.
reactorRepo.removeReaction('love')
Both addReaction()
and removeReaction()
methods return a Promise resolving a boolean acknowledging the server's successful response. If necessary, you can use await
to receive the result of those operations.
const didReact = await reactorRepo.addReaction('love')console.log(didReact) // trueconst didUnreact = reactorRepo.removeReaction('love')console.log(didUnreact) // true