> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-feature-react-native-sdk-quotedmessage-a.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Message Privately

Enable users to start a private one-on-one chat with a group member directly from a group chat screen using CometChat’s UIKit for iOS.

## Overview

The **Message Privately** feature allows users to long-press a message in a group chat and select **Message Privately** to transition into a private conversation with the original sender. This streamlines side discussions and follow-ups without manual user searches.

## Prerequisites

* UIKit-based iOS project.
* CometChat UIKit for iOS v5 installed via CocoaPods or Swift Package Manager.
* Valid CometChat **App ID**, **Region**, and **Auth Key**.
* Functional group chat via `CometChatMessageList`.
* A one-on-one chat screen (`CometChatMessages` or custom) and navigation flow configured.

## Components

| Component                                   | Role                                                              |
| :------------------------------------------ | :---------------------------------------------------------------- |
| `CometChatMessageList`                      | Displays group messages; handles long-press to show options.      |
| `CometChatMessageOption`                    | Defines the **Message Privately** option in the context menu.     |
| `MessageDataSource`                         | Supplies the `messagePrivatelyOption` in the options array.       |
| `CometChatMessageListViewModel`             | Manages UI state, including `hideMessagePrivatelyOption`.         |
| `CometChatMessages`                         | Entry point for rendering or pushing the private chat interface.  |
| `CometChatUIKit.getUser(uid:)`              | Retrieves the `User` object for the selected message sender.      |
| `CometChatUIKit.getConversationWith(user:)` | Creates or fetches the 1-on-1 conversation instance.              |
| `UIViewController` (Navigation)             | Pushes or presents the private chat screen (`CometChatMessages`). |

## Integration Steps

### 1. Control Option Visibility via ViewModel

Dynamically show or hide **Message Privately** based on app context.

```swift theme={null}
public var hideMessagePrivatelyOption: Bool = false {
    didSet {
        viewModel.hideMessagePrivatelyOption = hideMessagePrivatelyOption
    }
}
```

**File reference:**\
[`CometChatMessageList.swift`](https://github.com/cometchat/cometchat-uikit-ios/blob/v5/CometChatUIKitSwift/Components/Message%20List/CometChatMessageList.swift)

Ensures the option only appears when appropriate (e.g., user permissions).

### 2. Handle Private Chat Navigation

Retrieve the sender and initiate a private 1-on-1 chat.

```swift theme={null}
if let uid = selectedMessage.sender?.uid {
    CometChatUIKit.getUser(uid: uid) { user in
        CometChatUIKit.getConversationWith(user: user) { conversation in
            let messagesVC = CometChatMessages(conversation: conversation)
            navigationController?.pushViewController(messagesVC, animated: true)
        }
    }
}
```

**File reference:**\
[`CometChatMessageList.swift`](https://github.com/cometchat/cometchat-uikit-ios/blob/v5/CometChatUIKitSwift/Components/Message%20List/CometChatMessageList.swift)

Automates transition from group context to private conversation.

## Implementation Flow

1. Long-press a group message in `CometChatMessageList`.
2. Options menu appears with **Message Privately**.
3. User taps **Message Privately**.
4. App fetches `User` via `CometChatUIKit.getUser(uid:)`.
5. Retrieves or creates conversation via `CometChatUIKit.getConversationWith(user:)`.
6. Pushes `CometChatMessages` onto the navigation stack.

## Customization Options

* **Styling:** Override `CometChatMessageOption` UI (icons, fonts, colors).
* **Availability:** Control via `viewModel.hideMessagePrivatelyOption`.
* **Extend Options:** Add additional actions in `MessageDataSource.getMessageOptions(for:)`.

## Filtering & Edge Cases

* **Blocked Users:** Hide option if the sender is in block list.
* **Existing Conversations:** Reuse existing thread via `getConversationWith`.
* **Unavailable Users:** Skip option or show disabled state if user data missing.

## Error Handling & Blocked-User Handling

* **Block State:** Catch errors from `getUser`/`getConversationWith` and alert user.
* **Network Failures:** Present retry or toast on navigation errors.
* **Invalid Data:** Disable option if `sender.uid` is nil.

## Optional Context-Specific Notes

* Only available in **group chat** screens (`CometChatMessageList`).
* Hidden automatically in direct/private chat views.

## Summary / Feature Matrix

| Feature                      | Component / Method                     | File(s)                                                                                                                                                                                                                                                                                                                                   |
| :--------------------------- | :------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Show options menu            | `getMessageOptions(for:)`              | [`MessageDataSource.swift`](https://github.com/cometchat/cometchat-uikit-ios/blob/v5/CometChatUIKitSwift/Components/Shared/Framework/MessagesDataSource.swift)                                                                                                                                                                            |
| Toggle **Message Privately** | `viewModel.hideMessagePrivatelyOption` | [`CometChatMessageList.swift`](https://github.com/cometchat/cometchat-uikit-ios/blob/v5/CometChatUIKitSwift/Components/Message%20List/CometChatMessageList.swift),<br />[`MessageListViewModel.swift`](https://github.com/cometchat/cometchat-uikit-ios/blob/v5/CometChatUIKitSwift/Components/Message%20List/CometChatMessageList.swift) |

<CardGroup>
  <Card title="Full Sample App">
    Explore this feature in the CometChat SampleApp:
    [GitHub → SampleApp](https://github.com/cometchat/cometchat-uikit-ios/tree/v5/SampleApp)
  </Card>

  <Card title="UIKit Source Code">
    Browse the message list component:
    [GitHub → CometChatMessageList.swift](https://github.com/cometchat/cometchat-uikit-ios/blob/v5/CometChatUIKitSwift/Components/Message%20List/CometChatMessageList.swift)
  </Card>
</CardGroup>
