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.
Get members
Get all members of a channel with GetMembers().
Method signature
- Blueprint
- C++ / Input parameters
1Channel->GetMembers(
2 FString Filter = "",
3 FString Sort = "",
4 int Limit = 0,
5 FPubnubPage Page = FPubnubPage()
6);
| Parameter | Description |
|---|---|
FilterType: FStringDefault: 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. |
SortType: FStringDefault: 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. |
LimitType: intDefault: 100 | Number of objects to return in response. The default (and maximum) value is 100. |
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 |
|---|---|
FPubnubMembersResponseWrapperType: struct | Returned object containing these fields: Page, Total, Status, 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. |
→ StatusType: FString | Status code of a server response, like 200. |
→ MembershipsType: 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.
- Blueprint
- C++ / Input parameters
1User->GetMemberships(
2 FString Filter = "",
3 FString Sort = "",
4 int Limit = 0,
5 FPubnubPage Page = FPubnubPage()
6);
| Parameter | Description |
|---|---|
FilterType: FStringDefault: 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. |
SortType: FStringDefault: 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. |
LimitType: intDefault: 100 | Number of objects to return in response. The default (and maximum) value is 100. |
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 |
|---|---|
FPubnubMembershipsResponseWrapperType: struct | Returned object containing these fields: Page, Total, Status, 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. |
→ StatusType: FString | Status code of a server response, like 200. |
→ MembershipsType: 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 membershipStreamUpdatesOn()- 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 updatedMembershipobject on each change (nullptrif deleted)StreamUpdatesOn()returns the complete list of monitored memberships on any change
Method signature
- Blueprint
- C++ / Input parameters
-
StreamUpdates()1Membership->StreamUpdates(FOnPubnubMembershipStreamUpdateReceived MembershipUpdateCallback); -
StreamUpdatesOn()1Membership->StreamUpdatesOn(
2 TArray<UPubnubMembership*> Memberships,
3 FOnPubnubMembershipStreamUpdateReceived MembershipUpdateCallback
4);
| Parameter | Required in StreamUpdates() | Required in StreamUpdatesOn() | Description |
|---|---|---|---|
MembershipsType: TArray<UPubnubMembership*>Default: n/a | No | Yes | Array of Membership objects for which you want to get updates. |
MembershipUpdateCallbackType: FOnPubnubMembershipStreamUpdateReceivedDefault: n/a | Yes | Yes | 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. |
Sample code
Get updates on the first user membership.
-
StreamUpdates()
show all 22 lines1#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
Get updates on the first page of user memberships.
-
StreamUpdatesOn()
show all 20 lines1#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;
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
- Blueprint
- C++ / Input parameters
1Membership->Update(FPubnubChatMembershipData MembershipData);
| Type | Description |
|---|---|
FPubnubChatMembershipData | The object containing all membership data. |
FPubnubChatMembershipData
| Parameter | Description |
|---|---|
CustomDataJsonType: FString | Custom data associated with the membership. |
StatusType: FString | Status of the membership. |
TypeType: FString | Type of the membership. |
Output
| Type | Description |
|---|---|
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 linesGet membership data
GetMembershipData() returns the channel membership data for a given user.
Method signature
- Blueprint
- C++ / Input parameters
1Membership->GetMembershipData();
Output
| Type | Description |
|---|---|
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