For AI agents: this page in Markdown: https://www.pubnub.com/docs/chat/unity-chat-sdk/learn/chat-entities/membership.md. Documentation index: https://www.pubnub.com/llms-full.txt.
Membership object
Membership represents a single user-channel relationship in a chat.
Properties
Membership has the following properties:
1public class Membership : UniqueChatEntity {
2 public string Id { get; protected set; }
3 public string UserId { get; }
4 public string ChannelId { get; }
5 public string LastReadMessageTimeToken { get; }
6 public ChatMembershipData MembershipData { get; private set; }
7}
Id#- Unique identifier for the membership which is a combination of
UserIdandChannelId. UserId#- The user ID of the user that this membership belongs to.
ChannelId#- The channel ID of the channel that this membership belongs to.
LastReadMessageTimeToken#- The string time token of last read message on the membership channel.
MembershipData#- Contains all the additional data related to the chat membership, including custom data, status, and type.
ChatMembershipData
The ChatMembershipData object contains the following properties:
API limits
To learn about the maximum length of parameters used to set channel membership metadata, refer to REST API docs.
Events
The Membership object has the following events:
1// Event triggered when user-channel membership is updated.
2// Call StreamUpdates(true) to enable this callback.
3public event Action<Membership> OnUpdated;
4// Event triggered when the membership is hard-deleted from App Context.
5// Call StreamUpdates(true) to enable this callback.
6public event Action OnDeleted;
Example
An event that is triggered when user-channel membership is updated by the server.
1
Methods
You can call the following methods on the Membership object.
Click on each method for more details.
Standard methods
Delete()GetUnreadMessagesCount()LastReadMessageTimeTokenSetLastReadMessage()SetLastReadMessageTimeToken()Update()
Streaming methods
These methods register or unregister real-time event subscriptions. Each streaming method activates one or more of the events listed in the Events section above.
Use case
Membership methods enable:
- Updating user-channel relationships and getting updates on changes
- Deleting user-channel relationships
- Tracking the last message read by a user on a channel
- Getting the count of unread messages for a user