Chat UIKit iOS UIKit v3
Chat UIKit iOS UIKit
Chat UIKit
iOS UIKit
Version 3

Moderate open channels and participants

Copy link

You can moderate open channels and participants in UIKit through the SBUModerationsViewController class. This class is used to display a moderation view for operators, muted participants, and banned users.

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


Initialize

Copy link

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: {OPEN_CHANNEL})
let navigationController = UINavigationController(rootViewController: moderationsVC)
present(navigationController, animated: true)

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

Module components

Copy link

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.OpenModerationsModule.HeaderComponent

ListComponent

SBUModerationsModule.List

SBUModuleSet.OpenModerationsModule.ListComponent

Each module component is assigned with 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, the configure method of each module component is called to set the property values and display the view.

HeaderComponent

Copy link

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

Copy link

The ListComponent shows the moderation menu, which contains a list of operators, muted participants, and banned users. 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

Copy link

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:) and createViewModel(channelURL:channelType:) methods. 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

BaseChannel

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

Copy link

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


Customization

Copy link

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

View controller

Copy link

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 {
    // Implement custom code here.
}
  1. Change the value of SBUViewControllerSet.OpenModerationsViewController.
SBUViewControllerSet.OpenModerationsViewController = 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: {OPEN_CHANNEL})
let navigationController = UINavigationController(rootViewController: moderationsVC)
present(navigationController, animated: true)

Module component

Copy link

There are two ways to customize a module component: change the default module component type in the global SBUModuleSet.OpenModerationsModule 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: SBUModerationsModule.Header {
    // Implement custom code here.
}
  1. Change the value of SBUModuleSet.OpenModerationsModule.HeaderComponent.
SBUModuleSet.OpenModerationsModule.HeaderComponent = CustomHeader.self

let moderationVC = SBUViewControllerSet.OpenModerationsViewController(channel: {OPEN_CHANNEL}})

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

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

View model

Copy link

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: SBUModerationsViewController {
    override func createViewModel(channel: OpenChannel? = nil,
                                  channelURL: String? = nil) {
        // Set `viewModel` to the `CustomViewModel` object.
        self.viewModel = CustomViewModel()

        // Implement your code here.
    }
}
  1. Customize the view model's event delegate.
extension CustomViewController: SBUModerationsViewModelDelegate {
    override func moderationsViewModel(
        _ viewModel: SBUModerationsViewModel,
        didChangeChannel channel: BaseChannel?,
        withContext context: MessageContext
    ) {
        // Implement your code here.
    }
}