Skip to main content

Search Conversation Message Cell

Overview

The LMChatSearchConversationMessageCell is a table view cell designed to display conversation messages in search results. It presents essential details such as the sender's profile image, sender name, highlighted message content, and a formatted timestamp.

UI Components

  • userImageIcon: Displays the sender's profile image.
  • titleLabel: Shows the sender's name.
  • subtitleLabel: Displays the conversation message with highlighted text matching the search query.
  • dateLabel: Shows the formatted date of the message.

Key Methods

  • configure(with:): Configures the cell with search result data, including message content and sender information.

Customization

CustomSearchConversationMessageCell.swift
class CustomSearchConversationMessageCell: LMChatSearchConversationMessageCell {
override func setupViews() {
super.setupViews()
// Customize views if needed
}

override func setupAppearance() {
super.setupAppearance()
// Modify appearance of UI elements
titleLabel.textColor = .blue
}

override func configure(with data: ContentModel) {
super.configure(with: data)
// Add additional customization
}
}
AppDelegate.swift
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
LMUIComponents.shared.chatSearchConversationMessageCell = CustomSearchConversationMessageCell.self
// ...
return true
}

Models

ContentModel

A data model representing a conversation message search result.

VARIABLETYPEDESCRIPTIONOptional
chatroomIDStringThe identifier of the chatroom associated with the conversation.
messageIDString?The optional identifier of the specific message.✔️
chatroomNameStringThe name of the chatroom.
messageStringThe content of the conversation message.
senderNameStringThe name of the sender.
dateTimeIntervalThe timestamp of the message.
isJoinedBoolIndicates whether the user has joined the chatroom.
highlightedTextStringThe text to be highlighted in the message.
userImageUrlString?An optional URL string for the sender’s image.✔️

Example Usage:

let searchResult = LMChatSearchConversationMessageCell.ContentModel(
chatroomID: "12345",
messageID: "67890",
chatroomName: "General",
message: "This is an important message",
senderName: "John Doe",
date: Date().timeIntervalSince1970,
isJoined: true,
highlightedText: "important",
userImageUrl: "https://example.com/profile.jpg"
)

cell.configure(with: searchResult)

Response Handling

This cell is used within the chat search interface to display conversation search results. It updates the UI dynamically based on the provided ContentModel.

Example Response Handling:

LMChatClient.shared.searchConversation(request: request) { result in
switch result {
case .success(let response):
let searchResults = response.conversations.map {
LMChatSearchConversationMessageCell.ContentModel(
chatroomID: $0.chatroomID,
messageID: $0.messageID,
chatroomName: $0.chatroomName,
message: $0.message,
senderName: $0.senderName,
date: $0.date,
isJoined: $0.isJoined,
highlightedText: "searchQuery",
userImageUrl: $0.userImageUrl
)
}
// Reload table view with searchResults
case .failure(let error):
print("Error fetching search results: \(error.localizedDescription)")
}
}