Message threads

The message threads feature organizes conversations into threads, making it easier to follow and respond to specific topics.

icon

Usage in Blueprints and C++


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

Output

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

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 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
boolInfo 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 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 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

icon

Handle the response


Output

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

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 lines

Remove thread

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

Method signature

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

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

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

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

    #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 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).

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

Basic usage

Unpin the thread message from the support parent channel.

  • UnpinMessageFromParentChannel()

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

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