UNPKG

stream-chat

Version:

JS SDK for the Stream Chat API

157 lines (156 loc) 7.08 kB
import { BaseSearchSource, type SearchSourceOptions } from '../../../search'; import type { ChannelMentionSuggestion, HereMentionSuggestion, MentionSuggestion, RoleMentionSuggestion, TextComposerMiddlewareOptions, UserGroupMentionSuggestion, UserSuggestion } from './types'; import type { StreamChat } from '../../../client'; import type { MemberFilters, MemberSort, UserFilters, UserGroupResponse, UserOptions, UserResponse, UserSort } from '../../../types'; import type { Channel } from '../../../channel'; import type { Middleware } from '../../../middleware'; import type { TextComposerMiddlewareExecutorState } from './TextComposerMiddlewareExecutor'; export declare const accentsMap: { [key: string]: string; }; export declare const removeDiacritics: (text?: string) => string; export declare const calculateLevenshtein: (query: string, name: string) => number; export type MentionsSearchSourceOptions = SearchSourceOptions & { mentionAllAppUsers?: boolean; suggestionFactoryMappers?: MentionSuggestionFactoryMapperOverrides; textComposerText?: string; trigger?: string; transliterate?: (text: string) => string; }; type MentionType = MentionSuggestion['mentionType']; type MentionSuggestionFactoryInputByType = { channel: 'channel'; here: 'here'; role: string; user: UserResponse; user_group: UserGroupResponse; }; type MentionSuggestionByType = { channel: ChannelMentionSuggestion; here: HereMentionSuggestion; role: RoleMentionSuggestion; user: UserSuggestion; user_group: UserGroupMentionSuggestion; }; export type MentionSuggestionFactoryMapperContext = { searchToken: string; source: MentionsSearchSource; }; export type MentionSuggestionFactoryMapper<TMentionType extends MentionType = MentionType> = (value: MentionSuggestionFactoryInputByType[TMentionType], context: MentionSuggestionFactoryMapperContext) => MentionSuggestionByType[TMentionType]; export type MentionSuggestionFactoryMapperOverrides = { [TMentionType in MentionType]?: MentionSuggestionFactoryMapper<TMentionType>; }; export declare const getAllowedMentionTypesFromCapabilities: (ownCapabilities?: string[]) => Record<MentionType, boolean>; type UserPaginationState = { itemCount: number; nextOffset?: number; }; export declare class MentionsSearchSource extends BaseSearchSource<MentionSuggestion> { readonly type = "mentions"; protected client: StreamChat; protected channel: Channel; protected latestUserPaginationState?: UserPaginationState; protected userGroupCursor?: string; userFilters: UserFilters | undefined; memberFilters: MemberFilters | undefined; userSort: UserSort | undefined; memberSort: MemberSort | undefined; searchOptions: Omit<UserOptions, 'limit' | 'offset'> | undefined; config: MentionsSearchSourceOptions; constructor(channel: Channel, options?: MentionsSearchSourceOptions); get allMembersLoadedWithInitialChannelQuery(): boolean; normalizeSearchValue: (value?: string) => string; matchesSearchQuery: (value: string | undefined, searchQuery: string) => boolean; matchesPrefixSearchQuery: (value: string | undefined, searchQuery: string) => boolean; matchesUserNameSearchQuery: (value: string | undefined, searchQuery: string) => boolean; isMentionTypeAllowed: (mentionType: MentionType) => boolean; protected mapMentionSuggestion: <TMentionType extends MentionType>(mentionType: TMentionType, value: MentionSuggestionFactoryInputByType[TMentionType], searchToken?: string) => MentionSuggestionByType[TMentionType]; getChannelTeam: () => string | undefined; toUserSuggestion: (user: UserResponse, searchToken?: string) => UserSuggestion; toChannelMentionSuggestion: (searchToken?: string) => ChannelMentionSuggestion; toHereMentionSuggestion: (searchToken?: string) => HereMentionSuggestion; toRoleMentionSuggestion: (role: string, searchToken?: string) => RoleMentionSuggestion; toUserGroupMentionSuggestion: (userGroup: UserGroupResponse, searchToken?: string) => UserGroupMentionSuggestion; getStateBeforeFirstQuery(newSearchString: string): { items: MentionSuggestion[] | undefined; hasNext: boolean; isActive: boolean; isLoading: boolean; searchQuery: string; lastQueryError?: Error; next?: string | null; offset?: number; }; canExecuteQuery: (newSearchString?: string) => boolean; protected updatePaginationStateFromQuery(): { hasNext: boolean; next: undefined; offset: number; }; transliterate: (text: string) => string; getMembersAndWatchers: () => UserResponse[]; getBuiltinMentionSuggestions: (searchQuery: string) => MentionSuggestion[]; getRoleMentionSuggestions: (query: string) => Promise<RoleMentionSuggestion[]>; searchMembersLocally: (searchQuery: string) => UserResponse[]; prepareQueryUsersParams: (searchQuery: string, offset?: number) => { filters: UserFilters; sort: UserSort; options: { limit: number; offset: number; include_deactivated_users?: boolean; presence?: boolean; }; }; prepareQueryMembersParams: (searchQuery: string, offset?: number) => { filters: MemberFilters; sort: MemberSort; options: { limit: number; offset: number; include_deactivated_users?: boolean; presence?: boolean; }; }; queryUsers: (searchQuery: string, offset?: number) => Promise<UserResponse[]>; queryMembers: (searchQuery: string, offset?: number) => Promise<UserResponse[]>; getUserSuggestionsPage: (searchQuery: string, userOffset?: number) => Promise<{ items: UserSuggestion[]; nextOffset: number | undefined; }>; buildUserGroupSearchCursor: (items: UserGroupResponse[]) => string | undefined; getUserGroupSuggestionsPage: (searchQuery: string, cursor?: string) => Promise<{ items: UserGroupMentionSuggestion[]; next: string | undefined; }>; query(searchQuery: string): Promise<{ items: MentionSuggestion[]; }>; filterMutes(data: UserSuggestion[]): UserSuggestion[]; filterMutes(data: MentionSuggestion[]): MentionSuggestion[]; filterQueryResults(items: MentionSuggestion[]): MentionSuggestion[]; resetState(): void; } /** * TextComposer middleware for mentions * Usage: * * const textComposer = new TextComposer(options); * * textComposer.use(createMentionsMiddleware(channel, { * trigger: '$', * minChars: 2 * })); * * @param channel * @param {{ * minChars: number; * trigger: string; * }} options * @returns */ export type MentionsMiddleware = Middleware<TextComposerMiddlewareExecutorState<MentionSuggestion>, 'onChange' | 'onSuggestionItemSelect'>; export declare const createMentionsMiddleware: (channel: Channel, options?: Partial<TextComposerMiddlewareOptions> & { searchSource?: MentionsSearchSource; }) => MentionsMiddleware; export {};