On this page

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.

icon

Usage in Blueprints and C++


Asynchronous and synchronous method execution

Most PubNub Unreal SDK methods are available in both asynchronous and synchronous variants.

  • Asynchronous methods (Async suffix) return void and take an optional delegate parameter that fires when the operation completes.

    1Message->ToggleReactionAsync(Reaction, OnToggleReactionResponseDelegate);

    You can also use native callbacks that accept lambdas instead of dynamic delegates. Native callback types have the Native suffix (for example, FOnPubnubChatOperationResponseNative).

  • Synchronous methods (no suffix) block the main game thread until the operation completes and return a result struct directly.

    1FPubnubChatOperationResult Result = Message->ToggleReaction(Reaction);

Add & delete

ToggleReaction() is a method for both adding and removing message reactions. It adds a string flag to the message if the current user hasn't added it yet or removes it if the current user already added it before.

If you use this method to add or remove message reactions, this flag would be a literal emoji you could implement in your app's UI. However, you could also use this method for a different purpose, like marking a message as pinned to a channel or unpinned if you implement the pinning feature in your chat app.

Method signature

Output

TypeDescription
FPubnubChatOperationResult
Result of the operation. Check Error and ErrorMessage for failure.

Sample code

Reference code

This example is a self-contained code snippet ready to be run. Set up your Unreal project and follow the instructions in the lines marked with ACTION REQUIRED before running the code. Use it as a reference when working with other examples in this document.

Toggle a reaction on a message asynchronously.

Actor.h
1

Actor.cpp
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

GetReactions() returns a list of all reactions added to the given message (with the ID of the user who added it and the timetoken stating when this action was added).

Method signature

Output

FieldTypeDescription
Result
FPubnubChatOperationResult
Operation result with Error (bool) and ErrorMessage (FString).
Reactions
TArray<FPubnubChatMessageReaction>
An array of reaction objects. Each FPubnubChatMessageReaction contains: Value (FString), IsMine (bool), UserIDs (TArray<FString>), Count (int).

Sample code

List all reactions added to a 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 GetHistory() method. By default, when you fetch historical messages, PubNub returns all message reactions and metadata attached to the retrieved messages.

Check

HasUserReaction() checks if the current user added a given emoji to the message.

Method signature

Output

FieldTypeDescription
Result
FPubnubChatOperationResult
Operation result with Error (bool) and ErrorMessage (FString).
HasReaction
bool
Specifies if the current user added a given emoji to the message or not.

Sample code

Check if the current user added the "thumb up" emoji to a message on the support channel.

1

Last updated on