SearchConversationsService manages conversation search state using Angular signals. It handles SDK query building, pagination, and attaches real-time listeners for message, user status, group, call, typing, and receipt events to keep results up to date.
Import
Signals (Reactive State)
All state is exposed as AngularWritableSignal values. Components read these in templates or computed signals for automatic change detection.
Methods
search()
Initiates a conversation search. Resets state, validates criteria, builds the SDK request, and fetches the first page.
The method sets
fetchState to loading immediately, then to loaded (with results), empty (no results), or error (SDK failure).
loadMore()
Fetches the next page of results and appends to the existing list. Deduplicates by conversation ID.attachListeners()
Attaches all real-time SDK listeners (message, user, group, call, typing, receipt). Call this after obtaining the logged-in user.- Message listener: new text/media/custom messages, edits, deletes
- User listener: online/offline status changes
- Group listener: member joined/left/kicked/banned/added, scope changes
- Call listener: incoming/outgoing/accepted/rejected/cancelled calls
- Typing listener: typing started/ended indicators
- Receipt listener: delivered/read receipts (via
CometChatMessageEvents)
detachListeners()
Removes all SDK listeners and unsubscribes from receipt observables.reset()
Detaches listeners and resets all signals to their default values.Request Building
The service builds aCometChat.ConversationsRequest based on the keyword and active filters:
- Sets
setSearchKeyword()when keyword is non-empty - Sets
setUnread(true)when theUnreadfilter is active - Sets
setConversationType('group')when theGroupsfilter is active - Limit is 3 when no filters are active (preview mode), 30 when filters are active (full list mode)
- Custom builder overrides the default when provided
Real-Time Event Handling
Usage
The service is typically used internally byCometChatSearchConversationsListComponent, but can be injected directly for custom implementations: