CometChatSearch component is a powerful and customizable search interface that allows users to search across conversations and messages in real time. It supports a wide variety of filters, scopes, and customization options.

AI Agent Component Spec
AI Agent Component Spec
Usage
Integration
CometChatSearch is a composite component that offers flexible integration options. It can be launched directly via button clicks or any user-triggered action.
- Swift
Actions
Actions dictate how a component functions. They are divided into two types: Predefined and User-defined. You can override either type to tailor the behavior to fit your specific needs.1. onConversationClicked
Triggered when you click on a Conversation from the search result. This action doesn’t have a predefined behavior—you can override it using the following code snippet:- Swift
2. onMessageClicked
Triggered when you click on a Message from the search result. This action doesn’t have a predefined behavior—you can override it using the following code snippet:- Swift
3. onBack
Triggered when you click on the back button of the search component.- Swift
4. onError
Listens for any errors that occur in the Search component. This action doesn’t change the component’s behavior.- Swift
5. onEmpty
Listens for the empty state of the Search component. This action doesn’t change the component’s behavior.- Swift
Filters
Filters allow you to customize the data displayed in a list within a Component. You can filter the list based on your specific criteria using RequestBuilders of the Chat SDK.SearchScope
TheSearchScope enum defines what types of content to search:
| Value | Description |
|---|---|
.conversations | Search in conversations |
.messages | Search in messages |
SearchFilter
TheSearchFilter enum defines available filter options:
| Value | Description |
|---|---|
.unread | Filter by unread items |
.groups | Filter by group conversations |
.photos | Filter by photo messages |
.videos | Filter by video messages |
.links | Filter by link messages |
.documents | Filter by document messages |
.audio | Filter by audio messages |
1. ConversationsRequestBuilder
Set theConversationsRequestBuilder in the Search Component to filter the search results. For more options, refer to ConversationRequestBuilder.
- Swift
2. MessagesRequestBuilder
Set theMessagesRequestBuilder in the Search Component to filter the search results. For more options, refer to MessagesRequestBuilder.
- Swift
Events
Events are emitted by a Component. By using events, you can extend existing functionality. Being global events, they can be applied in multiple locations and can be added or removed as needed. TheCometChatSearch component does not produce any events.
Customization
To fit your app’s design requirements, you can customize the appearance of theCometChatSearch component. We provide exposed methods that allow you to modify the experience and behavior according to your specific needs.
Style
Using Style, you can customize the look and feel of the component in your app. These parameters typically control elements such as the color, size, shape, and fonts used within the component.
- Swift
Functionality
These are small functional customizations that allow you to fine-tune the overall experience of the component. With these, you can toggle the visibility of UI elements.| Property | Description | Example |
|---|---|---|
| user | Restrict search to a specific user chat | search.user = user |
| group | Restrict search to a group | search.group = group |
| hideUserStatus | Hide online/offline indicator | search.hideUserStatus = true |
| hideGroupType | Hide group type icon | search.hideGroupType = true |
| searchFilters | Filters like “Unread”, “Groups”, “Photos”, etc. | search.set(searchFilters: [.unread, .groups, .photos]) |
| initialSearchFilter | Default filter to apply on load | search.set(searchFilters: [...], initialFilter: .photos) |
| searchIn (searchScopes) | Restrict search: messages / conversations / both | search.set(searchIn: [.messages, .conversations]) |
| loadingView | Custom loader view | search.set(loadingView: spinner) |
| emptyView | Custom empty result view | search.set(emptyView: emptyView) |
| errorView | Custom error UI | search.set(errorView: errorView) |
| disableTyping | Disable typing indicators | search.disableTyping = true |
| disableSoundForMessages | Disable message sounds | search.disableSoundForMessages = true |
| customSoundForMessages | Custom sound URL for messages | search.customSoundForMessages = URL(string: "...") |
Advanced
For advanced-level customization, you can set custom views to the component. This lets you tailor each aspect of the component to fit your exact needs and application aesthetics. You can create and define your own views, layouts, and UI elements and then incorporate those into the component.Conversation View Customization
| Function | Description |
|---|---|
| listItemViewForConversation | Assign a custom list item view to a conversation. |
| leadingViewForConversation | Assign a custom leading view to a conversation. |
| titleViewForConversation | Assign a custom title view to a conversation. |
| subtitleViewForConversation | Assign a custom subtitle view to a conversation. |
| tailViewForConversation | Assign a custom trailing view to a conversation. |
- Swift
Message View Customization
With message item view functions, you can assign custom views to different types of messages in the search result. For more information, refer to the itemView prop of theCometChatMessages component.
Here’s how you can override the default message item view with a custom one for text messages:
- Swift

- Swift
| Function | Message Type |
|---|---|
| listItemViewForMessage | Text Message |
| listItemViewForImage | Image Message |
| listItemViewForVideo | Video Message |
| listItemViewForAudio | Audio Message |
| listItemViewForDocument | Document Message |
| listItemViewForLink | Link Message |
- Swift
Mention Configuration
Configure how @all mentions appear in search results using thesetMentionAllLabel method.
- Swift
DateTime Formatters
By providing a custom implementation of the DateTimeFormatterCallback, you can configure how time and date values are displayed. This ensures consistent formatting for labels such as “Today”, “Yesterday”, “X minutes ago”, and more.- Swift
Text Formatters
ThesetTextFormatters method enables developers to define and apply text formatters that dynamically modify or transform message content before rendering it in the UI. Text formatters can be used for:
- Automatically converting URLs into clickable links
- Applying Markdown or rich text styling
- Replacing certain words or patterns with emojis or predefined text
- Censoring specific words for moderation