Reactions

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

Reactions are the interactions that you can perform with a message, post, or comment. This can be anything such as like, dislike, love, etc.

MessageRepository, PostRepository, and CommentRepository classes provide a convenient method to add, remove, and query reactions for any content. Currently, reactions are supported for Posts, Messages, and Comments.

import { MessageRepository, PostRepository, CommentRepository } from '@amityco/js-sdk';

Reaction Description

Name

Data Type

Description

Attributes

reactionId

String

ID of a reaction

referenceId

String

ID of a document

referenceType

String

Type of document

userId

String

ID of the creator

reactionName

String

Name of reaction

'like', 'love' , 'wow'

createdAt

String($date-time)

Date/time when a reaction is created

Reaction Data

Each post, comment, message has a set of fields providing detailed info about reactions.

  • reactionsCount - how many reactions the post has

  • myReactions - list of reactions you added to the post

  • reactions - map that tells how many reactions of a certain type a post has

Before you can perform the adding or removing of reactions to the related post or comment, the post or comment must be fetched from the server first using either of these methods:

Methods used for fetching posts

Methods used for fetching comments

Query Reaction

You can fetch a detailed information about reactions and the users who reacted to a post, comment, or message by using the ReactionRepository class.

You can fetch information about a particular reaction and all the reactions through thequeryReactions method. This method requires the following parameters:

  • referenceId - ID of the post and content

  • referenceType - values can be message, post and comment

The response from the query is a collection of reaction models.

Add Reaction

You can add reactions to a given post through the addReaction method which accepts the following parameters:

  • postId/commentId - ID of the post or comment respectively

  • reactionName - name of the reaction that you will add. Reaction name is case sensitive, i.e "like" & "Like" are two different reactions.

The method returns a promise. If the reaction is successfully added, the method will return true. Otherwise, it will return false or an error.

Remove Reaction

You can remove a reaction from a message, post, or comment by calling removeReaction. This method requires the following parameters:

  • postId/commentId - ID of the post or comment respectively

  • reactionName - name of the reaction that you will remove. Reaction name is case sensitive, i.e "like" & "Like" are two different reactions.

The method returns a promise. If the reaction is successfully removed, the method will return true. Otherwise, it will return false or an error.

Last updated