> ## Documentation Index
> Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Message Privately

> Start a one-to-one chat from a group message or a profile in a CometChat iOS UI Kit v6 app.

> [accordion] AI Integration Quick Reference
>
> ```json theme={null}
> {
>   "products": ["CometChatSwiftUI", "CometChatUIKit"],
>   "components": ["CometChatMessageList", "CometChatMessageHeader", "CometChatMessageComposer"],
>   "option": "Message Privately — in a group chat's long-press menu, on other people's messages",
>   "callback": "onMessagePrivately: (User) -> Void (SwiftUI) / set(onMessagePrivately:) (UIKit)",
>   "hide": "hideMessagePrivatelyOption",
>   "note": "Without the callback the option does nothing: the Kit has no chat screen to open."
> }
> ```

"Message Privately" takes someone from a group conversation — or from a profile — straight into
a one-to-one chat with them.

## Overview

* In a **group** chat, the message list's long-press menu offers **Message Privately** on
  messages other people sent.
* Choosing it fetches the sender and hands you the `User`. You open your one-to-one chat
  screen with it.
* The same screen opens from a profile or a users list — anywhere you hold a `User`.
* The conversation appears in Conversations once the first message is sent.

## Prerequisites

* The Kit is set up and a user is logged in — see [Getting Started](https://www.cometchat.com/docs/ui-kit/ios/v6/getting-started-swiftui.md).
* A one-to-one chat screen: `CometChatMessageHeader`, `CometChatMessageList` and
  `CometChatMessageComposer` given a `User`.

## Components

| Component | Role |
| - | - |
| `CometChatMessageList` | Offers the option in a group chat and calls you with the sender. |
| `CometChatMessageHeader` / `List` / `Composer` | Your one-to-one chat screen, given the `User`. |
| `CometChatSession.sendTextMessage(_:)` | Optional: a first message, so the chat shows in Conversations. |

## Integration Steps

### 1. Handle Message Privately in the group chat

> [tab] SwiftUI
>
> ```swift GroupChatView.swift theme={null}
> import SwiftUI
> import CometChatSwiftUI
> import CometChatSDK
>
> struct PrivateChatRoute: Identifiable, Hashable {
>     let user: CometChatSDK.User
>     var id: String { user.uid ?? "" }
>     static func == (lhs: PrivateChatRoute, rhs: PrivateChatRoute) -> Bool { lhs.id == rhs.id }
>     func hash(into hasher: inout Hasher) { hasher.combine(id) }
> }
>
> struct GroupChatView: View {
>     let group: CometChatSDK.Group
>     @State private var privateChat: PrivateChatRoute?
>
>     var body: some View {
>         // … the header and the composer as bars over the list …
>         CometChatMessageList(group: group, onMessagePrivately: { sender in
>             privateChat = PrivateChatRoute(user: sender)
>         })
>         .navigationDestination(item: $privateChat) { route in
>             OneToOneChatView(user: route.user)
>         }
>     }
> }
>
> struct OneToOneChatView: View {
>     let user: CometChatSDK.User
>
>     var body: some View {
>         // … the header and the composer as bars over the list …
>         CometChatMessageList(user: user)
>     }
> }
> ```

> [tab] UIKit
>
> ```swift GroupChatViewController.swift theme={null}
> import UIKit
> import CometChatUIKit
> import CometChatSDK
>
> final class GroupChatViewController: UIViewController {
>     let group: CometChatSDK.Group
>     let messageList = CometChatMessageList()
>
>     init(group: CometChatSDK.Group) {
>         self.group = group
>         super.init(nibName: nil, bundle: nil)
>     }
>     required init?(coder: NSCoder) { fatalError() }
>
>     override func viewDidLoad() {
>         super.viewDidLoad()
>         messageList.set(group: group)
>         messageList.set(onMessagePrivately: { [weak self] sender in
>             self?.navigationController?.pushViewController(OneToOneChatViewController(user: sender), animated: true)
>         })
>         // … add the header, the list and the composer …
>     }
> }
>
> final class OneToOneChatViewController: UIViewController {
>     let user: CometChatSDK.User
>     let header = CometChatMessageHeader()
>     let messageList = CometChatMessageList()
>     let composer = CometChatMessageComposer()
>
>     init(user: CometChatSDK.User) {
>         self.user = user
>         super.init(nibName: nil, bundle: nil)
>     }
>     required init?(coder: NSCoder) { fatalError() }
>
>     override func viewDidLoad() {
>         super.viewDidLoad()
>         header.set(user: user)
>         messageList.set(user: user)
>         composer.set(user: user)
>         // … lay the three out …
>     }
> }
> ```

Host the header and the composer over the list as [Conversation List + Message View](https://www.cometchat.com/docs/ui-kit/ios/v6/conversation-message-view.md#step-2-set-up-the-message-screen) shows.

> [!NOTE]
>
> Without `onMessagePrivately` the option still shows but does nothing — the Kit has no chat
> screen of its own to open. Hide it if you do not handle it.

### 2. Open the same chat from a profile or a list

Anywhere you hold a `User`, push the same screen. From the users list:

> [tab] SwiftUI
>
> ```swift theme={null}
> struct PeopleView: View {
>     @State private var chat: PrivateChatRoute?
>
>     var body: some View {
>         CometChatUsers(onItemClick: { user in chat = PrivateChatRoute(user: user) })
>     }
> }
>
> struct PrivateChatRoute: Identifiable {
>     let user: CometChatSDK.User
>     var id: String { user.uid ?? "" }
> }
> ```

> [tab] UIKit
>
> ```swift theme={null}
> let users = CometChatUsers()
> users.set(onItemClick: { user, _ in
>     print("open a chat with", user.uid ?? "")
> })
> ```

### 3. (Optional) Send a first message

A one-to-one conversation shows in Conversations only once it has a message. To surface it
straight away, send one through the Kit, so the open chat and Conversations both update:

> [tab] SwiftUI
>
> ```swift theme={null}
> let hello = TextMessage(receiverUid: "UID", text: "👋", receiverType: .user)
> try await CometChatSession.sendTextMessage(hello)
> ```

> [tab] UIKit
>
> ```swift theme={null}
> let hello = TextMessage(receiverUid: "UID", text: "👋", receiverType: .user)
> CometChatUIKit.sendTextMessage(message: hello) { result in
>     if case .failure(let error) = result { print(error.message) }
> }
> ```

## Implementation Flow

| Step | Action | Where |
| - | - | - |
| 1 | The user long-presses someone's message and chooses **Message Privately** | the group chat's message list |
| 2 | The list fetches the sender and calls your handler | `onMessagePrivately` |
| 3 | You open the one-to-one chat with that `User` | your navigation |
| 4 | (Optional) A first message surfaces the chat in Conversations | `CometChatSession.sendTextMessage(_:)` |

## Customization Options

Hide the option:

> [tab] SwiftUI
>
> ```swift theme={null}
> CometChatMessageList(group: guideGroup, hideMessagePrivatelyOption: true)
> ```

> [tab] UIKit
>
> ```swift theme={null}
> let list = CometChatMessageList()
> list.hideMessagePrivatelyOption = true
> ```

## Edge Cases

| Case | Behaviour |
| - | - |
| A one-to-one chat | The option is not offered — it is already private. |
| Your own message | The option is not offered. |
| You blocked the sender | The chat opens; hide the composer as in [Block / Unblock User](https://www.cometchat.com/docs/ui-kit/ios/v6/guide-block-unblock-user.md). |
| The sender cannot be fetched | Your handler is not called. |

## Feature Matrix

| Feature | SwiftUI | UIKit |
| - | - | - |
| Handle the option | `onMessagePrivately:` | `set(onMessagePrivately:)` |
| Hide the option | `hideMessagePrivatelyOption: true` | `hideMessagePrivatelyOption = true` |
| Open the chat | `CometChatMessageHeader/List/Composer(user:)` | `set(user:)` on each |
| First message | `CometChatSession.sendTextMessage(_:)` | `CometChatUIKit.sendTextMessage(message:)` |

## Next Steps

> [card] [Message List](https://www.cometchat.com/docs/ui-kit/ios/v6/message-list.md)
>
> The message menu and its options

> [card] [New Chat](https://www.cometchat.com/docs/ui-kit/ios/v6/guide-new-chat.md)
>
> Start a chat from users and groups

> [card] [Users](https://www.cometchat.com/docs/ui-kit/ios/v6/users.md)
>
> The users list

> [card] [All Guides](https://www.cometchat.com/docs/ui-kit/ios/v6/guide-overview.md)
>
> Browse the other guides


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.