On this page

Message threads

Organize conversations into threads for topic-specific discussions.

icon

Usage in Blueprints and C++


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

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

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

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

Utility 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:

Properties

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

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

Stream update behavior
  • StreamThreadMessageUpdatesOn() returns the complete list of thread messages you're monitoring each time any change occurs to any of them.

Method signature

icon

Handle the response


Output

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

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:

Output

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

Remove thread

RemoveThread() removes a thread (channel) for a selected message.

Method signature

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 lines

Pin thread message to thread channel

PinMessageToThread() called on the ThreadChannel object pins a selected thread message to the thread channel.

Method signature

Output

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

Pin 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

Output

TypeDescription
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()

    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 lines
  • PinToParentChannel()

    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 21 lines

Unpin thread message from thread channel

UnpinMessage() called on the ThreadChannel object unpins the previously pinned thread message from the thread channel.

Method signature

Output

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

Unpin thread message from parent channel

You can unpin the previously pinned thread message from the parent channel with UnpinMessageFromParentChannel() and UnpinFromParentChannel().

Method signature

Output

TypeDescription
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()

    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 lines
  • UnpinFromParentChannel()

    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 lines
Last updated on