stream-chat 9.45.1 → 9.45.3
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 +24 -13
- package/dist/cjs/index.browser.js.map +2 -2
- package/dist/cjs/index.node.js +24 -13
- package/dist/cjs/index.node.js.map +2 -2
- package/dist/esm/index.mjs +24 -13
- package/dist/esm/index.mjs.map +2 -2
- package/dist/types/search/BaseSearchSource.d.ts +2 -0
- package/dist/types/search/types.d.ts +4 -0
- package/package.json +1 -1
- package/src/channel.ts +0 -7
- package/src/search/BaseSearchSource.ts +17 -4
- package/src/search/UserSearchSource.ts +7 -1
- package/src/search/types.ts +4 -0
|
@@ -36,6 +36,8 @@ export interface SearchSourceSync<T = any> extends ISearchSource<T> {
|
|
|
36
36
|
declare abstract class BaseSearchSourceBase<T> implements ISearchSource<T> {
|
|
37
37
|
state: StateStore<SearchSourceState<T>>;
|
|
38
38
|
pageSize: number;
|
|
39
|
+
protected allowEmptySearchString: boolean;
|
|
40
|
+
protected resetOnNewSearchQuery: boolean;
|
|
39
41
|
abstract readonly type: SearchSourceType;
|
|
40
42
|
protected constructor(options?: SearchSourceOptions);
|
|
41
43
|
get lastQueryError(): Error | undefined;
|
|
@@ -12,6 +12,10 @@ export type SearchSourceOptions = {
|
|
|
12
12
|
/** The number of milliseconds to debounce the search query. The default interval is 300ms. */
|
|
13
13
|
debounceMs?: number;
|
|
14
14
|
pageSize?: number;
|
|
15
|
+
/** When true, the source can execute queries with an empty search string. Defaults to false. */
|
|
16
|
+
allowEmptySearchString?: boolean;
|
|
17
|
+
/** When true, previously loaded items are cleared at the start of a new search query. Defaults to true. */
|
|
18
|
+
resetOnNewSearchQuery?: boolean;
|
|
15
19
|
};
|
|
16
20
|
export type SearchSourceType = 'channels' | 'users' | 'messages' | (string & {});
|
|
17
21
|
export type QueryReturnValue<T> = {
|
package/package.json
CHANGED
package/src/channel.ts
CHANGED
|
@@ -2165,9 +2165,6 @@ export class Channel {
|
|
|
2165
2165
|
...channelState.members,
|
|
2166
2166
|
[memberCopy.user.id]: memberCopy,
|
|
2167
2167
|
};
|
|
2168
|
-
if (channel.data?.member_count && event.type === 'member.added') {
|
|
2169
|
-
channel.data.member_count += 1;
|
|
2170
|
-
}
|
|
2171
2168
|
}
|
|
2172
2169
|
|
|
2173
2170
|
const currentUserId = this.getClient().userID;
|
|
@@ -2190,10 +2187,6 @@ export class Channel {
|
|
|
2190
2187
|
|
|
2191
2188
|
channelState.members = newMembers;
|
|
2192
2189
|
|
|
2193
|
-
if (channel.data?.member_count) {
|
|
2194
|
-
channel.data.member_count = Math.max(channel.data.member_count - 1, 0);
|
|
2195
|
-
}
|
|
2196
|
-
|
|
2197
2190
|
// TODO?: unset membership
|
|
2198
2191
|
}
|
|
2199
2192
|
break;
|
|
@@ -57,16 +57,25 @@ export interface SearchSourceSync<T = any> extends ISearchSource<T> {
|
|
|
57
57
|
const DEFAULT_SEARCH_SOURCE_OPTIONS: Required<SearchSourceOptions> = {
|
|
58
58
|
debounceMs: 300,
|
|
59
59
|
pageSize: 10,
|
|
60
|
+
allowEmptySearchString: false,
|
|
61
|
+
resetOnNewSearchQuery: true,
|
|
60
62
|
} as const;
|
|
61
63
|
|
|
62
64
|
abstract class BaseSearchSourceBase<T> implements ISearchSource<T> {
|
|
63
65
|
state: StateStore<SearchSourceState<T>>;
|
|
64
66
|
pageSize: number;
|
|
67
|
+
protected allowEmptySearchString: boolean;
|
|
68
|
+
protected resetOnNewSearchQuery: boolean;
|
|
65
69
|
abstract readonly type: SearchSourceType;
|
|
66
70
|
|
|
67
71
|
protected constructor(options?: SearchSourceOptions) {
|
|
68
|
-
const { pageSize } = {
|
|
72
|
+
const { pageSize, allowEmptySearchString, resetOnNewSearchQuery } = {
|
|
73
|
+
...DEFAULT_SEARCH_SOURCE_OPTIONS,
|
|
74
|
+
...options,
|
|
75
|
+
};
|
|
69
76
|
this.pageSize = pageSize;
|
|
77
|
+
this.allowEmptySearchString = allowEmptySearchString;
|
|
78
|
+
this.resetOnNewSearchQuery = resetOnNewSearchQuery;
|
|
70
79
|
this.state = new StateStore<SearchSourceState<T>>(this.initialState);
|
|
71
80
|
}
|
|
72
81
|
|
|
@@ -136,15 +145,19 @@ abstract class BaseSearchSourceBase<T> implements ISearchSource<T> {
|
|
|
136
145
|
this.isActive &&
|
|
137
146
|
!this.isLoading &&
|
|
138
147
|
(this.hasNext || hasNewSearchQuery) &&
|
|
139
|
-
searchString
|
|
148
|
+
(this.allowEmptySearchString || searchString)
|
|
140
149
|
);
|
|
141
150
|
};
|
|
142
151
|
|
|
143
152
|
protected getStateBeforeFirstQuery(newSearchString: string): SearchSourceState<T> {
|
|
153
|
+
const initialState = this.initialState;
|
|
154
|
+
const oldItems = this.items;
|
|
155
|
+
const items = this.resetOnNewSearchQuery ? initialState.items : oldItems;
|
|
144
156
|
return {
|
|
145
|
-
...
|
|
157
|
+
...initialState,
|
|
158
|
+
items,
|
|
146
159
|
isActive: this.isActive,
|
|
147
|
-
isLoading: true,
|
|
160
|
+
isLoading: this.resetOnNewSearchQuery ? true : !oldItems,
|
|
148
161
|
searchQuery: newSearchString,
|
|
149
162
|
};
|
|
150
163
|
}
|
|
@@ -60,7 +60,13 @@ export class UserSearchSource<
|
|
|
60
60
|
baseFilters: this.filters,
|
|
61
61
|
context: { searchQuery } as UserSearchSourceFilterBuilderContext<TFilterContext>,
|
|
62
62
|
});
|
|
63
|
-
|
|
63
|
+
let sort: UserSort;
|
|
64
|
+
if (Array.isArray(this.sort)) {
|
|
65
|
+
const hasIdSort = this.sort.some((entry) => 'id' in entry);
|
|
66
|
+
sort = hasIdSort ? this.sort : [...this.sort, { id: 1 }];
|
|
67
|
+
} else {
|
|
68
|
+
sort = { id: 1, ...this.sort };
|
|
69
|
+
}
|
|
64
70
|
const options = { ...this.searchOptions, limit: this.pageSize, offset: this.offset };
|
|
65
71
|
const { users } = await this.client.queryUsers(filters, sort, options);
|
|
66
72
|
return { items: users };
|
package/src/search/types.ts
CHANGED
|
@@ -14,6 +14,10 @@ export type SearchSourceOptions = {
|
|
|
14
14
|
/** The number of milliseconds to debounce the search query. The default interval is 300ms. */
|
|
15
15
|
debounceMs?: number;
|
|
16
16
|
pageSize?: number;
|
|
17
|
+
/** When true, the source can execute queries with an empty search string. Defaults to false. */
|
|
18
|
+
allowEmptySearchString?: boolean;
|
|
19
|
+
/** When true, previously loaded items are cleared at the start of a new search query. Defaults to true. */
|
|
20
|
+
resetOnNewSearchQuery?: boolean;
|
|
17
21
|
};
|
|
18
22
|
|
|
19
23
|
export type SearchSourceType = 'channels' | 'users' | 'messages' | (string & {});
|