On this page

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++


Get members

Get all members of a channel with GetMembers().

Method signature

Output

ParameterDescription
FPubnubMembersResponseWrapper
Type: struct
Returned object containing these fields: Page, Total, Status, 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.
 → Status
Type: FString
Status code of a server response, like 200.
 → Memberships
Type: TArray<UPubnubMembership*>
Array of all related memberships.

Sample code

List all members of the support channel on the premium support plan.

1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9UPubnubChannel* Channel = Chat->GetChannel("support");
10
11// Define the filter for members with "premium" support plan
12FString Filter = "custom.support_plan == 'premium'";
13
14// Fetch the members with the filter
15FPubnubMembersResponseWrapper Members = Channel->GetMembers(Filter);

Get membership

Get all channel memberships for a user with GetMemberships().

To list all channels, use GetChannels() instead.

Output

ParameterDescription
FPubnubMembershipsResponseWrapper
Type: struct
Returned object containing these fields: Page, Total, Status, 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.
 → Status
Type: FString
Status code of a server response, like 200.
 → Memberships
Type: TArray<UPubnubMembership*>
Array of all related memberships.

Sample code

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

1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9// Define user ID
10FString UserID = "support_agent_15";
11
12// Get the user and save the reference
13UPubnubUser* User = Chat->GetUser(UserID);
14
15FPubnubMembershipsResponseWrapper Memberships = User->GetMemberships();

Get updates

Receive updates when Membership objects are edited:

  • StreamUpdates() - monitors a single membership
  • StreamUpdatesOn() - monitors multiple memberships
Membership changes

These methods notify about field changes (metadata, status) for existing memberships, not additions or removals.

Both methods accept a callback invoked when membership data changes. They subscribe to a channel and add an objects event listener for membership events, returning an unsubscribe function.

Stream update behavior
  • StreamUpdates() returns the updated Membership object on each change (nullptr if deleted)
  • StreamUpdatesOn() returns the complete list of monitored memberships on any change

Method signature

icon

Handle the response


Output

TypeDescription
UPubnubCallbackStop*
Object on which you can call Stop() to stop receiving updates.

Sample code

Get updates on the first user membership.

  • StreamUpdates()

    1#include "Kismet/GameplayStatics.h"
    2#include "PubnubChatSubsystem.h"
    3
    4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
    5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
    6
    7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
    8
    9// Get the users and save the reference
    10UPubnubUser* User1 = Chat->GetUser("support_agent_15");
    11
    12FPubnubMembershipsResponseWrapper Memberships = User->GetMemberships();
    13
    14UPubnubMembership* Membership = Memberships.Memberships[0];
    15
    show all 22 lines

Get updates on the first page of user memberships.

  • StreamUpdatesOn()

    1#include "Kismet/GameplayStatics.h"
    2#include "PubnubChatSubsystem.h"
    3
    4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
    5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
    6
    7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
    8
    9// Get the users and save the reference
    10UPubnubUser* User1 = Chat->GetUser("support_agent_15");
    11TArray<UPubnubMembership*> Memberships = User->GetMemberships().Memberships;
    12
    13// Create a pubnub response delegate
    14// you MUST implement your own callback function to handle the response
    15FOnPubnubMembershipStreamUpdateReceived MembershipUpdatesOnResponse;
    show all 20 lines

Other examples

Stop listening to updates on the first user membership.

  • StreamUpdates()

    1auto StopUpdates = Membership->StreamUpdates(MembershipUpdatesResponse);
    2
    3StopUpdates->Stop();

Stop listening to updates on the first page of user memberships.

  • StreamUpdatesOn()

    1auto StopUpdates = Membership->StreamUpdatesOn(MembershipUpdatesOnResponse);
    2
    3StopUpdates->Stop();

Update

Update a user's channel membership information with Update().

Method signature

Output

TypeDescription
UPubnubMembership*
Returned (modified) object containing all membership data.

Sample code

Assign the premium-support role to support_agent_15 on the high-priority-incidents channel.

1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9// Define user ID
10FString UserID = "support_agent_15";
11
12// Get the user and save the reference
13UPubnubUser* User = Chat->GetUser(UserID);
14
15// Define user ID
show all 35 lines

Get membership data

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

Method signature

Output

TypeDescription
FPubnubChatMembershipData
The object containing all membership data.

Sample code

1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9// Define user ID
10FString UserID = "support_agent_15";
11
12// Get the user and save the reference
13UPubnubUser* User = Chat->GetUser(UserID);
14
15// Define user ID
show all 31 lines
Last updated on