/ SDKs / Flutter
SDKs
Chat SDKs Flutter v4
Chat SDKs Flutter
Chat SDKs
Flutter
Version 4

Ban and unban a user

Copy link

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

Copy link
try {
  final openChannel = await OpenChannel.getChannel('CHANNEL_URL');

  // Ban a user.
  await openChannel.banUser(userId: '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 openChannel.unbanUser(userId: '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

Copy link
try {
  final groupChannel = await GroupChannel.getChannel('CHANNEL_URL');

  // Ban a user.
  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.

  // Unban a user.
  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.
}