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
1Message->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). |
Sample code
Create a thread for the last message on the support channel.
1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9UPubnubChannel* Channel = Chat->GetChannel("support");
10
11FString Timetoken = "16200000000000001";
12
13// Fetch the message
14UPubnubMessage* Message = Channel->GetMessage(Timetoken);
15
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
1Message->GetThread();
Output
| Type | Description |
|---|---|
UPubnubThreadChannel* | Object returning the thread channel metadata. |
Sample code
Get the thread channel created from the message with the 16200000000000001 timetoken.
1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9UPubnubChannel* Channel = Chat->GetChannel("support");
10
11FString Timetoken = "16200000000000001";
12
13// Fetch the message
14UPubnubMessage* Message = Channel->GetMessage(Timetoken);
15
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
1Message->HasThread();
Properties
| Type | Description |
|---|---|
bool | Info on whether the message already starts a thread or not. |
Sample code
Check if the message with the 16200000000000001 timetoken starts a thread.
1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9UPubnubChannel* Channel = Chat->GetChannel("support");
10
11FString Timetoken = "16200000000000001";
12
13// Fetch the message
14UPubnubMessage* Message = Channel->GetMessage(Timetoken);
15
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 actions 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
1ThreadMessage->StreamThreadMessageUpdatesOn(
2 TArray<UPubnubThreadMessage*> Messages,
3 FOnPubnubThreadMessagesStreamUpdateOnReceived MessageUpdateCallback
4);
| Parameter | Description |
|---|---|
Messages *Type: TArray<UPubnubThreadMessage*>Default: n/a | Array of ThreadMessage objects for which you want to get updates on changed message threads or related message reactions. |
MessageUpdateCallback *Type: FOnPubnubThreadMessagesStreamUpdateOnReceivedDefault: 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. |
Sample code
Get message threads and message reaction-related updates for messages published in a thread on the support channel.
1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9// Create a pubnub response delegate
10// you MUST implement your own callback function to handle the response
11FOnPubnubThreadMessagesStreamUpdateOnReceived ThreadUpdatesOnResponse;
12ThreadUpdatesOnResponse.BindDynamic(this, &AMyActor::OnThreadUpdatesResponseReceived);
13
14UPubnubChannel* Channel = Chat->GetChannel("support");
15
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
1ThreadChannel->GetThreadHistory(
2 int Limit,
3 FString Start,
4 FString End
5);
| Parameter | Description |
|---|---|
LimitType: intDefault: 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. |
StartType: FStringDefault: n/a | Timetoken delimiting the start of a time slice (exclusive) to pull thread messages from. |
EndType: FStringDefault: 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.
Sample code
From the thread created for a message in the support channel, fetch 10 historical thread messages that are older than the timetoken 15343325214676133.
1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9UPubnubChannel* Channel = Chat->GetChannel("support");
10
11FString Timetoken = "16200000000000001";
12
13// Fetch the message
14UPubnubMessage* Message = Channel->GetMessage(Timetoken);
15
show all 18 linesRemove thread
RemoveThread() removes a thread (channel) for a selected message.
Method signature
- Blueprint
- C++ / Input parameters
1Message->RemoveThread();
Output
This method doesn't return any value.
Sample code
Remove a thread for a message on the support channel.
1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9UPubnubChannel* Channel = Chat->GetChannel("support");
10
11FString Timetoken = "16200000000000001";
12
13// Fetch the message
14UPubnubMessage* Message = Channel->GetMessage(Timetoken);
15
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
1ThreadChannel->PinMessageToThread(UPubnubThreadMessage* ThreadMessage);
| Parameter | Description |
|---|---|
ThreadMessage *Type: UPubnubThreadMessage*Default: 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). |
Sample code
A thread was created for a message in the support parent channel. Pin the last message from this thread to the thread channel.
1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9UPubnubChannel* Channel = Chat->GetChannel("support");
10
11FString Timetoken = "16200000000000001";
12
13// Fetch the message
14UPubnubMessage* Message = Channel->GetMessage(Timetoken);
15
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()1ThreadChannel->PinMessageToParentChannel(UPubnubThreadMessage* ThreadMessage); -
ThreadMessage->PinToParentChannel()1ThreadMessage->PinToParentChannel();
| Parameter | Required in ThreadChannel->PinMessageToParentChannel() | Required in ThreadMessage->PinToParentChannel() | Description |
|---|---|---|---|
ThreadMessageType: UPubnubThreadMessage*Default: n/a | Yes | No | 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). |
Sample code
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 lines1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9UPubnubChannel* Channel = Chat->GetChannel("support");
10
11FString Timetoken = "16200000000000001";
12
13// Fetch the message
14UPubnubMessage* Message = Channel->GetMessage(Timetoken);
15 -
PinToParentChannel()
show all 21 lines1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9UPubnubChannel* Channel = Chat->GetChannel("support");
10
11FString Timetoken = "16200000000000001";
12
13// Fetch the message
14UPubnubMessage* Message = Channel->GetMessage(Timetoken);
15
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
1ThreadChannel->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). |
Sample code
Unpin the thread message from the thread (channel) created for the last message on the support channel.
1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9UPubnubChannel* Channel = Chat->GetChannel("support");
10
11FString Timetoken = "16200000000000001";
12
13// Fetch the message
14UPubnubMessage* Message = Channel->GetMessage(Timetoken);
15
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()1ThreadChannel->UnpinMessageFromParentChannel(); -
ThreadMessage->UnpinFromParentChannel()1ThreadMessage->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). |
Sample code
Unpin the thread message from the support parent channel.
-
UnpinMessageFromParentChannel()
show all 18 lines1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9UPubnubChannel* Channel = Chat->GetChannel("support");
10
11FString Timetoken = "16200000000000001";
12
13// Fetch the message
14UPubnubMessage* Message = Channel->GetMessage(Timetoken);
15 -
UnpinFromParentChannel()
show all 22 lines1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9UPubnubChannel* Channel = Chat->GetChannel("support");
10
11FString Timetoken = "16200000000000001";
12
13// Fetch the message
14UPubnubMessage* Message = Channel->GetMessage(Timetoken);
15