Reactions

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.

Reading the reactions

Each model which can be reacted upon will carry a set of properties useful to display its reactions. You will find:

  1. reactions: an object containing the name of the reactions as key, and their count as value (ex: { like: 1, love: 1 })

  2. reactionCount: the sum of all the counts for all the reactions

  3. 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) // 8
console.log(messageModel.myReactions) // ['love', 'care']

Reacting on a model

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')

Removing a reaction

Just as you did for adding a reaction, you can call removeReaction() to remove a reaction.

reactorRepo.removeReaction('love')

Server feedback

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) // true
const didUnreact = reactorRepo.removeReaction('love')
console.log(didUnreact) // true