Manage the user-channel membership relation
Requires App Context
Enable App Context for your keyset in the Admin Portal.
A Membership entity is created when a user joins or is invited to a channel, and ends when the user leaves.
Asynchronous and synchronous method execution
Most PubNub Unreal SDK methods are available in both asynchronous and synchronous variants.
-
Asynchronous methods (
Asyncsuffix) returnvoidand take an optional delegate parameter that fires when the operation completes.1Channel->GetMembersAsync(OnGetMembersResponseDelegate);You can also use native callbacks that accept lambdas instead of dynamic delegates. Native callback types have the
Nativesuffix (for example,FOnPubnubChatMembershipsResponseNative). -
Synchronous methods (no suffix) block the main game thread until the operation completes and return a result struct directly.
1FPubnubChatMembershipsResult Result = Channel->GetMembers();
Get members
Get all members of a channel with GetMembers().
Method signature
- Blueprint
- C++ / Input parameters
1Channel->GetMembers(
2 int Limit = 0,
3 FString Filter = "",
4 FPubnubMemberSort Sort = ...,
5 FPubnubPage Page = FPubnubPage()
6);
| Parameter | Description |
|---|---|
LimitType: intDefault: 0 | Number of objects to return in response. The default (and maximum) value is 100. |
FilterType: FStringDefault: "" | Expression used to filter the results. Returns only these channels whose properties satisfy the given expression are returned. The filter language is defined here. |
SortType: FPubnubMemberSortDefault: n/a | Struct used to specify a property to sort by and sort direction. Available options are id, name, and updated. Use asc or desc to specify the sorting direction. By default, the items are sorted by the last updated date. |
PageType: FPubnubPageDefault: FPubnubPage() | Object used for pagination to define which previous or next result page you want to fetch. |
→ NextType: FStringDefault: n/a | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. |
→ PrevType: FStringDefault: n/a | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the Next parameter is supplied. |
Output
| Parameter | Description |
|---|---|
FPubnubChatMembershipsResultType: struct | Returned object containing these fields: Result, Memberships, Page, and Total. |
→ ResultType: FPubnubChatOperationResult | Contains Error and ErrorMessage for operation status. |
→ MembershipsType: TArray<UPubnubChatMembership*> | Array of all related memberships. |
→ PageType: FPubnubPage | Object used for pagination to define which previous or next result page you want to fetch. |
→ NextType: FString | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. |
→ PrevType: FString | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the Next parameter is supplied. |
→ TotalType: int | Total number of channel members. |
Sample code
Reference code
This example is a self-contained code snippet ready to be run. Set up your Unreal project and follow the instructions in the lines marked with ACTION REQUIRED before running the code. Use it as a reference when working with other examples in this document.
Get channel members with user data asynchronously.
Get member
Get a specific channel member by user ID with GetMember().
Method signature
- C++ / Input parameters
- Blueprint
1Channel->GetMember(const FString UserID);
| Parameter | Description |
|---|---|
UserID *Type: FStringDefault: n/a | Unique identifier of the user to retrieve the membership for. |
Output
| Parameter | Description |
|---|---|
FPubnubChatMembershipResultType: struct | Returned object containing Result and Membership. |
→ ResultType: FPubnubChatOperationResult | Contains Error and ErrorMessage for operation status. |
→ MembershipType: UPubnubChatMembership* | Membership of the specified user, or nullptr if they are not a member. |
Sample code
Reference code
This example is a self-contained code snippet ready to be run. Set up your Unreal project and follow the instructions in the lines marked with ACTION REQUIRED before running the code. Use it as a reference when working with other examples in this document.
Get the membership of a user on the current channel.
Actor.h
1
Actor.cpp
1
Check member
Check if a specific user is a member of the channel with HasMember().
Method signature
- C++ / Input parameters
- Blueprint
1Channel->HasMember(const FString UserID);
| Parameter | Description |
|---|---|
UserID *Type: FStringDefault: n/a | Unique identifier of the user to check. |
Output
| Parameter | Description |
|---|---|
FPubnubChatHasMemberResultType: struct | Returned object containing Result and HasMember. |
→ ResultType: FPubnubChatOperationResult | Contains Error and ErrorMessage for operation status. |
→ HasMemberType: bool | true if the user is a member of the channel; false otherwise. |
Sample code
Reference code
This example is a self-contained code snippet ready to be run. Set up your Unreal project and follow the instructions in the lines marked with ACTION REQUIRED before running the code. Use it as a reference when working with other examples in this document.
Check if a user is a member of the current channel.
Actor.h
1
Actor.cpp
1
Get membership
Get all channel memberships for a user with GetMemberships().
To list all channels, use GetChannels() instead.
- C++ / Input parameters
- Blueprint
1User->GetMemberships(
2 const int Limit = 0,
3 const FString Filter = "",
4 FPubnubMembershipSort Sort = FPubnubMembershipSort(),
5 FPubnubPage Page = FPubnubPage()
6);
| Parameter | Description |
|---|---|
LimitType: intDefault: 0 | Number of objects to return in response. Pass 0 to use the server default. |
FilterType: FStringDefault: "" | Expression used to filter the results. Returns only these channels whose properties satisfy the given expression. The filter language is defined here. |
SortType: FPubnubMembershipSortDefault: n/a | Struct defining the property to sort by, and a sort direction. Available options are id, name, and updated. |
PageType: FPubnubPageDefault: n/a | Object used for pagination to define which previous or next result page you want to fetch. |
→ NextType: FStringDefault: n/a | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. |
→ PrevType: FStringDefault: n/a | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the Next parameter is supplied. |
Output
| Parameter | Description |
|---|---|
FPubnubChatMembershipsResultType: struct | Returned object containing these fields: Page, Total, Result, and Memberships. |
→ PageType: FPubnubPage | Object used for pagination to define which previous or next result page you want to fetch. |
→ NextType: FString | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. |
→ PrevType: FString | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the Next parameter is supplied. |
→ TotalType: int | Total number of channel members. |
→ ResultType: FPubnubChatOperationResult | Contains Error and ErrorMessage for operation status. |
→ MembershipsType: TArray<UPubnubChatMembership*> | Array of all related memberships. |
Sample code
Find out which channels the support_agent_15 user is a member of.
- C++
- Blueprint
1
Get single membership
Get a user's membership on a specific channel with GetMembership().
Method signature
- C++ / Input parameters
- Blueprint
1User->GetMembership(const FString ChannelID);
| Parameter | Description |
|---|---|
ChannelID *Type: FStringDefault: n/a | ID of the channel to retrieve the user's membership for. |
Output
| Parameter | Description |
|---|---|
FPubnubChatMembershipResultType: struct | Returned object containing Result and Membership. |
→ ResultType: FPubnubChatOperationResult | Contains Error and ErrorMessage for operation status. |
→ MembershipType: UPubnubChatMembership* | The user's membership on the specified channel, or nullptr if not a member. |
Sample code
Reference code
This example is a self-contained code snippet ready to be run. Set up your Unreal project and follow the instructions in the lines marked with ACTION REQUIRED before running the code. Use it as a reference when working with other examples in this document.
Get the membership of a user on a specific channel.
Actor.h
1
Actor.cpp
1
Check channel membership
Check if a user is a member of a specific channel with IsMemberOn().
Method signature
- C++ / Input parameters
- Blueprint
1User->IsMemberOn(const FString ChannelID);
| Parameter | Description |
|---|---|
ChannelID *Type: FStringDefault: n/a | ID of the channel to check membership on. |
Output
| Parameter | Description |
|---|---|
FPubnubChatIsMemberOnResultType: struct | Returned object containing Result and IsMemberOn. |
→ ResultType: FPubnubChatOperationResult | Contains Error and ErrorMessage for operation status. |
→ IsMemberOnType: bool | true if the user is a member of the specified channel; false otherwise. |
Sample code
Reference code
This example is a self-contained code snippet ready to be run. Set up your Unreal project and follow the instructions in the lines marked with ACTION REQUIRED before running the code. Use it as a reference when working with other examples in this document.
Check if a user is a member of a specific channel.
Actor.h
1
Actor.cpp
1
Get updates
Receive updates when Membership objects are edited or removed:
StreamUpdates()- monitors a single membershipStreamUpdatesOn()- monitors multiple memberships (static method)
Both methods return FPubnubChatOperationResult. Updates are delivered via the membership's OnUpdated delegate (with channel ID, user ID, and data) and deletions via the OnDeleted delegate. Bind these delegates before calling StreamUpdates() or StreamUpdatesOn().
Stream update behavior
-
StreamUpdates()delivers updates via the membership'sOnUpdateddelegate (with channel ID, user ID, and data) and deletions viaOnDeleteddelegate. -
StreamUpdatesOn()delivers updates on any of the monitored memberships via the same delegate pattern. -
To stop receiving updates, call
StopStreamingUpdates()orStopStreamingUpdatesAsync()on the membership.
Method signature
- C++ / Input parameters
- Blueprint
-
StreamUpdates()1Membership->StreamUpdates(); -
StreamUpdatesOn()(static)1UPubnubChatMembership::StreamUpdatesOn(const TArray<UPubnubChatMembership*>& Memberships);
| Parameter | Required in StreamUpdates() | Required in StreamUpdatesOn() | Description |
|---|---|---|---|
MembershipsType: TArray<UPubnubChatMembership*>Default: n/a | No | Yes | Array of Membership objects for which you want to get updates. |
Output
| Type | Description |
|---|---|
FPubnubChatOperationResult | Contains Error (bool) and ErrorMessage (FString). Check Error to determine if the operation succeeded. |
Sample code
Stream updates on a membership and stop when no longer needed.
- C++
- Blueprint
1
Stopping updates
To stop receiving membership updates, call StopStreamingUpdates() or StopStreamingUpdatesAsync() on the membership.
Update
Update a user's channel membership information with Update().
Method signature
- C++ / Input parameters
- Blueprint
1Membership->Update(FPubnubChatUpdateMembershipInputData UpdateMembershipData);
| Type | Description |
|---|---|
FPubnubChatUpdateMembershipInputData | The object containing the membership fields to update. |
FPubnubChatUpdateMembershipInputData
| Parameter | Description |
|---|---|
CustomType: FStringDefault: n/a | JSON custom data associated with the membership. |
StatusType: FStringDefault: n/a | Status of the membership. |
TypeType: FStringDefault: n/a | Type of the membership. |
ForceSetCustomType: boolDefault: false | When true, overwrites the custom data even if empty. |
ForceSetStatusType: boolDefault: false | When true, overwrites the status even if empty. |
ForceSetTypeType: boolDefault: false | When true, overwrites the type even if empty. |
Output
| Type | Description |
|---|---|
FPubnubChatOperationResult | Contains Error (bool) and ErrorMessage (FString). Check Error to determine if the operation succeeded. The membership is updated in place. |
Sample code
Update a membership's status to active.
- C++
- Blueprint
1
Get membership data
GetMembershipData() returns the channel membership data for a given user.
Method signature
- C++ / Input parameters
- Blueprint
1Membership->GetMembershipData();
Output
| Type | Description |
|---|---|
FPubnubChatMembershipData | The object containing all membership data. |
FPubnubChatMembershipData
| Parameter | Description |
|---|---|
CustomType: FString | Custom data associated with the membership. |
StatusType: FString | Status of the membership. |
TypeType: FString | Type of the membership. |
Sample code
Get the membership data for a membership.
- C++
- Blueprint
1
Other examples
These accessors return the user or channel associated with a membership. They are local getters and do not make network calls.
Get user
Get channel
Get user ID
Get channel ID
Delete
Remove a user's channel membership with Delete(). This removes the user from the channel's members on the server.
Method signature
- C++ / Input parameters
- Blueprint
1Membership->Delete();
Output
| Type | Description |
|---|---|
FPubnubChatOperationResult | Contains Error (bool) and ErrorMessage (FString). Check Error to determine if the operation succeeded. |
Sample code
Delete a membership.
- C++
- Blueprint
1