stream-chat 9.45.6 → 9.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.browser.js +163 -119
- package/dist/cjs/index.browser.js.map +3 -3
- package/dist/cjs/index.node.js +160 -118
- package/dist/cjs/index.node.js.map +3 -3
- package/dist/esm/index.mjs +163 -119
- package/dist/esm/index.mjs.map +3 -3
- package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +1 -1
- package/dist/types/search/ChannelMemberSearchSource.d.ts +24 -0
- package/dist/types/search/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/messageComposer/middleware/textComposer/mentions.ts +14 -13
- package/src/search/ChannelMemberSearchSource.ts +85 -0
- package/src/search/MessageSearchSource.ts +1 -1
- package/src/search/index.ts +1 -0
|
@@ -11,7 +11,6 @@ export declare const accentsMap: {
|
|
|
11
11
|
export declare const removeDiacritics: (text?: string) => string;
|
|
12
12
|
export declare const calculateLevenshtein: (query: string, name: string) => number;
|
|
13
13
|
export type MentionsSearchSourceOptions = SearchSourceOptions & {
|
|
14
|
-
allowedMentionTypes?: Partial<Record<MentionType, boolean>>;
|
|
15
14
|
mentionAllAppUsers?: boolean;
|
|
16
15
|
suggestionFactoryMappers?: MentionSuggestionFactoryMapperOverrides;
|
|
17
16
|
textComposerText?: string;
|
|
@@ -41,6 +40,7 @@ export type MentionSuggestionFactoryMapper<TMentionType extends MentionType = Me
|
|
|
41
40
|
export type MentionSuggestionFactoryMapperOverrides = {
|
|
42
41
|
[TMentionType in MentionType]?: MentionSuggestionFactoryMapper<TMentionType>;
|
|
43
42
|
};
|
|
43
|
+
export declare const getAllowedMentionTypesFromCapabilities: (ownCapabilities?: string[]) => Record<MentionType, boolean>;
|
|
44
44
|
type UserPaginationState = {
|
|
45
45
|
itemCount: number;
|
|
46
46
|
nextOffset?: number;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BaseSearchSource } from './BaseSearchSource';
|
|
2
|
+
import { FilterBuilder, type FilterBuilderOptions } from '../pagination';
|
|
3
|
+
import type { Channel } from '../channel';
|
|
4
|
+
import type { ChannelMemberResponse, MemberFilters, MemberSort, QueryMembersOptions } from '../types';
|
|
5
|
+
import type { SearchSourceOptions } from './types';
|
|
6
|
+
type CustomContext = Record<string, unknown>;
|
|
7
|
+
export type ChannelMemberSearchSourceFilterBuilderContext<C extends CustomContext = CustomContext> = {
|
|
8
|
+
searchQuery?: string;
|
|
9
|
+
} & C;
|
|
10
|
+
export declare class ChannelMemberSearchSource<TFilterContext extends CustomContext = CustomContext> extends BaseSearchSource<ChannelMemberResponse> {
|
|
11
|
+
readonly type = "members";
|
|
12
|
+
channel: Channel;
|
|
13
|
+
filters: MemberFilters | undefined;
|
|
14
|
+
sort: MemberSort | undefined;
|
|
15
|
+
searchOptions: Omit<QueryMembersOptions, 'limit' | 'offset'> | undefined;
|
|
16
|
+
filterBuilder: FilterBuilder<MemberFilters, ChannelMemberSearchSourceFilterBuilderContext<TFilterContext>>;
|
|
17
|
+
constructor(channel: Channel, options?: SearchSourceOptions, filterBuilderOptions?: FilterBuilderOptions<MemberFilters, ChannelMemberSearchSourceFilterBuilderContext<TFilterContext>>);
|
|
18
|
+
canExecuteQuery: (newSearchString?: string) => boolean;
|
|
19
|
+
protected query(searchQuery: string): Promise<{
|
|
20
|
+
items: ChannelMemberResponse[];
|
|
21
|
+
}>;
|
|
22
|
+
protected filterQueryResults(items: ChannelMemberResponse[]): ChannelMemberResponse[];
|
|
23
|
+
}
|
|
24
|
+
export {};
|
package/package.json
CHANGED
|
@@ -92,7 +92,6 @@ export const calculateLevenshtein = (query: string, name: string) => {
|
|
|
92
92
|
};
|
|
93
93
|
|
|
94
94
|
export type MentionsSearchSourceOptions = SearchSourceOptions & {
|
|
95
|
-
allowedMentionTypes?: Partial<Record<MentionType, boolean>>;
|
|
96
95
|
mentionAllAppUsers?: boolean;
|
|
97
96
|
suggestionFactoryMappers?: MentionSuggestionFactoryMapperOverrides;
|
|
98
97
|
textComposerText?: string;
|
|
@@ -134,13 +133,18 @@ export type MentionSuggestionFactoryMapperOverrides = {
|
|
|
134
133
|
[TMentionType in MentionType]?: MentionSuggestionFactoryMapper<TMentionType>;
|
|
135
134
|
};
|
|
136
135
|
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
136
|
+
const hasOwnCapability = (ownCapabilities: string[] | undefined, capability: string) =>
|
|
137
|
+
ownCapabilities?.includes(capability) ?? false;
|
|
138
|
+
|
|
139
|
+
export const getAllowedMentionTypesFromCapabilities = (
|
|
140
|
+
ownCapabilities?: string[],
|
|
141
|
+
): Record<MentionType, boolean> => ({
|
|
142
|
+
channel: hasOwnCapability(ownCapabilities, 'notify-channel'),
|
|
143
|
+
here: hasOwnCapability(ownCapabilities, 'notify-here'),
|
|
144
|
+
role: hasOwnCapability(ownCapabilities, 'notify-role'),
|
|
141
145
|
user: true,
|
|
142
|
-
user_group:
|
|
143
|
-
};
|
|
146
|
+
user_group: hasOwnCapability(ownCapabilities, 'notify-group'),
|
|
147
|
+
});
|
|
144
148
|
|
|
145
149
|
type UserGroupSearchCursor = Pick<SearchUserGroupsOptions, 'id_gt' | 'name_gt'>;
|
|
146
150
|
type UserPaginationState = {
|
|
@@ -299,7 +303,6 @@ export class MentionsSearchSource extends BaseSearchSource<MentionSuggestion> {
|
|
|
299
303
|
|
|
300
304
|
constructor(channel: Channel, options?: MentionsSearchSourceOptions) {
|
|
301
305
|
const {
|
|
302
|
-
allowedMentionTypes,
|
|
303
306
|
mentionAllAppUsers,
|
|
304
307
|
suggestionFactoryMappers,
|
|
305
308
|
textComposerText,
|
|
@@ -311,10 +314,6 @@ export class MentionsSearchSource extends BaseSearchSource<MentionSuggestion> {
|
|
|
311
314
|
this.client = channel.getClient();
|
|
312
315
|
this.channel = channel;
|
|
313
316
|
this.config = {
|
|
314
|
-
allowedMentionTypes: {
|
|
315
|
-
...DEFAULT_ALLOWED_MENTION_TYPES,
|
|
316
|
-
...allowedMentionTypes,
|
|
317
|
-
},
|
|
318
317
|
mentionAllAppUsers,
|
|
319
318
|
suggestionFactoryMappers,
|
|
320
319
|
textComposerText,
|
|
@@ -371,7 +370,9 @@ export class MentionsSearchSource extends BaseSearchSource<MentionSuggestion> {
|
|
|
371
370
|
};
|
|
372
371
|
|
|
373
372
|
isMentionTypeAllowed = (mentionType: MentionType) =>
|
|
374
|
-
this.
|
|
373
|
+
getAllowedMentionTypesFromCapabilities(this.channel.data?.own_capabilities)[
|
|
374
|
+
mentionType
|
|
375
|
+
];
|
|
375
376
|
|
|
376
377
|
protected mapMentionSuggestion = <TMentionType extends MentionType>(
|
|
377
378
|
mentionType: TMentionType,
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { BaseSearchSource } from './BaseSearchSource';
|
|
2
|
+
import { FilterBuilder, type FilterBuilderOptions } from '../pagination';
|
|
3
|
+
import type { Channel } from '../channel';
|
|
4
|
+
import type {
|
|
5
|
+
ChannelMemberResponse,
|
|
6
|
+
MemberFilters,
|
|
7
|
+
MemberSort,
|
|
8
|
+
QueryMembersOptions,
|
|
9
|
+
} from '../types';
|
|
10
|
+
import type { SearchSourceOptions } from './types';
|
|
11
|
+
|
|
12
|
+
type CustomContext = Record<string, unknown>;
|
|
13
|
+
|
|
14
|
+
export type ChannelMemberSearchSourceFilterBuilderContext<
|
|
15
|
+
C extends CustomContext = CustomContext,
|
|
16
|
+
> = { searchQuery?: string } & C;
|
|
17
|
+
|
|
18
|
+
export class ChannelMemberSearchSource<
|
|
19
|
+
TFilterContext extends CustomContext = CustomContext,
|
|
20
|
+
> extends BaseSearchSource<ChannelMemberResponse> {
|
|
21
|
+
readonly type = 'members';
|
|
22
|
+
channel: Channel;
|
|
23
|
+
filters: MemberFilters | undefined;
|
|
24
|
+
sort: MemberSort | undefined;
|
|
25
|
+
searchOptions: Omit<QueryMembersOptions, 'limit' | 'offset'> | undefined;
|
|
26
|
+
filterBuilder: FilterBuilder<
|
|
27
|
+
MemberFilters,
|
|
28
|
+
ChannelMemberSearchSourceFilterBuilderContext<TFilterContext>
|
|
29
|
+
>;
|
|
30
|
+
|
|
31
|
+
constructor(
|
|
32
|
+
channel: Channel,
|
|
33
|
+
options?: SearchSourceOptions,
|
|
34
|
+
filterBuilderOptions: FilterBuilderOptions<
|
|
35
|
+
MemberFilters,
|
|
36
|
+
ChannelMemberSearchSourceFilterBuilderContext<TFilterContext>
|
|
37
|
+
> = {},
|
|
38
|
+
) {
|
|
39
|
+
super(options);
|
|
40
|
+
this.channel = channel;
|
|
41
|
+
this.filterBuilder = new FilterBuilder<
|
|
42
|
+
MemberFilters,
|
|
43
|
+
ChannelMemberSearchSourceFilterBuilderContext<TFilterContext>
|
|
44
|
+
>({
|
|
45
|
+
initialFilterConfig: {
|
|
46
|
+
default: {
|
|
47
|
+
enabled: true,
|
|
48
|
+
generate: ({ searchQuery }) =>
|
|
49
|
+
searchQuery
|
|
50
|
+
? {
|
|
51
|
+
$or: [
|
|
52
|
+
{ name: { $autocomplete: searchQuery } },
|
|
53
|
+
{ id: { $eq: searchQuery } },
|
|
54
|
+
],
|
|
55
|
+
}
|
|
56
|
+
: null,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
...filterBuilderOptions,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
canExecuteQuery = (newSearchString?: string) => {
|
|
64
|
+
const hasNewSearchQuery = typeof newSearchString !== 'undefined';
|
|
65
|
+
|
|
66
|
+
return this.isActive && !this.isLoading && (this.hasNext || hasNewSearchQuery);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
protected async query(searchQuery: string) {
|
|
70
|
+
const filters = this.filterBuilder.buildFilters({
|
|
71
|
+
baseFilters: this.filters,
|
|
72
|
+
context: {
|
|
73
|
+
searchQuery,
|
|
74
|
+
} as ChannelMemberSearchSourceFilterBuilderContext<TFilterContext>,
|
|
75
|
+
});
|
|
76
|
+
const sort = this.sort ?? [];
|
|
77
|
+
const options = { ...this.searchOptions, limit: this.pageSize, offset: this.offset };
|
|
78
|
+
const { members } = await this.channel.queryMembers(filters ?? {}, sort, options);
|
|
79
|
+
return { items: members };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
protected filterQueryResults(items: ChannelMemberResponse[]) {
|
|
83
|
+
return items;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -130,7 +130,7 @@ export class MessageSearchSource<
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
protected async query(searchQuery: string) {
|
|
133
|
-
if (!this.client.userID ||
|
|
133
|
+
if (!this.client.userID || this.next === null) return { items: [] };
|
|
134
134
|
|
|
135
135
|
const channelFilters = this.messageSearchChannelFilterBuilder.buildFilters({
|
|
136
136
|
baseFilters: {
|