On this page

Moderate misbehaving users as a chat user

Regular chat users (without secretKey) can mute undesirable users to hide their messages on the client side.

Mute list behavior:

  • Soft limit: 200 users
  • Default: session-only persistence
  • Optional: persist across sessions (32KiB server limit applies)
Mute list limit

Persisted lists exceeding 32KiB (~200 users) trigger HTTP 413 errors. Users remain muted for the session but won't persist.

Affected methods:

Requires App Context

Enable App Context in the Admin Portal to mute users.

Mute users as a regular chat user

Mute a specific user on all channels.

Method signature

1func muteUser(userId: String) async throws

Input

* required
ParameterDescription
userId *
Type: String
User ID of the user you want to mute.
completion
Type: ((Result<Void, Error>) -> Void)?
Completion closure called with the result of the operation.

Output

This method calls the completion closure with a Result<Void, Error> that succeeds when the data has been synced with the server. If syncMutedUsers is not enabled, the completion always succeeds.

Errors

If the size of the mute list exceeds 32KiB (roughly 200 users), you'll get the HTTP 413 (Request Entity Too Large) error.

Sample code

Sample code

The code samples in Swift Chat SDK focus on asynchronous code execution.

You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.

1

Unmute users as a regular chat user

Remove a user from the mute list to see their messages and events again.

Method signature

1func unmuteUser(userId: String) async throws

Input

* required
ParameterDescription
userId *
Type: String
User ID of the user you want to unmute.
completion
Type: ((Result<Void, Error>) -> Void)?
Completion closure called with the result of the operation.

Output

This method calls the completion closure with a Result<Void, Error> that succeeds when the data has been synced with the server. If syncMutedUsers is not enabled, the completion always succeeds.

Sample code

Sample code

The code samples in Swift Chat SDK focus on asynchronous code execution.

You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.

1

Check muted users

Inspect the mute list to see which users are muted.

Method signature

1var mutedUsers: Set<String> { get }

Output

This property returns a Set<String> where each String is a user ID of a muted user.

Sample code

1

Persist the mute list

Set syncMutedUsers: true during client initialization to persist the mute list across sessions.

Access Manager permissions

With Access Manager and syncMutedUsers enabled, grant these permissions (replace $currentUserId with the actual user ID):

  • read on PN_PRV.$currentUserId.mute1 channel
  • update, delete, get on PN_PRV.$currentUserId.mute1 user

Check restrictions

Check admin-imposed mute or ban restrictions:

Sample code

Single user on a single channel
1    // reference the "chat" object and invoke the "getUser()" method
2 chat.getUser("support_agent_15").async { userResult ->
3 userResult.onSuccess { user ->
4 if (user != null) {
5 // get the "support" channel
6 chat.getChannel("support").async { channelResult ->
7 channelResult.onSuccess { channel ->
8 if (channel != null) {
9 // get the channel restrictions for the user
10 user.getChannelRestrictions(channel).async { restrictionResult ->
11 restrictionResult.onSuccess { restriction ->
12 // handle the restriction object
13 }.onFailure {
14 // handle failure
15 }
show all 30 lines
All users on a single channel
1// reference the "chat" object and invoke the "getChannel()" method
2chat.getChannel("support").async { result ->
3 result.onSuccess { channel ->
4 if (channel != null) {
5 // fetch the user restrictions for the channel
6 channel.getUsersRestrictions().async { restrictionsResult ->
7 restrictionsResult.onSuccess { getRestrictionsResponse ->
8 // process the returned restrictions
9 for (restriction in getRestrictionsResponse.restrictions) {
10 if (restriction.mute || restriction.ban) {
11 // handle the restriction object (either muted or banned)
12 println("User ${restriction.userId} is restricted in channel ${channel.id}: mute=${restriction.mute}, ban=${restriction.ban}")
13 }
14 }
15 }.onFailure {
show all 27 lines
Single user on all channels
1// reference the "chat" object and invoke the "getUser()" method
2chat.getUser("support_agent_15").async { result ->
3 result.onSuccess { user ->
4 if (user != null) {
5 // fetch the channel restrictions for the user
6 user.getChannelsRestrictions().async { restrictionsResult ->
7 restrictionsResult.onSuccess { getRestrictionsResponse ->
8 // process the returned restrictions
9 for (restriction in getRestrictionsResponse.restrictions) {
10 if (restriction.mute || restriction.ban) {
11 // handle the restriction object (either muted or banned)
12 println("User is restricted on channel ${restriction.channelId}: mute=${restriction.mute}, ban=${restriction.ban}")
13 }
14 }
15 }.onFailure {
show all 27 lines
Last updated on