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
search()
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 aCometChat.MessagesRequest based on the search criteria:
hideDeletedMessages(true)— always excludes deleted messagessetSearchKeyword()— when keyword is non-emptysetUID()— when uid is provided (scoped to user)setGUID()— when guid is provided (scoped to group)hasLinks(true)— when theLinksfilter is activesetAttachmentTypes()— maps filters to SDK attachment types:
- Limit is 3 when
alwaysShowSeeMoreis true (preview mode), 30 otherwise - Results are reversed after fetch to show newest first
Usage
The service is typically used internally byCometChatSearchMessagesListComponent, but can be injected directly: