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 Unity 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 Unity 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
This method has the following signature:
1message.CreateThread()
Input
This method doesn't take any parameters.
Output
| Type | Description |
|---|---|
ChatOperationResult<ThreadChannel> | An awaitable Task with the created ThreadChannel object. |
Sample code
Create a thread for the last message on the support channel.
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.
Sample code
Send a message in a thread created for the last message on the support channel.
1
Get thread
Get the thread channel on which the thread message is published using one of these methods:
GetThread()called on theMessageobjectGetThreadChannel()called on theChatobject.
Method signature
Method signature
These methods take the following parameters:
-
GetThread()1message.GetThread() -
GetThreadChannel()1chat.GetThreadChannel(Message message)
Input
| Parameter | Required in GetThread() | Required in GetThreadChannel() | Description |
|---|---|---|---|
messageType: MessageDefault: n/a | No | Yes | Message object for which you want to get the related thread channel. |
Output
An awaitable Task<ChatOperationResult<ThreadChannel>> with the fetched ThreadChannel object or an error if one wasn't found.
Sample code
Get the thread channel created from the message with the 16200000000000001 timetoken.
-
GetThread()1 -
GetThreadChannel()1
Check if message starts thread
You can use the HasThread() method to check if a given message starts a thread.
Method signature
This method has the following signature:
1message.HasThread()
Properties
This method doesn't take any parameters.
Output
| Type | Description |
|---|---|
bool | Specifies if the message has started a thread (true) or not (false). |
Sample code
Check if the message with the 16200000000000001 timetoken starts a thread.
1
Get thread channel updates
You can receive updates when specific thread channels are edited or removed on other clients.
Method signature
Head over to OnChannelUpdate section for details.
Sample code
Get updates for the thread channel created from the message with the 16200000000000001 timetoken.
1
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 string startTimeToken,
3 string endTimeToken,
4 int count
5)
Input
| Parameter | Description |
|---|---|
startTimetoken *Type: stringDefault: n/a | Timetoken delimiting the start of a time slice (exclusive) to pull thread messages from. For details, refer to the Fetch History section. |
endTimetoken *Type: stringDefault: n/a | Timetoken delimiting the end of a time slice (inclusive) to pull messages from. For details, refer to the Fetch History section. |
count *Type: intDefault: 25 | Number of historical 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 messages is 25. For more details, refer to the description of the IncludeMessageActions parameter in the Unity SDK docs. |
Output
This method returns an awaitable Task<ChatOperationResult<List<ThreadMessage>>> with thread messages sent within the given timeframe.
By default, each call returns all message reactions and metadata attached to the retrieved thread messages.
Sample code
From the thread created for the last message in the support channel, fetch 10 historical thread messages that are older than the timetoken 15343325214676133.
1
Remove thread
RemoveThread() removes a thread channel for a selected message.
Method signature
This method has the following signature:
1message.RemoveThread()
Input
This method doesn't take any parameters.
Output
An awaitable Task.
Sample code
Remove a thread for the last message on the support channel.
1
Pin thread message to thread channel
To pin a selected thread message to the thread channel, use the PinMessage() method.
This method is available on the Channel object, but you can call it from the ThreadChannel object as ThreadChannel inherits all public methods from the Channel object.
Method signature
Head over to the PinMessage() section for details.
Sample code
A thread was created for the last message in the support parent channel. Pin the last message from this thread to the thread channel.
1
Pin thread message to parent channel
You can pin a selected thread message to the parent channel with PinMessageToParentChannel() methods. 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
These methods take the following parameters:
-
PinMessageToParentChannel()(onthreadChannelobject)1threadChannel.PinMessageToParentChannel(Message message) -
PinMessageToParentChannel()(onthreadMessageobject)1threadMessage.PinMessageToParentChannel()
Input
| Parameter | Required in the threadChannel object method | Required in the threadMessage object method | Description |
|---|---|---|---|
messageType: MessageDefault: n/a | Yes | No | Message object you want to pin to the selected parent channel. |
Output
An awaitable Task.
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.
1
Unpin thread message from thread channel
To unpin a selected thread message from the thread channel, use the UnpinMessage() method.
This method is available on the Channel object, but you can call it from the ThreadChannel object as ThreadChannel inherits all public methods from the Channel object.
Method signature
Head over to the UnpinMessage() section for details.
Sample code
Unpin the thread message from the thread (channel) created for the last message on the support channel.
1
Unpin thread message from parent channel
You can unpin the previously pinned thread message from the parent channel with UnpinMessageFromParentChannel() methods. They give the same output, and the only difference is that you call a given method either on the ThreadChannel or the ThreadMessage object.
Method signature
These methods have the following signatures:
-
UnpinMessageFromParentChannel()(on thethreadChannelobject)1threadChannel.UnPinMessageFromParentChannel() -
UnpinMessageFromParentChannel()(on thethreadMessageobject)1threadMessage.UnPinMessageFromParentChannel()
Input
These methods don't take any parameters.
Output
An awaitable Task.
Sample code
Unpin the thread message from the support parent channel.
1