Reactions
Manage emoji reactions on messages in your Chat SDK app. Users can add, remove, and view reactions on any message.
Message Actions vs. Message Reactions
Message Actions is the flexible, low-level API for adding any metadata to messages (read receipts, delivery confirmations, custom data), while Message Reactions specifically refers to using Message Actions for emoji/social reactions.
In PubNub Core and Chat SDKs, the same underlying Message Actions API is referred to as Message Reactions when used for emoji reactions - it's the same functionality, just different terminology depending on the use case.
Add & delete
ToggleReaction() adds or removes a message reaction. It adds a string flag if the current user hasn't added it yet, or removes it if already added.
Use this method for emoji reactions or other purposes like pinning messages to channels.
Method signature
This method takes the following parameters:
1message.ToggleReaction(string reactionValue)
Input
| Parameter | Description |
|---|---|
reactionValue *Type: stringDefault: n/a | Emoji added to the message or removed from it by the current user. |
Output
An awaitable Task<ChatOperationResult>.
Sample code
Add the "thumb up" emoji (\u{1F44D}) to the last message on the support channel.
1
Get updates
To learn how to receive updates whenever a message reaction is added, edited, or removed on other clients, head to the Get updates section.
Get reactions for one message
Reactions returns all reactions added to a message (with the user ID and timetoken for each).
Method signature
This method has the following signature:
1message.Reactions
Input
This method doesn't take any parameters.
Output
| Type | Description |
|---|---|
List<MessageAction> | A list of MessageAction objects, each containing details of a reaction including its type, value, timestamp, and the user ID of the person who added the reaction. |
Sample code
List all reactions added to the last message on the support channel.
1
Get historical reactions
If you have Message Persistence enabled on your keyset, PubNub stores all historical info about messages, their metadata, and reactions.
If you want to fetch historical info about message reactions, use the GetMessageHistory() method. By default, when you fetch historical messages, PubNub returns all message reactions and metadata attached to the retrieved messages.
Check reactions
HasUserReaction() checks if the current user added a given emoji to the message.
Method signature
This method takes the following parameters:
1message.HasUserReaction(string reactionValue)
Input
| Parameter | Description |
|---|---|
reactionValue *Type: stringDefault: n/a | Specific emoji added to the message. |
Output
| Type | Description |
|---|---|
bool | Specifies if the message has the specified user reaction (true) or not (false). |
Sample code
Check if the current user added the "thumb up" emoji (👍) to the last message on the support channel.
1