Reaction
Interactions are more fun when you can express yourself! Let users react using emojis, stickers, or thumbs up to messages.

Reaction Model

When you are observing reactions, it will always appear in this format:
1
{
2
"referenceId": "string",
3
"referenceType": "string",
4
"reactors": [
5
{
6
"reactionName": "string",
7
"userId": "string",
8
"reactionId": "string",
9
"createdAt": "2021-08-26T06:07:23.712Z"
10
}
11
]
12
}
Copied!

Reaction Description

Name
Data Type
Description
Attributes
referenceId
String
ID of a document
referenceType
String
Type of document
reactors
Array of Objects
List of mapping between reaction and reactor ID.
reactionName : ( 'like', 'love' , 'wow')
userID: ID of a creator
reactionId: ID of a reaction
createdAt: The date/time when a reaction is created

Reaction Data

There are 3 Reaction related methods on AmityMessage:
1. getReactionCount() returns Int, the total reaction count on the message.
2. getMyReactions() returns List<String>, a collection of reactions that have been added by the active user.
3. getReactions() returns AmityReactionMap, an extension of Map<String, Int> of reaction name and its count.
1
// To get reaction count of the message
2
val reactionCount = message.getReactionCount()
3
4
// To get a list of my reactions on the message
5
val myReactions = message.getMyReactions()
6
7
// To get a reaction map of the messsage
8
val reactionMap = message.getReactionMap()
9
10
// Count of a specific reactionName
11
val likeCount = reactionMap.getCount("like")
Copied!

Add/Remove Reaction

You can choose to add/remove a reaction to/from a message by calling react() method on AmityMessage
1
// Add a reaction
2
message.react()
3
.addReaction("like")
4
.subscribe()
5
6
// Remove a reaction
7
message.react()
8
.removeReaction("like")
9
.subscribe()
Copied!

Reaction Query

To query for a list of all reactions on a message:
1
message.getReactions()
2
.build()
3
.query()
4
.subscribe( { adapter.submitList(it) } )
Copied!
This method will return a Flowable<PagedList<AmityReaction>> of all reactions in the specified message.
Last modified 1mo ago