Invite users
In UIKit for iOS, you can invite users to a group channel through the SBUInviteUserViewController
class. The view controller uses the SBUUserCell
class to display a list of users who aren't in the channel and invite them. Unless you have a specific list of users you selected, all users who are using your chat service is displayed in the user list by default.
Note: If you set the starting point of your chat service to be the channel list, group or open channel, channel settings or member list, you can seamlessly guide your users to the invite users view.
Initialize
You can start building an invite users view through the SBUInviteUserViewController
class. Use either the init(channelURL:users:)
or init(channel:users:)
initializer to create the instance and display the view as shown below.
Note: If you don't set a value to the
user
parameter, the default value ofnil
is used instead.
Usage
The following items are key elements of SBUInviteUserViewController
that are used to create a functional view.
Module components
In the SBUInviteUserViewController
class, SBUInviteUserModule
and its components are used to create and display the invite users view. The module is composed of two components: HeaderComponent
and ListComponent
.
Property name | Type | Default value |
---|---|---|
HeaderComponent | SBUInviteUserModule.Header | SBUModuleSet.InviteUserModule.HeaderComponent |
ListComponent | SBUInviteUserModule.List | SBUModuleSet.InviteUserModule.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, the configure
method of each module component is called to set the property values and display the view.
HeaderComponent
The HeaderComponent
includes a channel title, a back button that takes the user to the previous view, and a text button that invites the selected users to the channel.
The following table shows the parameters of the configure
method of the HeaderComponent
.
Parameter name | Type |
---|---|
delegate | SBUInviteUserModuleHeaderDelegate |
dataSource | SBUInviteUserModuleHeaderDataSource |
theme | SBUUserListTheme |
Note: To learn more about the delegate, data source, and the properties of the
HeaderComponent
, go to this API reference page.
ListComponent
The ListComponent
shows a list of all users that can be invited. If the user is already a channel member, they will not be shown on the list.
The following table shows the parameters of the configure
method of the ListComponent
.
Parameter name | Type |
---|---|
delegate | SBUInviteUserModuleListDelegate |
dataSource | SBUInviteUserModuleListDataSource |
theme | SBUUserListTheme |
Note: To learn more about the delegate, data source, and the properties of the
ListComponent
, go to this API reference page.
View model
The SBUInviteUserViewController
class uses a view model that is a type of the SBUInviteUserViewModel
class. The view model is created in the initializer of the view controller through the createViewModel(channel:channelURL:channelType:users:)
method. When the view model object is created, it retrieves channel list data from Chat SDK to the view controller and updates the view through the baseSelectedUserViewModel(_:didChangeUserList:needsToReload:)
event.
Note: If the value of
channel
orchannelURL
is invalid, the view model cannot retrieve the user list.
The following table shows the parameters of the createViewModel
method.
Parameter name | Type | Description |
---|---|---|
channel | BaseChannel | Specifies the channel value. (Default: |
channelURL | String | Specifies the URL of the channel. (Default: |
channelType | ChannelType | Specifies the type of channel. This parameter needs to be specified with |
users | [SBUUser] | Specifies a custom user list if you wish to use your own list of users. (Default: |
Note: To learn more about the methods and the event delegates of the view model, go to this API reference page.
SBUInviteUserViewController properties
For detailed information about the properties of SBUInviteUserViewController
, go to this API reference page.
Customization
You can customize the invite users 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.
- Change the value of
SBUViewControllerSet.InviteUserViewController
.
- Use a one-time custom view controller in the invite users view.
Module component
There are two ways to customize a module component: change the default module component type in the global SBUModuleSet.InviteUserModule
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.
- Change the value of
SBUModuleSet.InviteUserModule.HeaderComponent
.
- Change the module component in
SBUInviteUserViewController
.
Note: To learn more about the methods of
SBUInviteUserModule
, go to this 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.
- Use a customized view model.
- Customize the view model's event delegate.
Note: You can also customize the data source using the same codes as above.