On this page

Message threads

Organize conversations into threads for topic-specific discussions.

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->CreateThreadAsync(OnCreateThreadResponseDelegate);

    You can also use native callbacks that accept lambdas instead of dynamic delegates. Native callback types have the Native suffix (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

Output

FieldTypeDescription
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.

Actor.h
1

Actor.cpp
1

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

Output

FieldTypeDescription
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.

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

Output

FieldTypeDescription
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.

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

TypeDescription
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.

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.

DelegateTypePayload
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);
* required
ParameterDescription
StartTimetoken
Type: FString
Default:
n/a
Start timetoken (inclusive) for the history range. Must be higher (newer) than EndTimetoken.
EndTimetoken
Type: FString
Default:
n/a
End timetoken (inclusive) for the history range. Must be lower (older) than StartTimetoken.
Count
Type: int
Default:
25
Maximum number of historical thread messages to return in a single call.

Output

FieldTypeDescription
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

Output

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

Sample code

Remove a thread for a message.

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

Output

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

Sample code

Pin a thread message to the parent channel.

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

Output

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

Sample code

Unpin the thread message from the parent channel.

1

Other examples

Unpin thread message from parent channel from ThreadMessage

Actor.h
1

Actor.cpp
1

Last updated on