Manage the user-channel membership relation

When a user joins a channel or gets invited to it, a membership relation between that user and the channel is created (Membership entity). The membership ends when this user leaves the channel.

icon

Usage in Blueprints and C++


Requires App Context

To set up and manage channel membership, you must enable App Context for your app's keyset in the Admin Portal.

Read on to learn how to check and update user-channel membership.

Get members

GetMembers() returns the list of all channel members.

Method signature

Output

ParameterTypeDescription
FPubnubMembersResponseWrapperstructReturned object containing these fields: Page, Total, Status, and Memberships.
 → PageFPubnubPageObject used for pagination to define which previous or next result page you want to fetch.
   → NextFStringRandom 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.
   → PrevFStringRandom 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.
 → TotalintTotal number of channel members.
 → StatusFStringStatus code of a server response, like 200.
 → MembershipsTArray<UPubnubMembership*>Array of all related memberships.

Basic usage

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

#include "Kismet/GameplayStatics.h"
#include "PubnubChatSubsystem.h"

UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();

UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");

UPubnubChannel* Channel = Chat->GetChannel("support");

// Define the filter for members with "premium" support plan
FString Filter = "custom.support_plan == 'premium'";

// Fetch the members with the filter
FPubnubMembersResponseWrapper Members = Channel->GetMembers(Filter);

Get membership

GetMemberships() returns the list of all channel memberships of a given user.

To get a list of all existing channels, use the GetChannels() method.

Output

ParameterTypeDescription
FPubnubMembershipsResponseWrapperstructReturned object containing these fields: Page, Total, Status, and Memberships.
 → PageFPubnubPageObject used for pagination to define which previous or next result page you want to fetch.
   → NextFStringRandom 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.
   → PrevFStringRandom 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.
 → TotalintTotal number of channel members.
 → StatusFStringStatus code of a server response, like 200.
 → MembershipsTArray<UPubnubMembership*>Array of all related memberships.

Basic usage

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

#include "Kismet/GameplayStatics.h"
#include "PubnubChatSubsystem.h"

UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();

UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");

// Define user ID
FString UserID = "support_agent_15";

// Get the user and save the reference
UPubnubUser* User = Chat->GetUser(UserID);

FPubnubMembershipsResponseWrapper Memberships = User->GetMemberships();

Get updates

You can receive updates when specific user-channel Membership object(s) are added, edited, or removed using the following methods:

  • StreamUpdates() checks updates on a single Membership object.
  • StreamUpdatesOn() checks updates on a list of Membership objects.

Both methods accept a callback function as an argument. The Unreal Chat SDK invokes this callback whenever someone adds, changes, or removes membership data.

Underneath, these methods subscribe the current user to a channel and add an objects event listener to receive all objects events of type membership. These methods also return the unsubscribe function you can invoke to stop receiving objects events and unsubscribe from the channel.

Method signature

icon

Handle the response


Output

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

Basic usage

Get updates on the first user membership.

  • StreamUpdates()

    #include "Kismet/GameplayStatics.h"
    #include "PubnubChatSubsystem.h"

    UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
    UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();

    UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");

    // Get the users and save the reference
    UPubnubUser* User1 = Chat->GetUser("support_agent_15");

    FPubnubMembershipsResponseWrapper Memberships = User->GetMemberships();

    UPubnubMembership* Membership = Memberships.Memberships[0];

    show all 21 lines

Get updates on the first page of user memberships.

  • StreamUpdatesOn()

    #include "Kismet/GameplayStatics.h"
    #include "PubnubChatSubsystem.h"

    UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
    UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();

    UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");

    // Get the users and save the reference
    UPubnubUser* User1 = Chat->GetUser("support_agent_15");
    TArray<UPubnubMembership*> Memberships = User->GetMemberships().Memberships;

    // Create a pubnub response delegate
    // you MUST implement your own callback function to handle the response
    FOnPubnubMembershipStreamUpdateReceived MembershipUpdatesOnResponse;
    show all 18 lines

Other examples

Stop listening to updates on the first user membership.

  • StreamUpdates()

    auto StopUpdates = Membership->StreamUpdates(MembershipUpdatesResponse);

    StopUpdates->Stop();

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

  • StreamUpdatesOn()

    auto StopUpdates = Membership->StreamUpdatesOn(MembershipUpdatesOnResponse);

    StopUpdates->Stop();

Update

Update() updates the channel membership information for a given user.

Method signature

Output

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

Basic usage

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

#include "Kismet/GameplayStatics.h"
#include "PubnubChatSubsystem.h"

UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();

UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");

// Define user ID
FString UserID = "support_agent_15";

// Get the user and save the reference
UPubnubUser* User = Chat->GetUser(UserID);

// Define user ID
show all 35 lines
Last updated on