> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-platform-docs-release.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Users With Messages

> Users With Messages — CometChat documentation.

## Overview

`CometChatUsersWithMessages` is a [Composite Component](/ui-kit/ios/v4/components-overview#composite-components) that seamlessly merges the functionalities of both the [Users](/ui-kit/ios/v4/users) and [Messages](/ui-kit/ios/v4/messages) modules. It empowers users to effortlessly navigate to any individual's chat window by simply clicking on their respective **list item** in the user list.

Additionally, `CometChatUsersWithMessages` inherits and encompasses all attributes available within the `CometChatUsers` module, ensuring a comprehensive user experience.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-platform-docs-release/DwRLpXRUatit-uQA/images/8192fe8b-uwm_overview_screens-56188ae39e333951f43440de3821c72f.png?fit=max&auto=format&n=DwRLpXRUatit-uQA&q=85&s=077c4f83ad3e51739fceafbacf6c8aaf" width="4768" height="3120" data-path="images/8192fe8b-uwm_overview_screens-56188ae39e333951f43440de3821c72f.png" />
</Frame>

| Components                          | Description                                                                                                                                                                                                                                                                                                              |
| ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [Users](/ui-kit/ios/v4/users)       | `Users` serves as a standalone component designed to establish a screen displaying a list of `users`, providing them with the capability to search for specific individuals. This component operates as a container, inheriting from `CometChatListBase`, and serves as a wrapper for the `CometChatUserList` component. |
| [Messages](/ui-kit/ios/v4/messages) | `Messages` presents the chat interface for both individual `users` and `group` entities. It exhibits a message list containing all interactions where the loggedInUser has sent or received messages from any of these entities.                                                                                         |

## Usage

### Integration

Since `CometChatUsersWithMessages` is a view controller, it can be launched either by a button click or through any event's trigger. It inherits all the customizable properties and methods of `CometChatUsers.`

**View Controller**: To use **CometChatUsersWithMessages** in your `view controller`, use the following code snippet.

```swift view controller theme={null}
let cometChatUsersWithMessages = CometChatUsersWithMessages()
let naviVC = UINavigationController(rootViewController: cometChatUsersWithMessages)
self.present(naviVC, animated: true)
```

***

### Actions

[Actions](/ui-kit/ios/v4/components-overview#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. SetOnItemClick

The `setOnItemClick` method is used to override the onClick behavior in **CometChatUsersWithMessages**. By default, this action has a predefined behavior which navigates to the **messages**. However, you have the flexibility to override this event and tailor it to suit your needs using the following code snippet.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let cometChatUsersWithMessages = CometChatUsersWithMessages()
        .setOnItemClick { user, indexPath in
            //Perform Your Actions
    }
    ```
  </Tab>
</Tabs>

##### 2. SetOnItemLongClick

This method `setOnItemLongClick`, empowers users to customize long-click actions within **CometChatUsersWithMessages**, offering enhanced functionality and interaction possibilities.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let cometChatUsersWithMessages = CometChatUsersWithMessages()
        .setOnItemLongClick { user, indexPath in
             //Perform Your Actions
    }
    ```
  </Tab>
</Tabs>

##### 3. SetOnBack

This method allows users to override the onBack Pressed behavior in **CometChatUsersWithMessages** by utilizing the `setOnBack` , providing customization options for handling the back action.

By default, this action has a predefined behavior: it simply dismisses the current view controller. However, the flexibility of CometChat UI Kit allows you to override this standard behavior according to your application's specific requirements. You can define a custom action that will be performed instead when the back button is pressed.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let cometChatUsersWithMessages = CometChatUsersWithMessages()
        .setOnBack {
        //Perform Your Actions
    }
    ```
  </Tab>
</Tabs>

##### 4. onError

This method `setOnError`, allows users to override error handling within **CometChatUsersWithMessages**, providing greater control over error responses and actions.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let cometChatUsersWithMessages = CometChatUsersWithMessages()
        .setOnError { error in
        //Perform Your Action
    }
               
    ```
  </Tab>
</Tabs>

### Filters

**Filters** allow you to customize the data displayed in a list within a Component. You can filter the list based on your specific criteria, allowing for a more customized. Filters can be applied using RequestBuilders of Chat SDK.

While the UsersWithMessages component does not have filters, its components do, For more detail on individual filters of its component refer to [Users Filters](/ui-kit/ios/v4/users)[Messages Filters](/ui-kit/ios/v4/messages)

By utilizing the [Configurations](#configurations) object of its components, you can apply filters.

In the following **example**, we're sorting `Users` by `UID's` and setting the `limit` to 10 using the `usersRequestBuilder`.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let usersRequestBuilder = UsersRequest.UsersRequestBuilder(limit: 20).set(UIDs: ["emma-uid"])
                            
    let cometChatUsersWithMessages = CometChatUsersWithMessages(usersRequestBuilder: usersRequestBuilder)
    let naviVC = UINavigationController(rootViewController: cometChatUsersWithMessages)
    self.present(naviVC, animated: true)
    ```
  </Tab>
</Tabs>

<Tip>
  make sure to `import CometChatSDK`
</Tip>

***

### Events

[Events](/ui-kit/ios/v4/components-overview#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 `UsersWithMessages` does not produce any events but its component does.

***

## Customization

To fit your app's design requirements, you have the ability to customize the appearance of the UsersWithMessages 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. UsersWithMessages Style 🛑

You can set the `UsersWithMessagesStyle` to the `UsersWithMessages` Component to customize the styling.

**Example**

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
     let usersWithMessagesStyle = UsersWithMessagesStyle()
        .set(messageTextColor: .red)
        .set(messageTextFont: .italicSystemFont(ofSize: 6))
        .set(background: .yellow)
        .set(borderColor: .green)

    let usersWithMessagesConfiguration = UsersWithMessagesConfiguration()
        .set(style: usersWithMessagesStyle)

    let cometChatUsersWithMessages = CometChatUsersWithMessages()
    ```
  </Tab>
</Tabs>

You can also customize its component styles. For more details on individual component styles, you can refer [Users Styles](/ui-kit/ios/v4/users) and [Messages Styles](/ui-kit/ios/v4/messages).

Styles can be applied to SubComponents using their respective configurations.

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

UsersWithMessages component does not have any available functionality.

***

### 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 own views, layouts, and UI elements and then incorporate those into the component.

By utilizing the [Configuration](#configurations) object of each component, you can apply advanced-level customizations to the `UsersWithMessages`.

**Example**

```csharp theme={null}
// Create an object of UsersConfiguration
let usersConfiguration = UsersConfiguration()

//pass your custom error view
usersConfiguration.set(errorView: UIView)
```

**Usage**

Utilize the provided code snippet to instantiate a `CometChatUsersWithMessages` component and configure it with a `UsersConfiguration` object. This ensures seamless integration and optimal functionality within your application.

```csharp theme={null}
 let cometChatUsersWithMessages = CometChatUsersWithMessages()
    .set(usersConfiguration: usersConfiguration)
```

To find all the details on individual Component advance customization you can refer, [Users Advance](/ui-kit/ios/v4/users#advanced) and [Messages Advance](/ui-kit/ios/v4/messages#advanced).

UsersWithMessages uses advanced-level customization of both Users & Messages components to achieve its default behavior.

1. UsersWithMessages utilizes the [SetMenu](/ui-kit/ios/v4/users) function of the `Users` subcomponent to navigate the [User](/ui-kit/ios/v4/users) to [Messages](/ui-kit/ios/v4/messages)

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-platform-docs-release/Ywe31WBX2s6eASE2/images/b7ec35f8-uwm_advanced_2_screens-0c0eee0877d03561afd59f690ff481b3.png?fit=max&auto=format&n=Ywe31WBX2s6eASE2&q=85&s=fac3adbbd0963dc79302fafd0445c964" width="4948" height="3120" data-path="images/b7ec35f8-uwm_advanced_2_screens-0c0eee0877d03561afd59f690ff481b3.png" />
</Frame>

2. UsersWithMessages utilizes the [SetMenu](/ui-kit/ios/v4/users) function of the `Messages` subcomponent to navigatefrom [Messages](/ui-kit/ios/v4/messages) to Details.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-platform-docs-release/kL0xzIA8wp4kGECR/images/09d0ad3d-uwm_advanced_1_screens-fbad571fb1172a2d923a0844c5673f99.png?fit=max&auto=format&n=kL0xzIA8wp4kGECR&q=85&s=816dec290aabca08188500cbb7d5d261" width="4921" height="3120" data-path="images/09d0ad3d-uwm_advanced_1_screens-fbad571fb1172a2d923a0844c5673f99.png" />
</Frame>

<Warning>
  When you override `.setMenu()`, the default behavior of **UsersWithMessages** will also be overridden.
</Warning>

## Configurations

[Configurations](/ui-kit/ios/v4/components-overview#configurations) offer the ability to customize the properties of each component within a Composite Component.

**UsersWithMessages** has `Users` and `Messages` component. Hence, each of these components will have its individual \`Configuration\`\`.

* `Configurations` expose properties that are available in its individual components.

#### Users

You can customize the properties of the Users component by making use of the UsersConfiguration. You can accomplish this by employing the `.set(usersConfiguration: usersConfiguration)` method as demonstrated below:

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let usersConfiguration = UsersConfiguration()
    ```
  </Tab>
</Tabs>

**Usage**

The **UsersConfiguration** is utilized within a widget housing `CometChatUsersWithMessages` as a child component. To configure CometChatUsersWithMessages, simply provide the usersConfiguration object using the `.set(usersConfiguration:)` method. This facilitates seamless customization and integration of user-specific settings within the `CometChatUsersWithMessages` component.

```csharp theme={null}
let cometChatUsersWithMessages = CometChatUsersWithMessages()
    .set(usersConfiguration: usersConfiguration)
```

All exposed properties of `UsersConfiguration` can be found under [Users](/ui-kit/ios/v4/users). Properties marked with the <Tooltip tip="Not available">🛑</Tooltip> symbol are not accessible within the Configuration Object.

**Example**

Let's say you want to change the style of the Users subcomponent and, in addition, you only want to display users with offline status.

You can modify the style using the `UsersStyle` method and filter the list with the `UsersRequestBuilder` method.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-platform-docs-release/xfvNasJe6EBsJZG-/images/a910f581-uwm_config_users_screens-377f9fef7c0fa1056937a340cf0ddf77.png?fit=max&auto=format&n=xfvNasJe6EBsJZG-&q=85&s=6dd0c013c5ebcfda10487a4b5df5b41a" width="4948" height="3120" data-path="images/a910f581-uwm_config_users_screens-377f9fef7c0fa1056937a340cf0ddf77.png" />
</Frame>

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let usersStyle = UsersStyle()
        .set(background: .lightGray.withAlphaComponent(0.8))
            
    let listItemStyle = ListItemStyle()
        .set(background: .lightGray.withAlphaComponent(0.4))
            
    let usersRequestBuilder = UsersRequest.UsersRequestBuilder(limit: 5).set(status: .offline)

    let cometChatUsersWithMessages = CometChatUsersWithMessages(usersRequestBuilder: usersRequestBuilder)
    .set(listItemStyle: listItemStyle)
    cometChatUsersWithMessages.set(usersStyle: usersStyle)

    let naviVC = UINavigationController(rootViewController: cometChatUsersWithMessages)
    self.present(naviVC, animated: true)
    ```
  </Tab>
</Tabs>

<Tip>
  make sure to `import CometChatSDK`
</Tip>

***

#### Messages

You can customize the properties of the Messages component by making use of the `messagesConfiguration`. You can accomplish this by employing the `messagesConfiguration` as demonstrated below:

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let messagesConfiguration = MessagesConfiguration()
    ```
  </Tab>
</Tabs>

All exposed properties of `MessagesConfiguration` can be found under [Messages](/ui-kit/ios/v4/messages). Properties marked with the <Tooltip tip="Not available">🛑</Tooltip> symbol are not accessible within the Configuration Object.

**Example**

Let's say you want to change the style of the Messages subcomponent and, in addition, you want to hide message composer.

You can modify the style using the `messagesStyle` method and hide using `hide(messageComposer: bool)` method.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-platform-docs-release/Be6Mu14MqhiP8v4-/images/eb4b6eb6-uwm_config_messages_screens-59c4648d355dd8b6b72e1e1450ddd359.png?fit=max&auto=format&n=Be6Mu14MqhiP8v4-&q=85&s=b62b66fff0c3c1193ed5a3fa1d6f4ee0" width="4929" height="3120" data-path="images/eb4b6eb6-uwm_config_messages_screens-59c4648d355dd8b6b72e1e1450ddd359.png" />
</Frame>

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let cometChatCornerStyle = CometChatCornerStyle.init(cornerRadius: 15)

    let messagesStyle = MessagesStyle()
        .set(cornerRadius: cometChatCornerStyle)
        .set(borderColor: .systemPurple)
        .set(borderWidth: 2)

    let messagesConfiguration = MessagesConfiguration()
        .set(messagesStyle: messagesStyle)
        .hide(messageComposer: true)

    let cometChatUsersWithMessages = CometChatUsersWithMessages()
        .hide(search: true)
        .set(messagesConfiguration: messagesConfiguration)
    ```
  </Tab>
</Tabs>
