Message threads
The message threads feature organizes conversations into threads, making it easier to follow and respond to specific topics.
Users need threads to:
-
Set topic-specific discussions - within group chats or 1:1 conversations, you can initiate or participate in separate threads dedicated to specific topics, ensuring focused and structured discussions.
-
Clarify and resolve issues - message threads let you address specific problems or questions within a conversation, allowing you to provide relevant input and ensure clarity and efficient problem-solving.
-
Reduce confusion - by allowing you to focus the conversation in a separate thread, you minimize cross-talk and make the conversation easier to follow.
In the Unreal Chat SDK, a thread is a separate channel created for a selected message. Such a thread channel gets the ID starting with PUBNUB_INTERNAL_THREAD
followed by the channel ID and message ID (separated by underscores). The message for which you create a thread channel has the hasThread
parameter set to true
to distinguish it from other messages. All messages in a thread (thread messages) are ordered by timetokens containing info on when messages were published.
Each thread message (threadMessage
) and thread channel (threadChannel
) are separate entities in the Unreal Chat SDK that extend the message
and channel
entities. This means that they offer separate methods for handling threads but also let you use all methods under the message
and channel
entities (for example, for editing or deleting).
Create thread
CreateThread()
creates a thread (channel) for a selected message.
Method signature
- Blueprint
- C++ / Input parameters
Message->CreateThread();
Output
Type | Description |
---|---|
UPubnubThreadChannel* | Object returning the thread channel metadata for the message updated with the hasThread parameter (and a threadRootId action type underneath). |
Basic usage
Create a thread for the last 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");
FString Timetoken = "16200000000000001";
// Fetch the message
UPubnubMessage* Message = Channel->GetMessage(Timetoken);
show all 16 linesSend thread message
Reply to a message in a thread by calling the SendText()
method from the previously created threadChannel
object.
Method signature
Head over to the SendText()
method section for details.
Get thread
Get the thread channel on which the thread message is published.
Method signature
- Blueprint
- C++ / Input parameters
Message->GetThread();
Output
Type | Description |
---|---|
UPubnubThreadChannel* | Object returning the thread channel metadata. |
Basic usage
Get the thread channel created from the message with the 16200000000000001
timetoken.
#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");
FString Timetoken = "16200000000000001";
// Fetch the message
UPubnubMessage* Message = Channel->GetMessage(Timetoken);
show all 16 linesUtility getter function
You can use the HasThread
method to check if a given message starts a thread.
Method signature
This method has the following signature:
- Blueprint
- C++ / Input parameters
Message->HasThread();
Properties
Type | Description |
---|---|
bool | Info on whether the message already starts a thread or not. |
Basic usage
Check if the message with the 16200000000000001
timetoken starts a thread.
#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");
FString Timetoken = "16200000000000001";
// Fetch the message
UPubnubMessage* Message = Channel->GetMessage(Timetoken);
show all 16 linesGet thread updates
You can receive updates when specific message threads and related message reactions are added, edited, or removed on other clients using the StreamThreadMessageUpdatesOn()
on the ThreadMessage
object.
This method accepts a callback function as an argument. The Unreal Chat SDK invokes this callback whenever someone adds, edits or deletes a message, or adds or removes a message reaction to/from the specific message thread(s).
Underneath, this method subscribes the current user to a channel and adds a message reactions event listener to receive all messageAction
events of type added
or removed
. These methods also return the unsubscribe
function you can invoke to stop receiving messageAction
events and unsubscribe from the channel.
Method signature
- Blueprint
- C++ / Input parameters
ThreadMessage->StreamThreadMessageUpdatesOn(
TArray<UPubnubThreadMessage*> Messages,
FOnPubnubThreadMessagesStreamUpdateOnReceived MessageUpdateCallback
);
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
Messages | TArray<UPubnubThreadMessage*> | Yes | n/a | Array of ThreadMessage objects for which you want to get updates on changed message threads or related message reactions. |
MessageUpdateCallback | FOnPubnubThreadMessagesStreamUpdateOnReceived | Yes | n/a | Callback function passed to the method as a parameter. It defines the custom behavior to be executed when detecting changes in message threads or related message reactions. |
Output
Type | Description |
---|---|
UPubnubCallbackStop* | Object on which you can call Stop() to stop receiving updates. |
Basic usage
Get message threads and message reaction-related updates for messages published in a thread 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");
// Create a pubnub response delegate
// you MUST implement your own callback function to handle the response
FOnPubnubThreadMessagesStreamUpdateOnReceived ThreadUpdatesOnResponse;
ThreadUpdatesOnResponse.BindDynamic(this, &AMyActor::OnThreadUpdatesResponseReceived);
UPubnubChannel* Channel = Chat->GetChannel("support");
show all 28 linesGet historical thread message
GetThreadHistory()
called on the threadChannel
object fetches historical thread messages from that thread channel.
Method signature
This method takes the following parameters:
- Blueprint
- C++ / Input parameters
ThreadChannel->GetThreadHistory(
int Limit,
FString Start,
FString End
);
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
Limit | int | No | n/a | Number of historical thread messages to return for the channel in a single call. Since each call returns all attached message reactions by default, the maximum number of returned thread messages is 25 . |
Start | FString | No | n/a | Timetoken delimiting the start of a time slice (exclusive) to pull thread messages from. |
End | FString | No | n/a | Timetoken delimiting the end of a time slice (inclusive) to pull thread messages from. |
Output
Type | Description |
---|---|
TArray<UPubnubThreadMessage*> | Array listing the requested number of historical thread Message objects. |
By default, each call returns all message reactions and metadata attached to the retrieved thread messages.
Basic usage
From the thread created for a message in the support
channel, fetch 10
historical thread messages that are older than the timetoken 15343325214676133
.
#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");
FString Timetoken = "16200000000000001";
// Fetch the message
UPubnubMessage* Message = Channel->GetMessage(Timetoken);
show all 18 linesRemove thread
RemoveThread()
removes a thread (channel) for a selected message.
Method signature
- Blueprint
- C++ / Input parameters
Message->RemoveThread();
Output
This method doesn't return any value.
Basic usage
Remove a thread for 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");
FString Timetoken = "16200000000000001";
// Fetch the message
UPubnubMessage* Message = Channel->GetMessage(Timetoken);
show all 16 linesPin thread message to thread channel
PinMessageToThread()
called on the ThreadChannel
object pins a selected thread message to the thread channel.
Method signature
- Blueprint
- C++ / Input parameters
ThreadChannel->PinMessageToThread(UPubnubThreadMessage* ThreadMessage);
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
ThreadMessage | UPubnubThreadMessage* | Yes | n/a | ThreadMessage object you want to pin to the selected thread channel. |
Output
Type | Description |
---|---|
UPubnubThreadChannel* | Object returning the thread channel metadata updated with these custom fields: PinnedMessageTimetoken to mark the timetoken when the message was pinned PinnedMessageChannelID to mark the channel on which the message was pinned to the thread channel (unpinning was performed either directly on the parent channel or on a thread channel). |
Basic usage
A thread was created for a message in the support
parent channel. Pin the last message from this thread to the thread 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");
FString Timetoken = "16200000000000001";
// Fetch the message
UPubnubMessage* Message = Channel->GetMessage(Timetoken);
show all 22 linesPin thread message to parent channel
You can pin a selected thread message to the parent channel with ThreadChannel->PinMessageToParentChannel()
and ThreadMessage->PinToParentChannel()
. They give the same output, and the only difference is that you call a given method either on the ThreadChannel
or the ThreadMessage
object. Depending on the object, these methods take different input parameters - you have to specify the thread message you want to pin or not because it's already known.
Method signature
- Blueprint
- C++ / Input parameters
-
ThreadChannel->PinMessageToParentChannel()
ThreadChannel->PinMessageToParentChannel(UPubnubThreadMessage* ThreadMessage);
-
ThreadMessage->PinToParentChannel()
ThreadMessage->PinToParentChannel();
Parameter | Type | Required in ThreadChannel->PinMessageToParentChannel() | Required in ThreadMessage->PinToParentChannel() | Default | Description |
---|---|---|---|---|---|
ThreadMessage | UPubnubThreadMessage* | Yes | No | n/a | ThreadMessage object you want to pin to the selected parent channel. |
Output
Type | Description |
---|---|
UPubnubChannel* | Object returning the channel metadata updated with these custom fields: pinnedMessageTimetoken to mark the timetoken when the message was pinned pinnedMessageChannelID to mark the channel on which the message was pinned to the parent channel (pinning was performed either directly on the parent channel or on a thread channel). |
Basic usage
A thread was created for the last message in the support
parent channel. Pin the last message from this thread to the parent channel.
-
PinMessageToParentChannel()
show all 22 lines#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");
FString Timetoken = "16200000000000001";
// Fetch the message
UPubnubMessage* Message = Channel->GetMessage(Timetoken); -
PinToParentChannel()
show all 21 lines#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");
FString Timetoken = "16200000000000001";
// Fetch the message
UPubnubMessage* Message = Channel->GetMessage(Timetoken);
Unpin thread message from thread channel
UnpinMessage()
called on the ThreadChannel
object unpins the previously pinned thread message from the thread channel.
Method signature
- Blueprint
- C++ / Input parameters
ThreadChannel->UnpinMessageFromThread();
Output
Type | Description |
---|---|
UPubnubThreadChannel* | Object returning the thread channel metadata updated with these custom fields: pinnedMessageTimetoken to mark the timetoken when the message was unpinned pinnedMessageChannelID to mark the channel on which the message was unpinned from the thread channel (unpinning was performed either directly on the parent channel or on a thread channel). |
Basic usage
Unpin the thread message from the thread (channel) created for the last 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");
FString Timetoken = "16200000000000001";
// Fetch the message
UPubnubMessage* Message = Channel->GetMessage(Timetoken);
show all 18 linesUnpin thread message from parent channel
You can unpin the previously pinned thread message from the parent channel with UnpinMessageFromParentChannel()
and UnpinFromParentChannel()
.
Method signature
- Blueprint
- C++ / Input parameters
-
ThreadChannel->UnpinMessageFromParentChannel()
ThreadChannel->UnpinMessageFromParentChannel();
-
ThreadMessage->UnpinFromParentChannel()
ThreadMessage->UnpinFromParentChannel();
Output
Type | Description |
---|---|
UPubnubChannel* | Object returning the channel metadata updated with these custom fields: pinnedMessageTimetoken to mark the timetoken when the message was unpinned pinnedMessageChannelID to mark the channel on which the message was unpinned from the parent channel (unpinning was performed either directly on the parent channel or on a thread channel). |
Basic usage
Unpin the thread message from the support
parent channel.
-
UnpinMessageFromParentChannel()
show all 18 lines#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");
FString Timetoken = "16200000000000001";
// Fetch the message
UPubnubMessage* Message = Channel->GetMessage(Timetoken); -
UnpinFromParentChannel()
show all 22 lines#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");
FString Timetoken = "16200000000000001";
// Fetch the message
UPubnubMessage* Message = Channel->GetMessage(Timetoken);