Message threads
Organize conversations into threads for topic-specific discussions.
Asynchronous and synchronous method execution
Most PubNub Unreal SDK methods are available in both asynchronous and synchronous variants.
-
Asynchronous methods (
Asyncsuffix) returnvoidand take an optional delegate parameter that fires when the operation completes.1Message->CreateThreadAsync(OnCreateThreadResponseDelegate);You can also use native callbacks that accept lambdas instead of dynamic delegates. Native callback types have the
Nativesuffix (for example,FOnPubnubChatThreadChannelResponseNative). -
Synchronous methods (no suffix) block the main game thread until the operation completes and return a result struct directly.
1FPubnubChatThreadChannelResult Result = Message->CreateThread();
Benefits:
- Focus discussions on specific topics
- Clarify and resolve issues without cross-talk
- Keep main channel conversations clean
Thread channels have IDs starting with PUBNUB_INTERNAL_THREAD_{channel_id}_{message_id}. Messages with threads have HasThread: true.
ThreadMessage and ThreadChannel extend the base message and channel entities with thread-specific methods.
Create thread
CreateThread() creates a thread (channel) for a selected message.
Method signature
- Blueprint
- C++ / Input parameters
1Message->CreateThread();
Output
| Field | Type | Description |
|---|---|---|
Result | FPubnubChatOperationResult | Operation result with Error (bool) and ErrorMessage (FString). |
ThreadChannel | UPubnubChatThreadChannel* | Object returning the thread channel metadata for the message updated with the hasThread parameter (and a threadRootId action type underneath). |
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.
Create a thread for a message asynchronously.
Other examples
Create thread channel from Chat object
Actor.h
1
Actor.cpp
1
Send 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
1Message->GetThread();
Output
| Field | Type | Description |
|---|---|---|
Result | FPubnubChatOperationResult | Operation result with Error (bool) and ErrorMessage (FString). |
ThreadChannel | UPubnubChatThreadChannel* | Object returning the thread channel metadata. |
Sample code
Get the thread channel created from a message.
- C++
- Blueprint
1
Other examples
Get thread channel from Chat object
Actor.h
1
Actor.cpp
1
Utility getter function
You can use the HasThread() method to check if a given message starts a thread.
Method signature
- Blueprint
- C++ / Input parameters
1Message->HasThread();
Output
| Field | Type | Description |
|---|---|---|
Result | FPubnubChatOperationResult | Operation result with Error (bool) and ErrorMessage (FString). |
HasThread | bool | Info on whether the message already starts a thread or not. |
Sample code
Check if a message starts a thread.
- C++
- Blueprint
1
Get parent channel ID (ThreadChannel)
Get parent message
Get parent channel ID (ThreadMessage)
Get thread updates
You can receive updates when specific thread messages and related message reactions are added, edited, or removed on other clients. Thread messages use the same streaming mechanism as regular messages.
Bind each thread message's OnUpdated delegate before calling StreamUpdates(), then call StopStreamingUpdates() to stop. Use StreamUpdatesOn() to start streaming for multiple thread messages at once.
Stream update behavior
Each thread message fires its own OnUpdated delegate individually with (FString Timetoken, FPubnubChatMessageData MessageData).
Method signature
1ThreadMessage->StreamUpdates();
2UPubnubChatMessage::StreamUpdatesOn(TArray<UPubnubChatMessage*> Messages);
3ThreadMessage->StopStreamingUpdates();
Output
| Type | Description |
|---|---|
FPubnubChatOperationResult | Result of the operation. Check Error for failure. |
Sample code
info
The following sample demonstrates how to listen for new thread messages (replies) using Connect()/Disconnect(), which is a related but distinct operation from StreamUpdates(). StreamUpdates() streams changes to existing messages (edits, reactions, deletions), while Connect() receives new messages posted to the thread.
Listen for new thread messages on a thread channel.
- C++
- Blueprint
1
OnThreadMessageReceived delegate
When a ThreadChannel is connected (via Connect()), incoming thread messages are delivered through the OnThreadMessageReceived delegate. Always bind OnThreadMessageReceived (type FOnPubnubChatThreadMessageReceived, parameter UPubnubChatThreadMessage*) before calling Connect() to handle new replies.
| Delegate | Type | Payload |
|---|---|---|
OnThreadMessageReceived | FOnPubnubChatThreadMessageReceived | UPubnubChatThreadMessage* -- the received thread message object. |
1ThreadChannel->OnThreadMessageReceived.AddDynamic(this, &AMyActor::OnNewThreadMessage);
2
3ThreadChannel->Connect();
4
5// To stop receiving:
6// ThreadChannel->Disconnect();
Get 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:
1ThreadChannel->GetThreadHistory(
2 FString StartTimetoken,
3 FString EndTimetoken,
4 int Count = 25
5);
| Parameter | Description |
|---|---|
StartTimetokenType: FStringDefault: n/a | Start timetoken (inclusive) for the history range. Must be higher (newer) than EndTimetoken. |
EndTimetokenType: FStringDefault: n/a | End timetoken (inclusive) for the history range. Must be lower (older) than StartTimetoken. |
CountType: intDefault: 25 | Maximum number of historical thread messages to return in a single call. |
Output
| Field | Type | Description |
|---|---|---|
Result | FPubnubChatOperationResult | Operation result with Error (bool) and ErrorMessage (FString). |
ThreadMessages | TArray<UPubnubChatThreadMessage*> | Array of historical thread Message objects. |
IsMore | bool | true when the returned count equals Count, indicating more messages may exist in the range. |
By default, each call returns all message reactions and metadata attached to the retrieved thread messages.
Sample code
From the thread created for a message in the support channel, fetch historical thread messages.
1
Remove thread
RemoveThread() removes a thread (channel) for a selected message.
Method signature
- Blueprint
- C++ / Input parameters
1Message->RemoveThread();
Output
| Type | Description |
|---|---|
FPubnubChatOperationResult | Result of the operation. Check Error and ErrorMessage for failure. |
Sample code
Remove a thread for a message.
- C++
- Blueprint
1
Other examples
Remove thread channel from Chat object
Actor.h
1
Actor.cpp
1
Pin thread message to parent channel
You can pin a selected thread message to the parent channel with ThreadChannel->PinMessageToParentChannel() and ThreadMessage->PinMessageToParentChannel(). 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()1ThreadChannel->PinMessageToParentChannel(UPubnubChatThreadMessage* ThreadMessage); -
ThreadMessage->PinMessageToParentChannel()1ThreadMessage->PinMessageToParentChannel();
| Parameter | Required in ThreadChannel->PinMessageToParentChannel() | Required in ThreadMessage->PinMessageToParentChannel() | Description |
|---|---|---|---|
ThreadMessageType: UPubnubChatThreadMessage*Default: n/a | Yes | No | ThreadMessage object you want to pin to the selected parent channel. |
Output
| Type | Description |
|---|---|
FPubnubChatOperationResult | Result of the operation. Check Error and ErrorMessage for failure. |
Sample code
Pin a thread message to the parent channel.
- C++
- Blueprint
1
Other examples
Pin thread message to parent channel from ThreadMessage
Actor.h
1
Actor.cpp
1
Unpin thread message from parent channel
You can unpin the previously pinned thread message from the parent channel with ThreadChannel->UnpinMessageFromParentChannel() and ThreadMessage->UnpinMessageFromParentChannel().
Method signature
- Blueprint
- C++ / Input parameters
-
ThreadChannel->UnpinMessageFromParentChannel()1ThreadChannel->UnpinMessageFromParentChannel(); -
ThreadMessage->UnpinMessageFromParentChannel()1ThreadMessage->UnpinMessageFromParentChannel();
Output
| Type | Description |
|---|---|
FPubnubChatOperationResult | Result of the operation. Check Error and ErrorMessage for failure. |
Sample code
Unpin the thread message from the parent channel.
- C++
- Blueprint
1
Other examples
Unpin thread message from parent channel from ThreadMessage
Actor.h
1
Actor.cpp
1