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 (32 KiB server limit applies)
Mute list limit

Persisted lists exceeding 32 KiB (~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 32 KiB (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_PRIV.$currentUserId.mute1 channel
  • update, delete, get on PN_PRIV.$currentUserId.mute1 user

Listen to restriction changes​

onRestrictionChanged() notifies the current user whenever an admin changes their mute or ban status on any channel. Use this to react in real time — for example, to show a notification or adjust UI when the user is muted or banned.

You can also use user.stream.restrictionChanges() for an AsyncStream-based approach.

Method signature​

1user.onRestrictionChanged(
2 callback: @escaping (Restriction) -> Void
3) -> AutoCloseable

The Restriction struct carries the restriction payload:

1public struct Restriction {
2 public let userId: String
3 public let channelId: String
4 public let ban: Bool
5 public let mute: Bool
6 public let reason: String?
7}

Input​

* required
ParameterDescription
callback *
Type: (Restriction) -> Void
Default:
n/a
Closure called with a Restriction whenever the user's moderation status changes on a channel.

Output​

ParameterDescription
AutoCloseableAn object you must retain. When released or closed, the listener stops.

Was this page useful?

Last updated on