Report misbehaving users

Unreal Chat SDK provides moderation mechanisms for:

  • Admins to mute misbehaving users on channels.
  • Admins to ban misbehaving users from accessing channels.
icon

Usage in Blueprints and C++


Requires App Context

To work with stored user metadata, you must enable App Context for your app's keyset in the Admin Portal.

You can also add custom logic that uses the emitted events and defines what an admin can do with reported users. For example, an admin can mute or ban the users from a given channel using Access Manager.

Mute or ban users

As an admin, you can mute a specific user on a channel or ban them from accessing that channel using three SetRestrictions() methods.

All of them give the same output. The only difference is that you call a given method on the Chat, User, or the Channel object. Depending on the object, these methods take a different set of input parameters.

When an admin mutes or bans a user on a channel, a moderation event is created (of type muted or banned). You can listen to these events and, for example, remove user's membership on that channel.

Also, when an admin mutes or bans a user, an additional moderation membership is created for that user. This membership copies the ID of the channel and adds the PUBNUB_INTERNAL_MODERATION_ prefix to it, even though no new channel gets created for that purpose. This moderation membership stores information about the user's current mute and ban restrictions under the custom property.

The reason behind creating an additional moderation membership was to have an object that could be secured with Access Manager and made inaccessible to users. The standard membership object couldn't serve this purpose as it stores info on the users' lastReadMessageTimetoken custom data that users should access to be able to see unread messages on channels.

The additional membership is created only for the moderation purposes - when fetching all channel memberships for a given user with the GetMemberships() method, you won't see the moderation membership as Unreal Chat SDK filters it out automatically with App Context Filtering Language.

When you lift restrictions on the user (unmute or unban them), the moderation membership is removed and a moderation event of type lifted is created.

To learn if a user is muted on a given channel or banned, use the Unreal Chat SDK methods to check moderation restrictions.

Requires Secret Key authentication

Mute and ban restrictions for the client devices should be set by servers initializing Unreal Chat SDK with a Secret Key (available on the Admin Portal on your app's keyset).

The Secret Key should only be used within a secure server and never exposed to client devices. If the Secret Key is ever compromised, it can be an extreme security risk to your application. If you suspect your Secret Key has been compromised, you can generate a new Secret Key for the existing PubNub keyset on the Admin Portal.

Method signature

Output

These methods don't return any value.

Basic usage

Mute

Mute support_agent_15 on the support channel.

  • SetRestrictions() (on the Chat object)

    #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";

    FString ChannelID = "support";

    FPubnubRestriction Restrictions;
    Restrictions.Mute = true;
    show all 20 lines
  • SetRestrictions() (on the User object)

    #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";
    FString ChannelID = "support";

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

    show all 22 lines
  • SetRestrictions() (on the Channel object)

    #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";
    FString ChannelID = "support";

    // Get the user and save the reference
    UPubnubChannel* Channel = Chat->GetChannel(ChannelID);

    show all 22 lines

Ban

Ban support_agent_15 from the support channel.

  • SetRestrictions() (on the Chat object)

    #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";

    FString ChannelID = "support";

    FPubnubRestriction Restrictions;
    Restrictions.Mute = false;
    show all 20 lines
  • SetRestrictions() (on the User object)

    #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";
    FString ChannelID = "support";

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

    show all 22 lines
  • SetRestrictions() (on the Channel object)

    #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";
    FString ChannelID = "support";

    // Get the user and save the reference
    UPubnubChannel* Channel = Chat->GetChannel(ChannelID);

    show all 22 lines

Check restrictions

One user on one channel

Check if there are any mute or ban restrictions set for a user on one channel using the GetChannelRestrictions() and GetUserRestrictions() methods.

Method signature

Output
ParameterTypeDescription
FPubnubRestrictionstructReturned object containing three fields: Ban, Mute, and Reason.
 → BanboolInfo whether the user is banned from the channel.
 → MuteboolInfo whether the user is muted on the channel.
 → ReasonFStringReason why the user was banned or muted.

Basic usage

Check if the user support_agent_15 has any restrictions set on the support channel.

  • GetChannelRestrictions()

    #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);
    UPubnubChannel* Channel = Chat->GetChannel("support");

    show all 16 lines
  • GetUserRestrictions()

    #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);
    UPubnubChannel* Channel = Chat->GetChannel("support");

    show all 16 lines

One user on all channels

Check if there are any mute or ban restrictions set for a user on all channels they are a member of using the GetChannelsRestrictions() method.

Method signature

Output
ParameterTypeDescription
FPubnubChannelsRestrictionsWrapperstructReturned object containing these fields: Page, Total, Status, and Restrictions.
 → pageobjectObject 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 restrictions.
 → StatusintStatus code of a server response, like 200.
 → RestrictionsTArray<FPubnubChannelRestriction>Array containing restrictions.
   → BanboolInfo whether the user is banned from the given channel.
   → MuteboolInfo whether the user is muted on the given channel.
   → ReasonFStringReason why the user was banned or muted.
   → Channel IDFStringID of the channel containing user restrictions.

Basic usage

List all mute and ban restrictions set for the user support_agent_15.

#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);

FPubnubChannelsRestrictionsWrapper Restrictions = User->GetChannelsRestrictions();

All users on one channel

Check if there are any mute or ban restrictions set for members of a given channel using the GetUsersRestrictions() method.

Method signature

Output
ParameterTypeDescription
FPubnubUsersRestrictionsWrapperstructReturned object containing these fields: Page, Total, Status, and Restrictions.
 → pageobjectObject 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 restrictions.
 → StatusintStatus code of a server response, like 200.
 → RestrictionsTArray<FPubnubUserRestriction>Array containing restrictions.
   → BanboolInfo whether the user is banned from the given channel.
   → MuteboolInfo whether the user is muted on the given channel.
   → ReasonFStringReason why the user was banned or muted.
   → User IDFStringID of the restricted user.

Basic usage

List all mute and ban restrictions set for the support 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");

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

FPubnubUsersRestrictionsWrapper Restrictions = Channel->GetUsersRestrictions();

Secure moderation

You could try to use only the banning or muting restrictions on client devices and enforce some UI moderation, like not displaying channels for users who are banned from them, or not displaying input field for users who are muted on a given channel so that they couldn't post a message.

Still, such solely client-side restrictions can easily be bypassed if not secured with an additional server-side logic that uses Access Manager to allow or block user's access to PubNub resources (channels and users). This server-side can also be followed by additional client-side errors that inform app users about their restrictions up front.

Server-side restrictions

It's recommended to use Access Manager alongside the Unreal Chat SDK methods and grant or revoke permissions from users based on their muting or banning restrictions.

For example, you could have a UI moderation dashboard (like Channel Monitor) where admins set restrictions on users by muting or banning them from specific channels. After that, you can use one of the Unreal Chat SDK methods to get moderation restrictions for users and, based on results, call the Access Manager API to either generate or revoke grant tokens for PubNub resources (channels or users).

Let's look at sample steps that use Unreal SDK methods to configure a chat app, set up server permissions, listen to any permission changes in Channel Monitor UI, and invoke access grant or revoke request on the server side.

  1. Enable Access Manager.

    Navigate to your app's keyset in the Admin Portal and turn on the ACCESS MANAGER option.

  2. Initialize Unreal Chat SDK with Auth Key.

    On the frontend of your app, initialize the Unreal Chat SDK (Init()) with the authentication key (Auth Key) on your clients. Use it for all requests made to PubNub APIs to authenticate users in your application and grant them access to PubNub resources (other users' metadata and channels).

  3. Secure backend initialization.

    On the backend, initialize the Unreal SDK with the secret key on your servers to secure your PubNub instance.

    Secret key

    Secret Key is a secret shared between your application's server and PubNub and it's used to administer Access Manager permissions for your client applications by signing and verifying the authenticity of messages and requests. Remember to never expose the Secret Key to client devices.

  4. Get user permissions.

    Retrieve detailed user restrictions and convert these details into a simplified permission format where each channel is marked with whether the user can read, write, or access it, based on such restrictions as bans or mutes using the Get user details and Check restrictions methods.

  5. Generate authorization token.

    Using the Unreal SDK, generate and assign an access token reflecting the user's permissions.

    The token contains information about which channels the user can access and how (read/write), and it's configured with a specific validity period. This token serves as a key for users to interact with the application according to their permissions.

    Operation-to-permission mapping

    Read the Permissions document for a complete list of available operations that users can do with PubNub resources in apps created with the Unreal Chat SDK.

    Set short TTLs

    You can mute or ban a user for an indefinite amount of time, but you can unmute/unban them at any time. To make sure that the permissions set with Access Manager reflect the most up-to-date muting/banning restrictions on the client-side, it's recommended to set short-lived tokens (TTLs) for grant calls (valid for seconds and minutes rather than hours or days).

  6. Listen for moderation events.

    Set up a listener to listen for the moderation event type ("banned," "muted," or "lifted") generated when UI restrictions are added or removed.

  7. Act on moderation events.

    Update permissions in response to moderation events and generate new tokens if necessary.

Client-side restrictions

Once you enable and define server-side permissions with Access Manager, you can be sure that your muting and banning restrictions are always enforced.

Additionally, you can read moderation restrictions set with the Unreal Chat SDK methods also on your app's frontend to let a given user know upfront that they are muted on a channel or banned from accessing a channel using popup messages, iconography, etc. For example, before a user tries to write a message on a channel where they are muted and tries to search for the input field that is either greyed out or unavailable, you can display a popup message informing them about the restriction.

Listen to moderation events

As an admin of your chat app, you can use the ListenForEvents() method to send notifications to the affected user when you mute or ban them on a channel, or to remove user channel membership each time they are banned.

Events documentation

To read more about the events of type moderation, refer to the Chat events documentation.

Method signature

icon

Handle the response

Output

This method doesn't return any value.

Basic usage

Listen for moderation events on the support 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");

FString ChannelID = "support";

// Create a pubnub response delegate
// you MUST implement your own callback function to handle the response
FOnPubnubEventReceived ListenResponse;
ListenResponse.BindDynamic(this, &AMyActor::OnListenResponseReceived);

show all 20 lines
Last updated on