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 requiring manual user searches.Prerequisites
Before implementing this feature, ensure you have:- Completed Getting Started setup
- CometChat UIKit 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 (
CometChatMessagesor custom) and navigation flow configured
Components
| Component | Description |
|---|---|
CometChatMessageList | Displays group messages and 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
Step 1: Control Option Visibility via ViewModel
Dynamically show or hide Message Privately based on app context:CometChatMessageList.swift
Step 2: Handle Private Chat Navigation
Retrieve the sender and initiate a private 1-on-1 chat:CometChatMessageList.swift
Implementation Flow
| Step | Action |
|---|---|
| 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
OverrideCometChatMessageOption UI elements:
Availability
Control visibility via the view model:Extend Options
Add additional actions inMessageDataSource.getMessageOptions(for:):
Edge Cases
| Scenario | Handling |
|---|---|
| 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 is missing |
Error Handling
| Error Type | Solution |
|---|---|
| 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 |
Additional Notes
- This feature is only available in group chat screens (
CometChatMessageList) - The option is hidden automatically in direct/private chat views
Feature Matrix
| Feature | Component / Method | File(s) |
|---|---|---|
| Show options menu | getMessageOptions(for:) | MessageDataSource.swift |
| Toggle Message Privately | viewModel.hideMessagePrivatelyOption | CometChatMessageList.swift, MessageListViewModel.swift |
Related Components
- Message List - Display messages in conversations
- Users - Display user list
- Conversations - Display conversation list