Skip to main content

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-style UITableView 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 implements LMChatSearchConversationMessageCell.ContentModel, this cell is dequeued to show the relevant message snippet.

  • searchController
    A UISearchController 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. Each ContentModel has an optional title and a list of items conforming to LMChatSearchCellDataProtocol.

  • 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 updates searchResults.

  • 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:

CustomSearchConversationListViewController.swift
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
}
}
AppDelegate.swift
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.

VARIABLETYPEDESCRIPTIONOptional
titleStringAn 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.