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
"reactionName": "string",
5
"userId": "string",
6
"reactionId": "string",
7
"reactorId": "string",
8
"reactorDisplayName": "string",
9
"createdAt": "2021-08-26T06:07:23.712Z"
10
}
Copied!

Reaction Description

Name
Data Type
Description
Attributes
referenceId
String
ID of a document
referenceType
String
Type of document
reactionName
String
Name of reaction
'like', 'love' , 'wow'
userId
String
ID of user
reactionId
String
ID of the reaction
reactorId
String
ID of the reactor
reactorDisplayName
String
Display name of the reactor
createdAt
String($date-time)
The date/time when a reaction is created

Reaction Query

To query for a list of all reactions on the specific message in a channel, one must utilize AmityMessageRepository. We can observe this the same way as when we observe messages. The only difference is you will have to use messageId as the parameter. The operation will return an instance AmityCollection of AmityReaction that contains the reaction name, message id, reactor id and reactor display name of the user who reacted to the message.
1
let reactionsCollection: AmityCollection<AmityReaction> = messageRepository.getReactions(message.messageId, referenceType: .message, reactionName: nil)
2
3
self.reactionsNotification = reactionsCollection.observe { [weak self] _, _ in
4
// refresh tableview or the view
5
self?.tableview.reloadData()
6
}
Copied!
This method will return a LiveObject of all reactions of specific message in the specified channel. You can observe the LiveObject in order to update your view whenever you receive new reaction on that message.

Add Reaction

For adding a new reaction, we can use AmityReactionRepository to perform its operation. Initialize the reactor with the client and specify messageId and the reaction name.
1
let messageReactor = AmityReactionRepository(client: client)
2
messageReactor.addReaction(reaction, referenceId: message.messageId, referenceType: .message) { (success, error) in}
Copied!

Remove Reaction

In order to remove a new reaction, we can use AmityReactionRepository . Initialize the reactor with the client and specify the messageId and reaction name.
1
let messageReactor = AmityReactionRepository(client: client)
2
messageReactor.removeReaction(reaction, referenceId: message.messageId, referenceType: .message) {(success, error) in}
Copied!
Last modified 1mo ago