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.

icon

Usage in Blueprints and C++


Asynchronous and synchronous method execution

Most PubNub Unreal SDK methods are available in both asynchronous and synchronous variants.

  • Asynchronous methods (Async suffix) return void and 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 Native suffix (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​

Output​

ParameterDescription
FPubnubChatMembershipsResult
Type: struct
Returned object containing these fields: Result, Memberships, Page, and Total.
> Result
Type: FPubnubChatOperationResult
Contains Error and ErrorMessage for operation status.
> Memberships
Type: TArray<UPubnubChatMembership*>
Array of all related memberships.
> Page
Type: FPubnubPage
Object used for pagination to define which previous or next result page you want to fetch.
>> Next
Type: 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.
>> Prev
Type: 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.
> Total
Type: 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.

Actor.h​
1

Actor.cpp​
1

Get member​

Get a specific channel member by user ID with GetMember().

Method signature​

1Channel->GetMember(const FString UserID);
* required
ParameterDescription
UserID *
Type: FString
Default:
n/a
Unique identifier of the user to retrieve the membership for.

Output​

ParameterDescription
FPubnubChatMembershipResult
Type: struct
Returned object containing Result and Membership.
> Result
Type: FPubnubChatOperationResult
Contains Error and ErrorMessage for operation status.
> Membership
Type: 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​

1Channel->HasMember(const FString UserID);
* required
ParameterDescription
UserID *
Type: FString
Default:
n/a
Unique identifier of the user to check.

Output​

ParameterDescription
FPubnubChatHasMemberResult
Type: struct
Returned object containing Result and HasMember.
> Result
Type: FPubnubChatOperationResult
Contains Error and ErrorMessage for operation status.
> HasMember
Type: 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.

1User->GetMemberships(
2 const int Limit = 0,
3 const FString Filter = "",
4 FPubnubMembershipSort Sort = FPubnubMembershipSort(),
5 FPubnubPage Page = FPubnubPage()
6);
* required
ParameterDescription
Limit
Type: int
Default:
0
Number of objects to return in response. Pass 0 to use the server default.
Filter
Type: FString
Default:
""
Expression used to filter the results. Returns only these channels whose properties satisfy the given expression. The filter language is defined here.
Sort
Type: FPubnubMembershipSort
Default:
n/a
Struct defining the property to sort by, and a sort direction. Available options are id, name, and updated.
Page
Type: FPubnubPage
Default:
n/a
Object used for pagination to define which previous or next result page you want to fetch.
> Next
Type: FString
Default:
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.
> Prev
Type: FString
Default:
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​

ParameterDescription
FPubnubChatMembershipsResult
Type: struct
Returned object containing these fields: Page, Total, Result, and Memberships.
> Page
Type: FPubnubPage
Object used for pagination to define which previous or next result page you want to fetch.
>> Next
Type: 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.
>> Prev
Type: 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.
> Total
Type: int
Total number of channel members.
> Result
Type: FPubnubChatOperationResult
Contains Error and ErrorMessage for operation status.
> Memberships
Type: TArray<UPubnubChatMembership*>
Array of all related memberships.

Sample code​

Find out which channels the support_agent_15 user is a member of.

1

Get single membership​

Get a user's membership on a specific channel with GetMembership().

Method signature​

1User->GetMembership(const FString ChannelID);
* required
ParameterDescription
ChannelID *
Type: FString
Default:
n/a
ID of the channel to retrieve the user's membership for.

Output​

ParameterDescription
FPubnubChatMembershipResult
Type: struct
Returned object containing Result and Membership.
> Result
Type: FPubnubChatOperationResult
Contains Error and ErrorMessage for operation status.
> Membership
Type: 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​

1User->IsMemberOn(const FString ChannelID);
* required
ParameterDescription
ChannelID *
Type: FString
Default:
n/a
ID of the channel to check membership on.

Output​

ParameterDescription
FPubnubChatIsMemberOnResult
Type: struct
Returned object containing Result and IsMemberOn.
> Result
Type: FPubnubChatOperationResult
Contains Error and ErrorMessage for operation status.
> IsMemberOn
Type: 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 membership
  • StreamUpdatesOn() - 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's OnUpdated delegate (with channel ID, user ID, and data) and deletions via OnDeleted delegate.

  • StreamUpdatesOn() delivers updates on any of the monitored memberships via the same delegate pattern.

  • To stop receiving updates, call StopStreamingUpdates() or StopStreamingUpdatesAsync() on the membership.

Method signature​

  • StreamUpdates()

    1Membership->StreamUpdates();
  • StreamUpdatesOn() (static)

    1UPubnubChatMembership::StreamUpdatesOn(const TArray<UPubnubChatMembership*>& Memberships);
ParameterRequired in StreamUpdates()Required in StreamUpdatesOn()Description
Memberships
Type: TArray<UPubnubChatMembership*>
Default:
n/a
NoYesArray of Membership objects for which you want to get updates.

Output​

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

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​

1Membership->Update(FPubnubChatUpdateMembershipInputData UpdateMembershipData);
TypeDescription
FPubnubChatUpdateMembershipInputDataThe object containing the membership fields to update.
FPubnubChatUpdateMembershipInputData​
* required
ParameterDescription
Custom
Type: FString
Default:
n/a
JSON custom data associated with the membership.
Status
Type: FString
Default:
n/a
Status of the membership.
Type
Type: FString
Default:
n/a
Type of the membership.
ForceSetCustom
Type: bool
Default:
false
When true, overwrites the custom data even if empty.
ForceSetStatus
Type: bool
Default:
false
When true, overwrites the status even if empty.
ForceSetType
Type: bool
Default:
false
When true, overwrites the type even if empty.

Output​

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

1

Get membership data​

GetMembershipData() returns the channel membership data for a given user.

Method signature​

1Membership->GetMembershipData();

Output​

TypeDescription
FPubnubChatMembershipDataThe object containing all membership data.
FPubnubChatMembershipData​
ParameterDescription
Custom
Type: FString
Custom data associated with the membership.
Status
Type: FString
Status of the membership.
Type
Type: FString
Type of the membership.

Sample code​

Get the membership data for a membership.

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​

1Membership->Delete();

Output​

TypeDescription
FPubnubChatOperationResultContains Error (bool) and ErrorMessage (FString). Check Error to determine if the operation succeeded.

Sample code​

Delete a membership.

1

Was this page useful?

Last updated on