Skip to main content

Overview

The Conversations is a Component, That shows all conversations related to the currently logged-in user,

Usage

Integration

As CometChatConversations is a custom view controller, it can be initiated either by tapping a button or through the trigger of any event. It offers multiple parameters and methods for tailoring its user interface.
swift
  • Integration (With Custom Request Builder)
During the initialization of CometChatConversations, users can provide this custom request builder.
swift
If a navigation controller is already in use, opt for the pushViewController method instead of presenting the view controller.

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. set(onItemClick:)
set(OnItemClick:) is triggered when you click on a ListItem of the Conversations component. This set(OnItemClick:) method proves beneficial when a user intends to customize the on-click behavior in CometChatConversations.

  1. set(OnItemLongClick:)
set(OnItemLongClick:) is triggered when you long press on a ListItem of the Conversations component. This set(OnItemLongClick:) method proves beneficial when a user intends to additional functionality on long press on list item in CometChatConversations.

3. set(onBack:)
This set(onBack:) method becomes valuable when a user needs to override the action triggered upon pressing the back button in CometChatConversations.

4. set(onSelection:)
The set(onSelection:) only gets trigger when selection mode is set to multiple of single. And this gets trigger on every selection, and returns the list of selected conversations.

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

6. set(onEmpty:)
This set(onEmpty:) method is triggered when the conversations list is empty in CometChatConversations.

7. setOnLoad
This set(onLoad:) gets triggered when a conversation list is fully fetched and going to displayed on the screen, this return the list of conversations to get displayed on the screen.

Filters

You can set ConversationsRequestBuilder in the Conversations Component to filter the conversation list. You can modify the builder as per your specific requirements with multiple options available to know more refer to ConversationRequestBuilder. You can set filters using the following parameters.
  1. Conversation Type: Filters on type of Conversation, User or Groups
  2. Limit: Number of conversations fetched in a single request.
  3. WithTags: Filter on fetching conversations containing tags
  4. Tags: Filters on specific Tag
  5. UserTags: Filters on specific User Tag
  6. GroupTags: Filters on specific Group Tag
If a navigation controller is already in use, opt for the pushViewController method instead of presenting the view controller.

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.
1. ConversationDeleted
This event will be emitted when the user deletes a conversation
Add Listener
Remove Listener

Customization

To align with your app’s design specifications, you have the flexibility to customize the appearance of the conversation component. We offer accessible methods that empower you to tailor the experience and functionality to meet your unique requirements.

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. Conversation Style
The CometChatConversation component allows developers to customize its appearance through the ConversationStyle class. This enables global-level or instance-specific styling. Global level styling
Instance level styling
List of properties exposed by ConversationStyle
2. Avatar Style
To apply customized styles to the Avatar component in the Conversations Component, you can use the following code snippet. For more information, visit Avatar Styles. Global level styling
Instance level styling
3. StatusIndicator Style
To apply customized styles to the Status Indicator component in the Conversations Component, you can use the following code snippet. For more information, visit Indicator Styles. Global level styling
Instance level styling
4. Badge Style
To apply customized styles to the Badge component in the Conversations Component, you can use the following code snippet. For more information, visit Badge Styles Global level styling
Instance level styling

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

Advanced

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 CometChatConversations 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 conversation—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.

SetTextFormatters

You can modify the text formatters by using .set(textFormatters:). This method accepts an array of CometChatTextFormatter, allowing you to apply multiple text formatters to the conversation text.
cometChatConversations.set(textFormatters: [CometChatTextFormatter])

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.
Demonstration

SetOptions

You can define custom options for each conversation using .set(options:). This method allows you to return an array of CometChatConversationOption based on the conversation object.

AddOptions

You can dynamically add options to conversations using .add(options:). This method lets you return additional CometChatConversationOption elements.

SetCustomSoundForMessages

You can customize the notification sound for incoming messages using .set(customSoundForMessages:). This method accepts a URL pointing to the audio file.

SetListItemView

With this function, you can assign a custom ListItem view to the Conversations Component.
Demonstration
You can create a CustomListItemView as a custom UIView. Which we will inflate in setListItemView()
swift

SetLeadingView

You can modify the leading view of a conversation cell using .set(leadingView:).
Demonstration
You can create a CustomLeadingView as a custom UIView. Which we will inflate in setLeadingView()

SetTitleView

You can customize the title view of a conversation cell using .set(titleView:).
Demonstration
You can create a CustomTitleView as a custom UIView. Which we will inflate in setTitleView()

SetTrailView

You can modify the trailing view of a conversation cell using .set(trailView:).
Demonstration
You can create a CustomTrailView as a custom UIView. Which we will inflate in setTrailView()

SetSubtitleView

You can customize the subtitle view for each conversation item to meet your requirements
Demonstration
You need to create a SubtitleView a custom UIView cocoa touch file and inflate it in the setSubtitleView apply function. Then, you can define individual actions depending on your requirements.
  • SubtitleView file should should appear as follows:
swift

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.