Skip to main content
The SearchMessagesService manages message search state using Angular signals. It handles SDK query building with keyword, attachment-type, and user/group scoping, plus pagination for loading more results.

Import

Signals (Reactive State)

Methods

Initiates a message search. Resets state, validates criteria, builds the SDK request, and fetches the first page.
Validation: search requires at least one of: non-empty keyword, active message filter, uid, or guid. Otherwise fetchState is set to States.empty.

loadMore()

Fetches the next page of results and appends to the existing list.

reset()

Resets all signals to their default values and clears the internal request reference.

Request Building

The service builds a CometChat.MessagesRequest based on the search criteria:
  • hideDeletedMessages(true) — always excludes deleted messages
  • setSearchKeyword() — when keyword is non-empty
  • setUID() — when uid is provided (scoped to user)
  • setGUID() — when guid is provided (scoped to group)
  • hasLinks(true) — when the Links filter is active
  • setAttachmentTypes() — maps filters to SDK attachment types:
  • Limit is 3 when alwaysShowSeeMore is true (preview mode), 30 otherwise
  • Results are reversed after fetch to show newest first

Usage

The service is typically used internally by CometChatSearchMessagesListComponent, but can be injected directly:

Differences from SearchConversationsService