Single Chat/ Group Chat

Initialize#

You start building the chat service by calling the MFUIChatViewParentController class. It uses MFUIUserMessageCell class to display the messages in chat.

The MFUIChatViewParentController should get initialised with the recent chat obtained from the previous screen.

open func chatListModule(_ listComponent: MFUIRecentChatListModule.List,
didSelectRowAt indexPath: IndexPath) {
guard let chat = self.viewModel?.recentChatList[indexPath.row] else { return }
let vc = MFUIChatViewParentController.init(chat: chat)
self.navigationController?.pushViewController(vc, animated: true)
}

Usage#

The following items are key elements of MFUIChatViewParentController that are used to create a functional chat.

Module components#

In the MFUIChatViewParentController class, MFUIChatViewParentModule and its components are used to create and display the chat view. The module is composed of three components: headerComponent, listComponent, and inputComponent.

Property nameType
headerComponentMFUIChatViewParentModule.Header
listComponentMFUIChatViewParentModule.List
inputComponentMFUIChatViewParentModule.Input

Header Component#

The headerComponent includes a chat title (UserName from the RecentChat), a back button that takes the user to the previous view. Each property corresponds to the elements in the navigation bar of the view controller.

The following table shows the parameters of the configure method of the headerComponent.

Parameter nameType
delegateMFUIChatViewParentModuleHeaderDelegate
themeMFChatTheme

List Component#

The listComponent shows a list of all messages in the chat. The following table shows the parameters of the configure method of the listComponent.

Parameter nameType
delegateMFUIChatViewParentModuleListDelegate
dataSourceMFUIChatViewParentModuleListDataSource
themeMFChatTheme

Input Component#

The inputComponent shows the input field of a chat where users can type and send their messages. The following table shows the parameters of the configure method of the inputComponent.

Parameter nameType
delegateMFUIChatViewParentModuleInputDelegate
dataSourceMFUIChatViewParentModuleInputDataSource
themeMFChatTheme

View Model#

The MFUIChatViewParentController class uses a view model that is a type of the MFUIChatViewModel class. The view model is created in the initializer of the view controller through the createViewModel(chat:startingPoint:showIndicator:) method. When the view model object is created, it retrieves message list data from Chat SDK to the view controller and updates the view through the baseChatViewModel(_:didChangeMessageList:needsToReload:initialLoad) event.

The following table shows the parameters list of the createViewModel method

Parameter nameType
chatRecentChat
startingPointInt64
showIndicatorBool