Reactions
Add, get, and delete message reactions for messages sent on apps built with the Unreal Chat SDK.
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
- Blueprint
- C++ / Input parameters
Message->ToggleReaction(FString Reaction);
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
Reaction | FString | Yes | n/a | Emoji added to the message or removed from it by the current user. |
Output
Type | Description |
---|---|
UPubnubMessage* | Updated message instance with an added reactions action type. |
Basic usage
Add the "thumb up" emoji (\u{1F44D}
) to a message on the support
channel.
#include "Kismet/GameplayStatics.h"
#include "PubnubChatSubsystem.h"
UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
UPubnubChannel* Channel = Chat->GetChannel("support");
// Get the message
UPubnubMessage* Message = Channel->GetMessage("16200000000000001");
Message->ToggleReaction("\u{1F44D}");
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
is a getter method that returns a list of all reactions added to the given messages (with the ID of the user who added it and the timetoken stating when this action was added).
Method signature
- Blueprint
- C++ / Input parameters
Message->Reactions();
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
Reaction | FString | Yes | n/a | Emoji added to the message or removed from it by the current user. |
Output
Type | Description |
---|---|
TArray<FPubnubMessageAction> | An array of Message Action objects. |
Basic usage
List all reactions added to a message on the support
channel.
#include "Kismet/GameplayStatics.h"
#include "PubnubChatSubsystem.h"
UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
UPubnubChannel* Channel = Chat->GetChannel("support");
// Get the message
UPubnubMessage* Message = Channel->GetMessage("16200000000000001");
// Get the reactions
TArray<FPubnubMessageAction> Reactions = Message->Reactions();
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
- Blueprint
- C++ / Input parameters
Message->HasUserReaction(FString Reaction);
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
Reaction | FString | Yes | n/a | Specific emoji added to the message. |
Output
Type | Description |
---|---|
bool | Specifies if the current user added a given emoji to the message or not. |
Basic usage
Check if the current user added the "thumb up" emoji (👍) to a message on the support
channel.
#include "Kismet/GameplayStatics.h"
#include "PubnubChatSubsystem.h"
UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
UPubnubChannel* Channel = Chat->GetChannel("support");
// Get the message
UPubnubMessage* Message = Channel->GetMessage("16200000000000001");
// Check for a reaction
bool HasAThumbsUpEmoji = Message->HasUserReaction("👍");