Skip to main content
The 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 Angular WritableSignal values. Components read these in templates or computed signals for automatic change detection.

Methods

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.
Listeners attached:
  • 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 a CometChat.ConversationsRequest based on the keyword and active filters:
  • Sets setSearchKeyword() when keyword is non-empty
  • Sets setUnread(true) when the Unread filter is active
  • Sets setConversationType('group') when the Groups filter 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 by CometChatSearchConversationsListComponent, but can be injected directly for custom implementations: