Search Conversation Screen
Overview
The LMChatSearchConversationListViewController
is a view controller that displays and manages search results for conversations and chatrooms. It provides a search bar for users to query messages or chatrooms, a table view for displaying results (with pagination support), and hooks for analytics tracking.
Functionality
Protocols Implemented
- UITableViewDataSource / UITableViewDelegate: Manages the data population and user interaction with the table view.
- UISearchBarDelegate: Handles search bar text changes, cancellations, and triggers the search logic.
- LMChatSearchConversationListViewProtocol: Updates the UI with new data and toggles the footer loader.
UI Components
tableView
A grouped-styleUITableView
for displaying the search results. It uses custom cells for rendering chatrooms and messages.LMChatSearchConversationMessageCell
A custom cell used to display matched conversation messages in the table view.
When a result item implementsLMChatSearchConversationMessageCell.ContentModel
, this cell is dequeued to show the relevant message snippet.searchController
AUISearchController
responsible for managing the search bar and its interactions.
It does not obscure the background and delegates user input to this view controller.
Properties
searchResults
([ContentModel]
)
An array containing sectioned search results. EachContentModel
has an optional title and a list of items conforming toLMChatSearchCellDataProtocol
.viewmodel
(LMChatSearchConversationListViewModel?
)
Manages data fetching and encapsulates the logic for search operations and pagination.
Methods
searchBar(_:textDidChange:)
Debounces the user’s typing, triggers the search after a brief delay, and updatessearchResults
.searchBarCancelButtonClicked(_:)
Resets the search when the user taps the cancel button. Tracks an analytics event for the cancellation.resetSearchData()
Clears the existing results and reloads the table when a new search begins or is canceled.updateSearchList(with:)
Refreshes the table view with new search result data. Displays a “no result” view if data is empty.showHideFooterLoader(isShow:)
Toggles a footer loader for pagination purposes.
Customization
Below is an example showing how you can override or extend LMChatSearchConversationListViewController
and set it up in your application:
class CustomSearchConversationListViewController: LMChatSearchConversationListViewController {
override func setupViews() {
super.setupViews()
// Customize table or other UI elements here
}
override func setupAppearance() {
super.setupAppearance()
// Adjust background colors, text attributes, etc.
view.backgroundColor = .lightGray
}
}
func application(
_ application: UIApplication,
willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
// Replace the default with your custom class
LMCoreComponents.shared.searchConversationListViewController = CustomSearchConversationListViewController.self
// ...
return true
}
Models
ContentModel
A data model representing a section in the search result list.
VARIABLE | TYPE | DESCRIPTION | Optional |
---|---|---|---|
title | String | An optional title for this section | ✔️ |
data | [LMChatSearchCellDataProtocol] | A list of items to display in this section |
Each item in the data
array represents a result conforming to LMChatSearchCellDataProtocol
(such as a chatroom or conversation message).
These items are then rendered in the table view cells.