UIKit iOS v3
UIKit iOS
UIKit
iOS
Home
/
UIKit
/
iOS
This is the new Docs for UIKit v3 beta for iOS. To see the previous Docs, click here.

Moderate channels and members

You can moderate channels and members in UIKit through the SBUModerationsViewController class. This class is used to display a moderation view for operators, muted members, and banned members, and the option to freeze the channel.

Note: By default, the moderation menu in SBUGroupChannelSettingsViewController is accessible for operators only.


Initialize

You can start building a moderation view through the SBUModerationsViewController class. Use either the init(channelUrl:) or init(channel:) initializer to create the instance and display the view as shown below.

// Case 1: Using channel url.
let moderationsVC = SBUModerationsViewController(channelUrl: {CHANNEL_URL})
let navigationController = UINavigationController(rootViewController: moderationsVC)
present(navigationController, animated: true)

// Case 2: Using channel object.
let moderationsVC = SBUModerationsViewController(channel: {CHANNEL})
let navigationController = UINavigationController(rootViewController: moderationsVC)
present(navigationController, animated: true)

Usage

The following items are key elements of SBUModerationsViewController that are used to create a functional moderation view.

Module components

In the SBUModerationsViewController class, SBUModerationsModule and its components are used to create the moderation view. The module is composed of two components: headerComponent and listComponent.

Property nameTypeDefault value

headerComponent

SBUModerationsModule.Header

SBUModuleSet.moderationsModule.headerComponent

listComponent

SBUModerationsModule.List

SBUModuleSet.moderationsModule.listComponent

Each module component is assigned a value from the SBUModuleSet class and gets added to the view in the setupView() method of the Sendbird UIKit's view life cycle. Then, headerComponent.configure(delegate:theme:) and listComponent.configure(delegate:dataSource:theme:) are called to set the values of the module components and display the view.

headerComponent

The headerComponent includes a channel title and a back button that takes the user to the previous view. Each property corresponds to the elements in the navigation bar of SBUModerationsViewController.

The following table shows the parameters of the configure method of the headerComponent.

Parameter nameType

delegate

SBUModerationsModuleHeaderDelegate

theme

SBUChannelSettingsTheme

Note: To learn more about the delegate and the properties of the headerComponent, go to the API reference page.

listComponent

The listComponent shows the moderation menu, which contains a list of operators, muted members, banned members, and the option to freeze the channel. The following table shows the parameters of the configure method of the listComponent.

Parameter nameType

delegate

SBUModerationsModuleListDelegate

dataSource

SBUModerationsModuleListDataSource

theme

SBUChannelSettingsTheme

Note: To learn more about the delegate, data source, and the properties of the listComponent, go to the API reference page.

View model

The SBUModerationsViewController class uses a view model that is a type of the SBUModerationsViewModel class. The view model is created in the initializer of the view controller through the createViewModel(channel:channelUrl:) method. When the view model object is created, it retrieves moderation data from Chat SDK to the view controller and updates the view through the moderationsViewModel(_:didChangeChannel:withContext:) event.

Note: If the value of channel or channelUrl is invalid, the view model cannot retrieve the moderation menu.

The following table shows the parameters of the createViewModel method.

Parameter nameTypeDescription

channel

SBDBaseChannel

Specifies the channel value. (Default: nil)

channelUrl

String

Specifies the URL of the channel. (Default: nil)

Note: To learn more about the methods and the event delegates of the view model, go to this API reference page.

SBUModerationsViewController properties

To learn more about the properties of SBUModerationsViewController, go to the API reference page.


Customization

You can customize the moderation view by changing the view controller, module component, and view model that correspond to this key function.

View controller

There are two ways to customize the view controller: change the default view controller value in the global SBUViewControllerSet class or set a single-use custom view controller in the key function.

The custom view controller in the code below is used in the following customization examples.

class CustomViewController: SBUModerationsViewController {
    ...
}
  1. Change the value of SBUViewControllerSet.ModerationsViewController.
SBUViewControllerSet.ModerationsViewController = CustomViewController.self

// The view controller will now use `CustomViewController` as the default value.
  1. Use a one-time custom view controller in the moderation view.
let moderationVC = CustomViewController(channel: {CHANNEL})
let navigationController = UINavigationController(rootViewController: moderationsVC)
present(navigationController, animated: true)

Module component

There are two ways to customize a module component: change the default module component value in the global SBUModuleSet.moderationsModule class or set a single-use custom module component in the view controller.

The custom header component in the code below is used in the following customization examples.

class CustomHeader: SBUModuleSet.moderationsModule.Header {
    ...
}
  1. Change the value of SBUModuleSet.moderationsModule.headerComponent.
SBUModuleSet.moderationsModule.headerComponent = CustomHeader()

let moderationVC = SBUViewControllerSet.ModerationsViewController(channel: {CHANNEL}})

// The `headerComponent` in `SBUModerationsViewController` will now use `customHeader` as the default value.
  1. Change the module component in SBUModerationsViewController.
let moderationVC = SBUViewControllerSet.ModerationsViewController(channel: {CHANNEL})
moderationVC.headerComponent = CustomHeader()

Note: To learn more about the methods of SBUModerationsModule, go to the API reference page.

View model

In order to use a customized view model or customize the existing view model's event delegate, you must override the view controller.

  1. Use a customized view model.
class CustomViewController: SBUModerationsViewModel {
    override func createViewModel(...) {
        // Set `viewModel` to the `CustomViewModel` object.
        self.viewModel = CustomViewModel()
        ...
    }
}
  1. Customize the view model's event delegate.
extension CustomViewController: SBUModerationsViewModelDelegate {
    override func moderationsViewModel(
        _ viewModel: SBUModerationsViewModel,
        didChangeChannel channel: SBDBaseChannel?,
        withContext context: SBDMessageContext
    ) {
        // Implement your code here.
    }
}