Search messages
You can search for messages within a group channel using the SBUMessageSearchViewController
class, which displays the message search bar and the search results. The message search view is accessible through the Search in channel option in the SBUGroupChannelSettingsViewController
class. Once you tap on one of the search results in the message search view, a new group channel view with the selected message as highlighted appears.
Note: If you set the starting point of your chat service to be the channel list or group channel, you can seamlessly guide your users to the message search view.
Initialize
You can start building a message search view through the SBUMessageSearchViewController
class. Use the init(channel:)
initializer to create the instance and display the view as shown below.
Usage
The following items are key elements of SBUMessageSearchViewController
that are used to create a functional message search view.
Module components
In the SBUMessageSearchViewController
class, SBUMessageSearchModule
and its components are used to create and display the message search view. The module is composed of two components: HeaderComponent
and ListComponent
.
Property name | Type | Default value |
---|---|---|
HeaderComponent | SBUMessageSearchModule.Header | SBUModuleSet.MessageSearchModule.HeaderComponent |
listComponent | SBUMessageSearchModule.List | SBUModuleSet.MessageSearchModule.ListComponent |
When the loadView()
method of the view controller is called, the module components get 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
in the message search view shows a search bar in the titleView
area and a button that searches for the keyword in the user's group channels. Each property corresponds to the elements in the NavigationBar
of SBUMessageSearchViewController
.
The following table shows the parameters of the configure
method of the HeaderComponent
.
Parameter name | Type |
---|---|
delegate | SBUMessageSearchModuleHeaderDelegate |
theme | SBUMessageSearchTheme |
Note: To learn more about the delegate and the properties of the
HeaderComponent
, go to the API reference page.
listComponent
The ListComponent
shows a list of search results that contain the keyword. When a user taps on one of the results, it takes them to the group channel view with the keyword as highlighted. The following table shows the parameters of the configure
method of the ListComponent
.
Parameter name | Type |
---|---|
delegate | SBUMessageSearchModuleListDelegate |
dataSource | SBUMessageSearchModuleListDataSource |
theme | SBUMessageSearchTheme |
Note: To learn more about the delegate, data source, and the properties of the
ListComponent
, go to the API reference page.
View model
The SBUMessageSearchViewController
class uses a view model that is a type of the SBUMessageSearchViewModel
class. The view model is created in the initializer of the view controller through the createViewModel(channel:)
method.
The following table shows the parameter of the createViewModel
method.
Parameter name | Type | Description |
---|---|---|
channel | BaseChannel | Specifies the channel value. (Default: |
Note: To learn more about the methods and the event delegates of the view model, go to this API reference page.
SBUMessageSearchViewController properties
To learn more about the properties of SBUMessageSearchViewController
, go to the API reference page.
Customization
You can customize the message search 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.MessageSearchViewController
.
- Use a one-time custom view controller in the message search view.
Module component
There are two ways to customize a module component: change the default module component type in the global SBUModuleSet.MessageSearchModule
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.MessageSearchModule.HeaderComponent
.
- Change the module component in
SBUMessageSearchViewController
.
Note: To learn more about the methods of
SBUMessageSearchModule
, 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.
- Use a customized view model.
- Customize the view model's event delegate.
MessageSearchQueryBuilder
In SBUMessageSearchViewController
, you can customize the query data used to search for keywords in the channel by using MessageSearchQueryBuilder
. There are two ways to customize the query builder: use a customized query builder in the view controller or override the createViewModel()
method.
- Use a customized query builder.
- Override
createViewModel()
.