Chat / Flutter
Current version: v3
Chat Flutter v3
Chat Flutter
Chat
Flutter
Home
/
Chat
/
Flutter
/
User

Ban and unban a user

Operators of an open or group channel can remove any users that behave inappropriately in the channel using the ban feature. A banned user is immediately kicked out of the channel, but allowed to participate in the channel again after the time specified in the seconds property has passed. Operators can ban and unban users using the following code.

Open channel

try {
    final channel = await OpenChannel.getChannel(CHANNEL_URL);
    // Ban a user.
    await channel.banUser(USER_ID, seconds: SECONDS);
    // The user is successfully banned from the channel.
    // You can display a message to let the user know they have been banned.

    // Unban a user.
    await channel.unbanUser(USER_ID);
    // The user is successfully unbanned from the channel.
    // You can display a message to let the user know they have been unbanned.
} catch (e) {
    // Handle error.
}

Group channel

try {
    await groupChannel.banUser(
        userId: USER_ID,
        seconds: SECONDS,
        description: DESCRIPTION
    );
    // The user is successfully banned from the channel.
    // You can display a message to let the user know they have been banned.

    await groupChannel.unbanUser(userId: USER_ID);
    // The user is successfully unbanned.
    // You can display a message to let the user know they have been unbanned.
} catch (e) {
    // Handle error.
}