Pinned messages
Pin messages to channels for easy access. Only one message can be pinned per channel at a time.
Use cases:
- Essential announcements and updates
- Action items and reminders
- Polls and persistent questions
Requires App Context and Message Persistence
Enable App Context and Message Persistence in the Admin Portal.
Pin
Pin() and PinMessage() attach a message to the channel.
Both of these methods give the same result. The only difference between them is that you may or may not be required to provide input parameters, and you call them on different objects: message (Pin()) or channel (PinMessage()).
Alternatively, you can also use other Unity Chat SDK methods to pin a message in a thread (thread message) to the thread channel or the parent channel.
Method signature
These methods take the following parameters:
-
Pin()1message.Pin() -
PinMessage()1channel.PinMessage(Message message)
Input
message#Messageobject that you want to pin to the selected channel.- Required in Pin()
- No
- Required in PinMessage()
- Yes
Output
An awaitable Task<ChatOperationResult>.
Sample code
Pin the last message on the incident-management channel.
-
Pin()
show all 54 lines1using System;
2using System.Linq;
3using System.Threading.Tasks;
4using PubnubApi;
5using PubnubChatApi;
6using UnityEngine;
7
8// Configuration
9PubnubChatConfig chatConfig = new PubnubChatConfig();
10
11PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
12{
13 SubscribeKey = "demo",
14 PublishKey = "demo",
15 Secure = true -
PinMessage()
show all 54 lines1using System;
2using System.Linq;
3using System.Threading.Tasks;
4using PubnubApi;
5using PubnubChatApi;
6using UnityEngine;
7
8// Configuration
9PubnubChatConfig chatConfig = new PubnubChatConfig();
10
11PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
12{
13 SubscribeKey = "demo",
14 PublishKey = "demo",
15 Secure = true
Get
GetPinnedMessage() fetches the message that is currently pinned to the channel.
Method signature
1channel.GetPinnedMessage()
Input
This method doesn't take any parameters.
Output
Task<ChatOperationResult<Message>>#- An awaitable
Taskwith theMessageobject if a pinned message exists, otherwise theErrorproperty on the result will betrue.
Sample code
Get the message pinned to the incident-management channel.
1using System;
2using System.Linq;
3using System.Threading.Tasks;
4using PubnubApi;
5using PubnubChatApi;
6using UnityEngine;
7
8// Configuration
9PubnubChatConfig chatConfig = new PubnubChatConfig();
10
11PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
12{
13 SubscribeKey = "demo",
14 PublishKey = "demo",
15 Secure = true
show all 43 linesUnpin
UnpinMessage() unpins a message from the channel.
Alternatively, you can also use other Unity Chat SDK methods to unpin a message in a thread (thread message) from the thread channel or the parent channel.
Method signature
This method has the following signature:
1channel.UnpinMessage()
Input
This method doesn't take any parameters.
Output
An awaitable Task<ChatOperationResult>.
Sample code
Unpin the message from the incident-management channel.
1using System;
2using System.Linq;
3using System.Threading.Tasks;
4using PubnubApi;
5using PubnubChatApi;
6using UnityEngine;
7
8// Configuration
9PubnubChatConfig chatConfig = new PubnubChatConfig();
10
11PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
12{
13 SubscribeKey = "demo",
14 PublishKey = "demo",
15 Secure = true
show all 45 lines