/ SDKs / Android
SDKs
Chat SDKs Android v4
Chat SDKs Android
Chat SDKs
Android
Version 4

Mute and unmute a user

Copy link

Operators of an open or group channel can restrict selected users from sending messages to the channel using the mute feature. A muted user remains in the channel and is allowed to view the messages but they can't send any messages to the channel until the operators unmute them. Operators can mute and unmute users using the following code.

Open channel

Copy link
KotlinKTX
OpenChannel.getChannel(CHANNEL_URL) { openChannel, e ->
    if (e != null) {
        // Handle error.
    }

    if (openChannel?.isOperator(SendbirdChat.currentUser) == true) {
        // Mute a user.
        openChannel?.muteUser(USER) { e ->
            if (e != null) {
                // Handle error.
            }

            // The user is successfully muted in the channel.
            // You can display a message to let the user know they have been muted.
            // ...
        }

        // Unmute a user.
        openChannel?.unmuteUser(USER) { e ->
            if (e != null) {
                // Handle error.
            }

            // The user is successfully unmuted in the channel.
            // You can display a message to let the user know they have been unmuted.
            // ...
        }
    }
}

Group channel

Copy link
KotlinKTX
GroupChannel.getChannel(CHANNEL_URL) { groupChannel, e ->
    if (e != null) {
        // Handle error.
    }

    if (groupChannel?.myRole == Role.OPERATOR) {
        // Mute a user.
        groupChannel?.muteUser(USER) { e ->
            if (e != null) {
                // Handle error.
            }

            // The user is successfully muted in the channel.
            // You can display a message to let the user know they have been muted.
            // ...
        }

        // Unmute a user.
        groupChannel?.unmuteUser(USER) { e ->
            if (e != null) {
                // Handle error.
            }

            // The user is successfully unmuted in the channel.
            // You can display a message to let the user know they have been unmuted.
            // ...
        }
    }
}

Note: For both open and group channels, you can also pass the unique ID of a user as a parameter instead of USER to mute or unmute using the muteUser(String) and unmuteUser(String) methods. These methods perform the same actions as the muteUser(USER) and unmuteUser(USER) methods.