Skip to main content

Overview

MessageList is a Composite Component that displays a list of messages and effectively manages real-time operations. It includes various types of messages such as Text Messages, Media Messages, Stickers, and more. MessageList is primarily a list of the base component MessageBubble. The MessageBubble Component is utilized to create different types of chat bubbles depending on the message type.

Usage

Integration

The following code snippet illustrates how you can directly incorporate the MessageList component.
To retrieve messages for a specific entity, you must associate it with either a User or Group object.

Actions

Actions dictate how a component functions. They are divided into two types: Predefined and User-defined. You can override either type, allowing you to tailor the behavior of the component to fit your specific needs.
1. onThreadRepliesClick
onThreadRepliesClick is triggered when you click on the thread indicator of message bubble. The onThreadRepliesClick action doesn’t have a predefined behavior. You can override this action using the following code snippet.

2. onReactionClick
onReactionClick is triggered when you click on a reaction on a message bubble.

3. onReactionListItemClick
onReactionListItemClick is triggered when you click on the list item of CometChatReactionList on a message bubble.

4. set(onError:)
This method proves helpful when a user needs to customize the action taken upon encountering an error in CometChatMessageList.

5. set(onEmpty:)
This set(onEmpty:) method is triggered when the message list is empty in CometChatMessageList.

6. setOnLoad
This set(onLoad:) method is triggered when messages are successfully loaded in CometChatMessageList.

Filters

You can adjust the MessagesRequestBuilder in the MessageList Component to customize your message list. Numerous options are available to alter the builder to meet your specific needs. For additional details on MessagesRequestBuilder, please visit MessagesRequestBuilder. In the example below, we are applying a filter to the messages based on a search substring and for a specific user. This means that only messages that contain the search term and are associated with the specified user will be displayed
The following parameters in messageRequestBuilder will always be altered inside the message list
  1. UID
  2. GUID
  3. types
  4. categories
Ensure to include the uid and name of the User in the implementation.

Events

Events are emitted by a Component. By using event you can extend existing functionality. Being global events, they can be applied in Multiple Locations and are capable of being Added or Removed. The MessageList Component does not emit any events of its own.

Customization

To fit your app’s design requirements, you can customize the appearance of the conversation component. We provide exposed methods that allow you to modify the experience and behavior according to your specific needs.

Style

Using Style you can customize the look and feel of the component in your app, These parameters typically control elements such as the color, size, shape, and fonts used within the component.
1. MessageList Style
To customize the appearance, you can assign a MessageListStyle object to the MessageList component Global level styling
Instance level styling
List of properties exposed by MessageListStyle

Functionality

These are a set of small functional customizations that allow you to fine-tune the overall experience of the component. With these, you can change text, set custom icons, and toggle the visibility of UI elements. Below is a list of customizations along with corresponding code snippets

Advance

For advanced-level customization, you can set custom views to the component. This lets you tailor each aspect of the component to fit your exact needs and application aesthetics. You can create and define your views, layouts, and UI elements and then incorporate those into the component.

Date Time Formatter

The CometChatMessageList component supports full customization of how date and time are displayed using the CometChatDateTimeFormatter. This enables developers to localize, format, or personalize the date and time strings shown next to each message such as “Today”, “Yesterday”, “12:45 PM”, etc.
  1. Component-Level (Global)
  1. Instance-Level (Local)
Available closures
Each closure receives a timestamp (Int, representing UNIX time) and must return a String representing the formatted time.

Set HeaderView

You can set custom headerView to the Message List component using the following method.
Following is the code of CustomHeaderView - UIView Class

Set FooterView

You can set custom footerView to the Message List component using the following method. Example
Following is the code of CustomFooterView UIView Class

Set DateSeparatorPattern

You can modify the date pattern of the message list date separator to your requirement using setDateSeparatorPattern(). This method accepts a function with a return type String. Inside the function, you can create your own pattern and return it as a String. Example
Ensure to pass and present cometChatMessages. If a navigation controller is already in use, utilize the pushViewController function instead of directly presenting the view controller.

SetDatePattern

You can modify the date pattern to your requirement using .set(datePattern:). This method accepts a function with a return type String. Inside the function, you can create your own pattern and return it as a String. Example

SetTimePattern

You can modify the date pattern to your requirement using .set(timePattern:). This method accepts a function with a return type String. Inside the function, you can create your own pattern and return it as a String. Example

SetTextFormatters

This functionality dynamically assigns a list of text formatters. If a custom list is provided, it uses that list. Otherwise, it gracefully falls back to the default text formatters retrieved from the data source for seamless integration. Example This code customizes a CometChat text formatter to identify and style the word “sure”, with handling options for interactions like string search, scrolling, and item clicks. The custom formatter is then applied to CometChat messages.
Swift
Demonstration:

SetTemplate and AddTemplate

CometChatMessageTemplate is a pre-defined structure for creating message views that can be used as a starting point or blueprint for creating message views often known as message bubbles. For more information, you can refer to CometChatMessageTemplate.

SetLoadingView

You can set a custom loading view using .set(loadingView:). This method accepts a UIView to display while data is being fetched.

SetErrorView

You can customize the error view using .set(errorView:). This method accepts a UIView that appears when an error occurs.

SetEmptyView

You can customize the empty state view using .set(emptyView:). This method accepts a UIView that appears when no conversations are available.

To ensure that the MessageList is properly configured, passing the controller is mandatory.
  • Swift

Ensure to pass and present cometChatMessages. If a navigation controller is already in use, utilize the pushViewController function instead of directly presenting the view controller.