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:
channel.onMessageReceived()channel.join()channel.getHistory()chat.listenForEvents()chat.getEventsHistory()
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
- Async/await
- Closure
1func muteUser(userId: String) async throws
1func muteUser(
2 userId: String,
3 completion: ((Result<Void, Error>) -> Void)?
4)
Input
| Parameter | Description |
|---|---|
userId *Type: String | User ID of the user you want to mute. |
completionType: ((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.
- Async/await
- Closure
1
1
Unmute users as a regular chat user
Remove a user from the mute list to see their messages and events again.
Method signature
- Async/await
- Closure
1func unmuteUser(userId: String) async throws
1func unmuteUser(
2 userId: String,
3 completion: ((Result<Void, Error>) -> Void)?
4)
Input
| Parameter | Description |
|---|---|
userId *Type: String | User ID of the user you want to unmute. |
completionType: ((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.
- Async/await
- Closure
1
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):
readonPN_PRIV.$currentUserId.mute1channelupdate,delete,getonPN_PRIV.$currentUserId.mute1user
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
| Parameter | Description |
|---|---|
callback *Type: (Restriction) -> VoidDefault: n/a | Closure called with a Restriction whenever the user's moderation status changes on a channel. |
Output
| Parameter | Description |
|---|---|
AutoCloseable | An object you must retain. When released or closed, the listener stops. |