Message Cell
Overview
The LMChatMessageCell
is a versatile table view cell designed to display various types of chat messages. It serves as a base class for specific message type cells and provides core functionality for message display, user interactions, and customization options.
Functionality
Protocols
LMChatMessageCellDelegate
onClickReactionOfMessage(reaction:indexPath:)
: Called when a user interacts with a message reaction.onClickAttachmentOfMessage(url:indexPath:)
: Triggered when an attachment in the message is tapped.onClickGalleryOfMessage(attachmentIndex:indexPath:)
: Handles taps on gallery items within a message.onClickReplyOfMessage(indexPath:)
: Called when the reply action is initiated for a message.didTappedOnSelectionButton(indexPath:)
: Triggered when the message selection button is tapped.onClickOfSeeMore(for:indexPath:)
: Handles the "See More" action for truncated messages.didCancelAttachmentUploading(indexPath:)
: Called when an attachment upload is cancelled.didRetryAttachmentUploading(indexPath:)
: Triggered when retrying a failed attachment upload.didTapOnProfileLink(route:)
: Handles taps on profile links within messages.
Protocols Implemented
LMAttachmentLoaderViewDelegate
: Handles attachment uploading cancellation.LMAttachmentUploadRetryViewDelegate
: Manages retry attempts for failed uploads.LMChatMessageContentViewDelegate
: Processes user interactions with message content.
UI Components
chatMessageView
: An instance ofLMChatMessageContentView
that displays the message content.retryContainerStackView
: A stack view containing the retry button.retryButton
: A button for retrying failed message sends.selectedButton
: A button for message selection in multi-select mode.
Methods
setData(with:index:)
: Configures the cell with the provided data model and index path.updateSelection(data:)
: Updates the cell's selected state.retrySendMessage(_:)
: Handles retry attempts for failed message sends.tappedTextView(tapGesture:)
: Processes taps on text content, handling URL and route interactions.
Customization
CustomChatMessageCell.swift
class CustomChatMessageCell: LMChatMessageCell {
override func setupViews() {
super.setupViews()
// Add custom views here
}
override func setupAppearance() {
super.setupAppearance()
// Customize cell appearance here
}
override func setData(with data: ContentModel, index: IndexPath) {
super.setData(with: data, index: index)
// Add custom data configuration here
}
}
AppDelegate.swift
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
LMUIComponents.shared.chatMessageCell = CustomChatMessageCell.self
// ...
return true
}