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.
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
- Blueprint
- C++ / Input parameters
Channel->GetMembers(
FString Filter = "",
FString Sort = "",
int Limit = 0,
FPubnubPage Page = FPubnubPage()
);
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
Filter | FString | No | n/a | Expression used to filter the results. Returns only these channels whose properties satisfy the given expression are returned. The filter language is defined here. |
Sort | FString | No | n/a | Key-value pair of a property to sort by, and a sort direction. Available options are id , name , and updated . Use asc or desc to specify the sorting direction, or specify null to take the default sorting direction (ascending). For example: {name: "asc"} . By default, the items are sorted by the last updated date. |
Limit | int | No | 100 | Number of objects to return in response. The default (and maximum) value is 100 . |
Page | FPubnubPage | No | n/a | Object used for pagination to define which previous or next result page you want to fetch. |
→ Next | FString | No | 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 | FString | No | 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 | Type | Description |
---|---|---|
FPubnubMembersResponseWrapper | struct | Returned object containing these fields: Page , Total , Status , and Memberships . |
→ Page | FPubnubPage | Object used for pagination to define which previous or next result page you want to fetch. |
→ Next | 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 | 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 | int | Total number of channel members. |
→ Status | FString | Status code of a server response, like 200 . |
→ Memberships | TArray<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.
- Blueprint
- C++ / Input parameters
User->GetMemberships(
FString Filter = "",
FString Sort = "",
int Limit = 0,
FPubnubPage Page = FPubnubPage()
);
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
Filter | FString | No | n/a | Expression used to filter the results. Returns only these channels whose properties satisfy the given expression are returned. The filter language is defined here. |
Sort | FString | No | n/a | Key-value pair of a property to sort by, and a sort direction. Available options are id , name , and updated . Use asc or desc to specify the sorting direction, or specify null to take the default sorting direction (ascending). For example: {name: "asc"} . By default, the items are sorted by the last updated date. |
Limit | int | No | 100 | Number of objects to return in response. The default (and maximum) value is 100 . |
Page | FPubnubPage | No | n/a | Object used for pagination to define which previous or next result page you want to fetch. |
→ Next | FString | No | 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 | FString | No | 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 | Type | Description |
---|---|---|
FPubnubMembershipsResponseWrapper | struct | Returned object containing these fields: Page , Total , Status , and Memberships . |
→ Page | FPubnubPage | Object used for pagination to define which previous or next result page you want to fetch. |
→ Next | 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 | 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 | int | Total number of channel members. |
→ Status | FString | Status code of a server response, like 200 . |
→ Memberships | TArray<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 singleMembership
object.StreamUpdatesOn()
checks updates on a list ofMembership
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
- Blueprint
- C++ / Input parameters
-
StreamUpdates()
Membership->StreamUpdates(FOnPubnubMembershipStreamUpdateReceived MembershipUpdateCallback);
-
StreamUpdatesOn()
Membership->StreamUpdatesOn(
TArray<UPubnubMembership*> Memberships,
FOnPubnubMembershipStreamUpdateReceived MembershipUpdateCallback
);
Parameter | Type | Required in StreamUpdates() | Required in StreamUpdatesOn() | Default | Description |
---|---|---|---|---|---|
Memberships | TArray<UPubnubMembership*> | No | Yes | n/a | Array of Membership objects for which you want to get updates. |
MembershipUpdateCallback | FOnPubnubMembershipStreamUpdateReceived | Yes | Yes | n/a | Callback function passed as a parameter to both methods. It defines the custom behavior to be executed when detecting channel metadata changes. |
Output
Type | Description |
---|---|
UPubnubCallbackStop* | Object on which you can call Stop() to stop receiving updates. |
Basic usage
Get updates on the first user membership.
-
StreamUpdates()
show all 21 lines#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];
Get updates on the first page of user memberships.
-
StreamUpdatesOn()
show all 18 lines#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;
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
- Blueprint
- C++ / Input parameters
Membership->Update(FString CustomData);
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
Custom | FString | Yes | n/a | Any custom properties or metadata associated with the channel-user membership. |
Output
Type | Description |
---|---|
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