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 (CometChatMessagesor 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 messagePrivatelyOptionin 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 Userobject 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.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.CometChatMessageList.swift
Automates transition from group context to private conversation.
Implementation Flow
- Long-press a group message in CometChatMessageList.
- Options menu appears with Message Privately.
- User taps Message Privately.
- App fetches UserviaCometChatUIKit.getUser(uid:).
- Retrieves or creates conversation via CometChatUIKit.getConversationWith(user:).
- Pushes CometChatMessagesonto the navigation stack.
Customization Options
- Styling: Override CometChatMessageOptionUI (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/getConversationWithand alert user.
- Network Failures: Present retry or toast on navigation errors.
- Invalid Data: Disable option if sender.uidis 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 | 
| Toggle Message Privately | viewModel.hideMessagePrivatelyOption | CometChatMessageList.swift,MessageListViewModel.swift | 
Full Sample App
Explore this feature in the CometChat SampleApp:
GitHub → SampleApp
UIKit Source Code
Browse the message list component:
GitHub → CometChatMessageList.swift