Overview
Threaded messages allow users to reply to specific messages within a conversation, creating a sub-conversation for improved clarity and context. With CometChat’s UIKit for iOS, you can:- Display a dedicated thread view
- View and send replies to a selected message
- Maintain context between the main conversation and the thread
Prerequisites
Before implementing this feature, ensure you have:- Completed Getting Started setup
- CometChat UIKit v5+ installed
- User logged in with
CometChatUIKit.login()
Components
| Component | Description |
|---|---|
CometChatMessageList | Displays messages and provides onThreadRepliesClick handler |
CometChatThreadedMessageHeader | Shows the parent message context at the top of the thread |
CometChatMessageComposer | Composes messages with an optional parentMessageId |
ThreadedMessagesVC | View controller that hosts the threaded conversation |
Integration Steps
Step 1: Show the “Reply in Thread” Option
Navigate to the thread when a message’s thread icon is tapped:ThreadedMessagesVC.swift
Step 2: Navigate to the Thread Screen
Show a dedicated UI for thread replies. InThreadedMessagesVC.swift:
Step 3: Send a Threaded Message
Ensure new replies are attached to the correct parent message:Step 4: Fetch and Display Thread Replies
Only messages that are part of the thread are displayed. This is handled internally by:CometChatMessageList fetches replies using the parentMessageId.
Customization Options
Header Styling
CustomizeCometChatThreadedMessageHeader appearance:
Composer
Modify placeholder text, input styles, and icons:Navigation
Add a custom back button for navigation:Edge Cases
| Scenario | Handling |
|---|---|
| Parent message deleted | Display a fallback UI or disable the composer |
| No replies | Show an empty state (e.g., “No replies yet”) |
| Offline mode | Disable the composer and queue thread operations |
Error Handling
| Error Type | Solution |
|---|---|
| Fetch failures | Show an error UI or retry mechanism when loading thread messages |
| Send failures | Handle send errors via delegate callbacks or show an alert with retry |
| Loading states | Display a UIActivityIndicatorView during fetch/send operations |
| Blocked users | Remove the composer and display a blocked status label |
Feature Matrix
| Feature | Implementation |
|---|---|
| Show thread option | CometChatMessageList.onThreadRepliesClick |
| Thread view screen | ThreadedMessagesVC.swift |
| Display threaded messages | CometChatMessageList.set(parentMessage:) |
| Send threaded message | CometChatMessageComposer.set(parentMessageId:) |
| Thread header | CometChatThreadedMessageHeader |
| Handle blocked user | Remove composer and show a blocked user label |
Related Components
- Message List - Display messages in conversations
- Message Composer - Compose and send messages
- Threaded Messages Header - Thread header component
Sample App
Explore a complete sample application demonstrating threaded messaging
UIKit Source
Browse the CometChat UIKit for iOS source code
Related Guides
Threaded Messages Header
Customize the thread header component
Message List
Display and customize chat messages
Core Features
Overview of messaging features