@stream-io/feeds-client 0.2.2 → 0.2.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/CHANGELOG.md +8 -0
- package/dist/@react-bindings/contexts/StreamSearchContext.d.ts +1 -1
- package/dist/@react-bindings/contexts/StreamSearchResultsContext.d.ts +1 -1
- package/dist/@react-bindings/hooks/search-state-hooks/useSearchQuery.d.ts +1 -1
- package/dist/@react-bindings/hooks/search-state-hooks/useSearchResult.d.ts +1 -1
- package/dist/@react-bindings/hooks/search-state-hooks/useSearchSources.d.ts +2 -2
- package/dist/@react-bindings/wrappers/StreamSearch.d.ts +1 -1
- package/dist/@react-bindings/wrappers/StreamSearchResults.d.ts +1 -1
- package/dist/index-react-bindings.browser.cjs +26 -8
- package/dist/index-react-bindings.browser.cjs.map +1 -1
- package/dist/index-react-bindings.browser.js +26 -8
- package/dist/index-react-bindings.browser.js.map +1 -1
- package/dist/index-react-bindings.node.cjs +26 -8
- package/dist/index-react-bindings.node.cjs.map +1 -1
- package/dist/index-react-bindings.node.js +26 -8
- package/dist/index-react-bindings.node.js.map +1 -1
- package/dist/index.browser.cjs +242 -170
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +242 -171
- package/dist/index.browser.js.map +1 -1
- package/dist/index.d.ts +1 -5
- package/dist/index.node.cjs +242 -170
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +242 -171
- package/dist/index.node.js.map +1 -1
- package/dist/src/common/{ActivitySearchSource.d.ts → search/ActivitySearchSource.d.ts} +3 -3
- package/dist/src/common/{BaseSearchSource.d.ts → search/BaseSearchSource.d.ts} +41 -35
- package/dist/src/common/{FeedSearchSource.d.ts → search/FeedSearchSource.d.ts} +3 -3
- package/dist/src/common/{SearchController.d.ts → search/SearchController.d.ts} +1 -3
- package/dist/src/common/{UserSearchSource.d.ts → search/UserSearchSource.d.ts} +4 -4
- package/dist/src/common/search/index.d.ts +6 -0
- package/dist/src/common/search/types.d.ts +22 -0
- package/dist/src/common/types.d.ts +1 -0
- package/dist/src/feed/event-handlers/activity/handle-activity-deleted.d.ts +5 -12
- package/dist/src/gen/models/index.d.ts +58 -26
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/index.ts +1 -5
- package/package.json +1 -1
- package/src/common/{ActivitySearchSource.ts → search/ActivitySearchSource.ts} +3 -3
- package/src/common/{BaseSearchSource.ts → search/BaseSearchSource.ts} +137 -69
- package/src/common/{FeedSearchSource.ts → search/FeedSearchSource.ts} +3 -3
- package/src/common/{SearchController.ts → search/SearchController.ts} +2 -7
- package/src/common/{UserSearchSource.ts → search/UserSearchSource.ts} +3 -3
- package/src/common/search/index.ts +6 -0
- package/src/common/search/types.ts +21 -0
- package/src/common/types.ts +2 -0
- package/src/feed/event-handlers/activity/activity-utils.test.ts +2 -2
- package/src/feed/event-handlers/activity/handle-activity-added.test.ts +86 -0
- package/src/feed/event-handlers/activity/handle-activity-deleted.test.ts +117 -0
- package/src/feed/event-handlers/activity/handle-activity-deleted.ts +8 -4
- package/src/feed/event-handlers/feed-member/handle-feed-member-added.test.ts +75 -0
- package/src/feed/event-handlers/feed-member/handle-feed-member-removed.test.ts +82 -0
- package/src/feed/event-handlers/feed-member/handle-feed-member-removed.ts +19 -9
- package/src/feed/event-handlers/feed-member/handle-feed-member-updated.test.ts +84 -0
- package/src/gen/feeds/FeedsApi.ts +6 -0
- package/src/gen/model-decoders/decoders.ts +13 -1
- package/src/gen/models/index.ts +90 -34
- package/src/test-utils/response-generators.ts +107 -0
- package/dist/src/test-utils/index.d.ts +0 -1
- package/dist/src/test-utils/response-generators.d.ts +0 -74
package/dist/index.node.js
CHANGED
|
@@ -2,7 +2,7 @@ import axios from 'axios';
|
|
|
2
2
|
|
|
3
3
|
const decoders = {};
|
|
4
4
|
const decodeDatetimeType = (input) => typeof input === 'number'
|
|
5
|
-
? new Date(Math.floor(input /
|
|
5
|
+
? new Date(Math.floor(input / 1000000))
|
|
6
6
|
: new Date(input);
|
|
7
7
|
decoders.DatetimeType = decodeDatetimeType;
|
|
8
8
|
const decode = (typeMappings, input) => {
|
|
@@ -413,6 +413,7 @@ decoders.Command = (input) => {
|
|
|
413
413
|
decoders.CommentAddedEvent = (input) => {
|
|
414
414
|
const typeMappings = {
|
|
415
415
|
created_at: { type: 'DatetimeType', isSingle: true },
|
|
416
|
+
activity: { type: 'ActivityResponse', isSingle: true },
|
|
416
417
|
comment: { type: 'CommentResponse', isSingle: true },
|
|
417
418
|
received_at: { type: 'DatetimeType', isSingle: true },
|
|
418
419
|
};
|
|
@@ -429,6 +430,7 @@ decoders.CommentDeletedEvent = (input) => {
|
|
|
429
430
|
decoders.CommentReactionAddedEvent = (input) => {
|
|
430
431
|
const typeMappings = {
|
|
431
432
|
created_at: { type: 'DatetimeType', isSingle: true },
|
|
433
|
+
activity: { type: 'ActivityResponse', isSingle: true },
|
|
432
434
|
comment: { type: 'CommentResponse', isSingle: true },
|
|
433
435
|
reaction: { type: 'FeedsReactionResponse', isSingle: true },
|
|
434
436
|
received_at: { type: 'DatetimeType', isSingle: true },
|
|
@@ -447,6 +449,7 @@ decoders.CommentReactionDeletedEvent = (input) => {
|
|
|
447
449
|
decoders.CommentReactionUpdatedEvent = (input) => {
|
|
448
450
|
const typeMappings = {
|
|
449
451
|
created_at: { type: 'DatetimeType', isSingle: true },
|
|
452
|
+
activity: { type: 'ActivityResponse', isSingle: true },
|
|
450
453
|
comment: { type: 'CommentResponse', isSingle: true },
|
|
451
454
|
reaction: { type: 'FeedsReactionResponse', isSingle: true },
|
|
452
455
|
received_at: { type: 'DatetimeType', isSingle: true },
|
|
@@ -809,6 +812,7 @@ decoders.Message = (input) => {
|
|
|
809
812
|
pin_expires: { type: 'DatetimeType', isSingle: true },
|
|
810
813
|
pinned_at: { type: 'DatetimeType', isSingle: true },
|
|
811
814
|
thread_participants: { type: 'User', isSingle: false },
|
|
815
|
+
member: { type: 'ChannelMember', isSingle: true },
|
|
812
816
|
pinned_by: { type: 'User', isSingle: true },
|
|
813
817
|
poll: { type: 'Poll', isSingle: true },
|
|
814
818
|
quoted_message: { type: 'Message', isSingle: true },
|
|
@@ -862,6 +866,8 @@ decoders.ModerationCustomActionEvent = (input) => {
|
|
|
862
866
|
};
|
|
863
867
|
decoders.ModerationFlagResponse = (input) => {
|
|
864
868
|
const typeMappings = {
|
|
869
|
+
created_at: { type: 'DatetimeType', isSingle: true },
|
|
870
|
+
updated_at: { type: 'DatetimeType', isSingle: true },
|
|
865
871
|
review_queue_item: { type: 'ReviewQueueItemResponse', isSingle: true },
|
|
866
872
|
user: { type: 'UserResponse', isSingle: true },
|
|
867
873
|
};
|
|
@@ -1628,6 +1634,7 @@ class FeedsApi {
|
|
|
1628
1634
|
const body = {
|
|
1629
1635
|
type: request?.type,
|
|
1630
1636
|
create_notification_activity: request?.create_notification_activity,
|
|
1637
|
+
skip_push: request?.skip_push,
|
|
1631
1638
|
custom: request?.custom,
|
|
1632
1639
|
};
|
|
1633
1640
|
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/activities/{activity_id}/reactions', pathParams, undefined, body, 'application/json');
|
|
@@ -1774,6 +1781,7 @@ class FeedsApi {
|
|
|
1774
1781
|
object_type: request?.object_type,
|
|
1775
1782
|
create_notification_activity: request?.create_notification_activity,
|
|
1776
1783
|
parent_id: request?.parent_id,
|
|
1784
|
+
skip_push: request?.skip_push,
|
|
1777
1785
|
attachments: request?.attachments,
|
|
1778
1786
|
mentioned_user_ids: request?.mentioned_user_ids,
|
|
1779
1787
|
custom: request?.custom,
|
|
@@ -1827,6 +1835,7 @@ class FeedsApi {
|
|
|
1827
1835
|
};
|
|
1828
1836
|
const body = {
|
|
1829
1837
|
comment: request?.comment,
|
|
1838
|
+
skip_push: request?.skip_push,
|
|
1830
1839
|
custom: request?.custom,
|
|
1831
1840
|
};
|
|
1832
1841
|
const response = await this.apiClient.sendRequest('PATCH', '/api/v2/feeds/comments/{id}', pathParams, undefined, body, 'application/json');
|
|
@@ -1840,6 +1849,7 @@ class FeedsApi {
|
|
|
1840
1849
|
const body = {
|
|
1841
1850
|
type: request?.type,
|
|
1842
1851
|
create_notification_activity: request?.create_notification_activity,
|
|
1852
|
+
skip_push: request?.skip_push,
|
|
1843
1853
|
custom: request?.custom,
|
|
1844
1854
|
};
|
|
1845
1855
|
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/comments/{id}/reactions', pathParams, undefined, body, 'application/json');
|
|
@@ -2080,6 +2090,7 @@ class FeedsApi {
|
|
|
2080
2090
|
create_notification_activity: request?.create_notification_activity,
|
|
2081
2091
|
follower_role: request?.follower_role,
|
|
2082
2092
|
push_preference: request?.push_preference,
|
|
2093
|
+
skip_push: request?.skip_push,
|
|
2083
2094
|
custom: request?.custom,
|
|
2084
2095
|
};
|
|
2085
2096
|
const response = await this.apiClient.sendRequest('PATCH', '/api/v2/feeds/follows', undefined, undefined, body, 'application/json');
|
|
@@ -2092,6 +2103,7 @@ class FeedsApi {
|
|
|
2092
2103
|
target: request?.target,
|
|
2093
2104
|
create_notification_activity: request?.create_notification_activity,
|
|
2094
2105
|
push_preference: request?.push_preference,
|
|
2106
|
+
skip_push: request?.skip_push,
|
|
2095
2107
|
custom: request?.custom,
|
|
2096
2108
|
};
|
|
2097
2109
|
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/follows', undefined, undefined, body, 'application/json');
|
|
@@ -4661,14 +4673,20 @@ function handleFeedMemberUpdated(event) {
|
|
|
4661
4673
|
function handleFeedMemberRemoved(event) {
|
|
4662
4674
|
const { connected_user: connectedUser } = this.client.state.getLatestValue();
|
|
4663
4675
|
this.state.next((currentState) => {
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4676
|
+
let newState;
|
|
4677
|
+
if (typeof currentState.members !== 'undefined') {
|
|
4678
|
+
const filtered = currentState.members.filter((member) => member.user.id !== event.member_id);
|
|
4679
|
+
if (filtered.length !== currentState.members.length) {
|
|
4680
|
+
newState ?? (newState = { ...currentState });
|
|
4681
|
+
newState.members = filtered;
|
|
4682
|
+
}
|
|
4683
|
+
}
|
|
4684
|
+
if (connectedUser?.id === event.member_id &&
|
|
4685
|
+
typeof currentState.own_membership !== 'undefined') {
|
|
4686
|
+
newState ?? (newState = { ...currentState });
|
|
4669
4687
|
delete newState.own_membership;
|
|
4670
4688
|
}
|
|
4671
|
-
return newState;
|
|
4689
|
+
return newState ?? currentState;
|
|
4672
4690
|
});
|
|
4673
4691
|
}
|
|
4674
4692
|
|
|
@@ -4905,7 +4923,7 @@ const removePinnedActivityFromState = (activityResponse, pinnedActivities) => {
|
|
|
4905
4923
|
if (index !== -1) {
|
|
4906
4924
|
const newActivities = [...pinnedActivities];
|
|
4907
4925
|
newActivities.splice(index, 1);
|
|
4908
|
-
return { changed: true,
|
|
4926
|
+
return { changed: true, pinned_activities: newActivities };
|
|
4909
4927
|
}
|
|
4910
4928
|
else {
|
|
4911
4929
|
return { changed: false, pinned_activities: pinnedActivities };
|
|
@@ -6109,16 +6127,120 @@ const FeedOwnCapability = {
|
|
|
6109
6127
|
UPDATE_FEED_MEMBERS: 'update-feed-members',
|
|
6110
6128
|
};
|
|
6111
6129
|
|
|
6130
|
+
class SearchController {
|
|
6131
|
+
constructor({ config, sources } = {}) {
|
|
6132
|
+
this.addSource = (source) => {
|
|
6133
|
+
this.state.partialNext({
|
|
6134
|
+
sources: [...this.sources, source],
|
|
6135
|
+
});
|
|
6136
|
+
};
|
|
6137
|
+
this.getSource = (sourceType) => this.sources.find((s) => s.type === sourceType);
|
|
6138
|
+
this.removeSource = (sourceType) => {
|
|
6139
|
+
const newSources = this.sources.filter((s) => s.type !== sourceType);
|
|
6140
|
+
if (newSources.length === this.sources.length)
|
|
6141
|
+
return;
|
|
6142
|
+
this.state.partialNext({ sources: newSources });
|
|
6143
|
+
};
|
|
6144
|
+
this.activateSource = (sourceType) => {
|
|
6145
|
+
const source = this.getSource(sourceType);
|
|
6146
|
+
if (!source || source.isActive)
|
|
6147
|
+
return;
|
|
6148
|
+
if (this.config.keepSingleActiveSource) {
|
|
6149
|
+
this.sources.forEach((s) => {
|
|
6150
|
+
if (s.type !== sourceType) {
|
|
6151
|
+
s.deactivate();
|
|
6152
|
+
}
|
|
6153
|
+
});
|
|
6154
|
+
}
|
|
6155
|
+
source.activate();
|
|
6156
|
+
this.state.partialNext({ sources: [...this.sources] });
|
|
6157
|
+
};
|
|
6158
|
+
this.deactivateSource = (sourceType) => {
|
|
6159
|
+
const source = this.getSource(sourceType);
|
|
6160
|
+
if (!source?.isActive)
|
|
6161
|
+
return;
|
|
6162
|
+
if (this.activeSources.length === 1)
|
|
6163
|
+
return;
|
|
6164
|
+
source.deactivate();
|
|
6165
|
+
this.state.partialNext({ sources: [...this.sources] });
|
|
6166
|
+
};
|
|
6167
|
+
this.activate = () => {
|
|
6168
|
+
if (!this.activeSources.length) {
|
|
6169
|
+
const sourcesToActivate = this.config.keepSingleActiveSource
|
|
6170
|
+
? this.sources.slice(0, 1)
|
|
6171
|
+
: this.sources;
|
|
6172
|
+
sourcesToActivate.forEach((s) => s.activate());
|
|
6173
|
+
}
|
|
6174
|
+
if (this.isActive)
|
|
6175
|
+
return;
|
|
6176
|
+
this.state.partialNext({ isActive: true });
|
|
6177
|
+
};
|
|
6178
|
+
this.search = async (searchQuery) => {
|
|
6179
|
+
const searchedSources = this.activeSources;
|
|
6180
|
+
this.state.partialNext({
|
|
6181
|
+
searchQuery,
|
|
6182
|
+
});
|
|
6183
|
+
await Promise.all(searchedSources.map((source) => source.search(searchQuery)));
|
|
6184
|
+
};
|
|
6185
|
+
this.cancelSearchQueries = () => {
|
|
6186
|
+
this.activeSources.forEach((s) => s.cancelScheduledQuery());
|
|
6187
|
+
};
|
|
6188
|
+
this.clear = () => {
|
|
6189
|
+
this.cancelSearchQueries();
|
|
6190
|
+
this.sources.forEach((source) => source.state.next({ ...source.initialState, isActive: source.isActive }));
|
|
6191
|
+
this.state.next((current) => ({
|
|
6192
|
+
...current,
|
|
6193
|
+
isActive: true,
|
|
6194
|
+
queriesInProgress: [],
|
|
6195
|
+
searchQuery: '',
|
|
6196
|
+
}));
|
|
6197
|
+
};
|
|
6198
|
+
this.exit = () => {
|
|
6199
|
+
this.cancelSearchQueries();
|
|
6200
|
+
this.sources.forEach((source) => source.state.next({ ...source.initialState, isActive: source.isActive }));
|
|
6201
|
+
this.state.next((current) => ({
|
|
6202
|
+
...current,
|
|
6203
|
+
isActive: false,
|
|
6204
|
+
queriesInProgress: [],
|
|
6205
|
+
searchQuery: '',
|
|
6206
|
+
}));
|
|
6207
|
+
};
|
|
6208
|
+
this.state = new StateStore({
|
|
6209
|
+
isActive: false,
|
|
6210
|
+
searchQuery: '',
|
|
6211
|
+
sources: sources ?? [],
|
|
6212
|
+
});
|
|
6213
|
+
this._internalState = new StateStore({});
|
|
6214
|
+
this.config = { keepSingleActiveSource: true, ...config };
|
|
6215
|
+
}
|
|
6216
|
+
get hasNext() {
|
|
6217
|
+
return this.sources.some((source) => source.hasNext);
|
|
6218
|
+
}
|
|
6219
|
+
get sources() {
|
|
6220
|
+
return this.state.getLatestValue().sources;
|
|
6221
|
+
}
|
|
6222
|
+
get activeSources() {
|
|
6223
|
+
return this.state.getLatestValue().sources.filter((s) => s.isActive);
|
|
6224
|
+
}
|
|
6225
|
+
get isActive() {
|
|
6226
|
+
return this.state.getLatestValue().isActive;
|
|
6227
|
+
}
|
|
6228
|
+
get searchQuery() {
|
|
6229
|
+
return this.state.getLatestValue().searchQuery;
|
|
6230
|
+
}
|
|
6231
|
+
get searchSourceTypes() {
|
|
6232
|
+
return this.sources.map((s) => s.type);
|
|
6233
|
+
}
|
|
6234
|
+
}
|
|
6235
|
+
|
|
6112
6236
|
const DEFAULT_SEARCH_SOURCE_OPTIONS = {
|
|
6113
6237
|
debounceMs: 300,
|
|
6114
6238
|
pageSize: 10,
|
|
6115
6239
|
allowEmptySearchString: false,
|
|
6240
|
+
resetOnNewSearchQuery: true,
|
|
6116
6241
|
};
|
|
6117
|
-
class
|
|
6242
|
+
class BaseSearchSourceBase {
|
|
6118
6243
|
constructor(options) {
|
|
6119
|
-
this.setDebounceOptions = ({ debounceMs }) => {
|
|
6120
|
-
this.searchDebounced = debounce(this.executeQuery.bind(this), debounceMs);
|
|
6121
|
-
};
|
|
6122
6244
|
this.activate = () => {
|
|
6123
6245
|
if (this.isActive)
|
|
6124
6246
|
return;
|
|
@@ -6137,15 +6259,11 @@ class BaseSearchSource {
|
|
|
6137
6259
|
(this.hasNext || hasNewSearchQuery) &&
|
|
6138
6260
|
(this.allowEmptySearchString || searchString));
|
|
6139
6261
|
};
|
|
6140
|
-
|
|
6141
|
-
const { debounceMs, pageSize, allowEmptySearchString } = {
|
|
6142
|
-
...DEFAULT_SEARCH_SOURCE_OPTIONS,
|
|
6143
|
-
...options,
|
|
6144
|
-
};
|
|
6262
|
+
const { pageSize, allowEmptySearchString, resetOnNewSearchQuery } = { ...DEFAULT_SEARCH_SOURCE_OPTIONS, ...options };
|
|
6145
6263
|
this.pageSize = pageSize;
|
|
6146
6264
|
this.allowEmptySearchString = allowEmptySearchString;
|
|
6265
|
+
this.resetOnNewSearchQuery = resetOnNewSearchQuery;
|
|
6147
6266
|
this.state = new StateStore(this.initialState);
|
|
6148
|
-
this.setDebounceOptions({ debounceMs });
|
|
6149
6267
|
}
|
|
6150
6268
|
get lastQueryError() {
|
|
6151
6269
|
return this.state.getLatestValue().lastQueryError;
|
|
@@ -6187,10 +6305,14 @@ class BaseSearchSource {
|
|
|
6187
6305
|
return this.state.getLatestValue().searchQuery;
|
|
6188
6306
|
}
|
|
6189
6307
|
getStateBeforeFirstQuery(newSearchString) {
|
|
6308
|
+
const initialState = this.initialState;
|
|
6309
|
+
const oldItems = this.items;
|
|
6310
|
+
const items = this.resetOnNewSearchQuery ? initialState.items : oldItems;
|
|
6190
6311
|
return {
|
|
6191
6312
|
...this.initialState,
|
|
6313
|
+
items,
|
|
6192
6314
|
isActive: this.isActive,
|
|
6193
|
-
isLoading: true,
|
|
6315
|
+
isLoading: this.resetOnNewSearchQuery ? true : !oldItems,
|
|
6194
6316
|
searchQuery: newSearchString,
|
|
6195
6317
|
};
|
|
6196
6318
|
}
|
|
@@ -6203,12 +6325,10 @@ class BaseSearchSource {
|
|
|
6203
6325
|
isLoading: false,
|
|
6204
6326
|
items: isFirstPage
|
|
6205
6327
|
? stateUpdate.items
|
|
6206
|
-
: [...(this.items ?? []), ...(stateUpdate.items
|
|
6328
|
+
: [...(this.items ?? []), ...(stateUpdate.items || [])],
|
|
6207
6329
|
};
|
|
6208
6330
|
}
|
|
6209
|
-
|
|
6210
|
-
if (!this.canExecuteQuery(newSearchString))
|
|
6211
|
-
return;
|
|
6331
|
+
prepareStateForQuery(newSearchString) {
|
|
6212
6332
|
const hasNewSearchQuery = typeof newSearchString !== 'undefined';
|
|
6213
6333
|
const searchString = newSearchString ?? this.searchQuery;
|
|
6214
6334
|
if (hasNewSearchQuery) {
|
|
@@ -6217,20 +6337,50 @@ class BaseSearchSource {
|
|
|
6217
6337
|
else {
|
|
6218
6338
|
this.state.partialNext({ isLoading: true });
|
|
6219
6339
|
}
|
|
6340
|
+
return { searchString, hasNewSearchQuery };
|
|
6341
|
+
}
|
|
6342
|
+
updatePaginationStateFromQuery(result) {
|
|
6343
|
+
const { items, next } = result;
|
|
6220
6344
|
const stateUpdate = {};
|
|
6345
|
+
if (next || next === null) {
|
|
6346
|
+
stateUpdate.next = next;
|
|
6347
|
+
stateUpdate.hasNext = !!next;
|
|
6348
|
+
}
|
|
6349
|
+
else {
|
|
6350
|
+
stateUpdate.offset = (this.offset ?? 0) + items.length;
|
|
6351
|
+
stateUpdate.hasNext = items.length === this.pageSize;
|
|
6352
|
+
}
|
|
6353
|
+
return stateUpdate;
|
|
6354
|
+
}
|
|
6355
|
+
resetState() {
|
|
6356
|
+
this.state.next(this.initialState);
|
|
6357
|
+
}
|
|
6358
|
+
resetStateAndActivate() {
|
|
6359
|
+
this.resetState();
|
|
6360
|
+
this.activate();
|
|
6361
|
+
}
|
|
6362
|
+
}
|
|
6363
|
+
class BaseSearchSource extends BaseSearchSourceBase {
|
|
6364
|
+
constructor(options) {
|
|
6365
|
+
const { debounceMs } = { ...DEFAULT_SEARCH_SOURCE_OPTIONS, ...options };
|
|
6366
|
+
super(options);
|
|
6367
|
+
this.setDebounceOptions = ({ debounceMs }) => {
|
|
6368
|
+
this.searchDebounced = debounce(this.executeQuery.bind(this), debounceMs);
|
|
6369
|
+
};
|
|
6370
|
+
this.search = (searchQuery) => this.searchDebounced(searchQuery);
|
|
6371
|
+
this.setDebounceOptions({ debounceMs });
|
|
6372
|
+
}
|
|
6373
|
+
async executeQuery(newSearchString) {
|
|
6374
|
+
if (!this.canExecuteQuery(newSearchString))
|
|
6375
|
+
return;
|
|
6376
|
+
const { hasNewSearchQuery, searchString } = this.prepareStateForQuery(newSearchString);
|
|
6377
|
+
let stateUpdate = {};
|
|
6221
6378
|
try {
|
|
6222
6379
|
const results = await this.query(searchString);
|
|
6223
6380
|
if (!results)
|
|
6224
6381
|
return;
|
|
6225
|
-
const { items
|
|
6226
|
-
|
|
6227
|
-
stateUpdate.next = next;
|
|
6228
|
-
stateUpdate.hasNext = !!next;
|
|
6229
|
-
}
|
|
6230
|
-
else {
|
|
6231
|
-
stateUpdate.offset = (this.offset ?? 0) + items.length;
|
|
6232
|
-
stateUpdate.hasNext = items.length === this.pageSize;
|
|
6233
|
-
}
|
|
6382
|
+
const { items } = results;
|
|
6383
|
+
stateUpdate = this.updatePaginationStateFromQuery(results);
|
|
6234
6384
|
stateUpdate.items = await this.filterQueryResults(items);
|
|
6235
6385
|
}
|
|
6236
6386
|
catch (e) {
|
|
@@ -6243,118 +6393,39 @@ class BaseSearchSource {
|
|
|
6243
6393
|
cancelScheduledQuery() {
|
|
6244
6394
|
this.searchDebounced.cancel();
|
|
6245
6395
|
}
|
|
6246
|
-
resetState() {
|
|
6247
|
-
this.state.next(this.initialState);
|
|
6248
|
-
}
|
|
6249
|
-
resetStateAndActivate() {
|
|
6250
|
-
this.resetState();
|
|
6251
|
-
this.activate();
|
|
6252
|
-
}
|
|
6253
6396
|
}
|
|
6254
|
-
|
|
6255
|
-
|
|
6256
|
-
|
|
6257
|
-
|
|
6258
|
-
|
|
6259
|
-
|
|
6260
|
-
});
|
|
6261
|
-
};
|
|
6262
|
-
this.getSource = (sourceType) => this.sources.find((s) => s.type === sourceType);
|
|
6263
|
-
this.removeSource = (sourceType) => {
|
|
6264
|
-
const newSources = this.sources.filter((s) => s.type !== sourceType);
|
|
6265
|
-
if (newSources.length === this.sources.length)
|
|
6266
|
-
return;
|
|
6267
|
-
this.state.partialNext({ sources: newSources });
|
|
6268
|
-
};
|
|
6269
|
-
this.activateSource = (sourceType) => {
|
|
6270
|
-
const source = this.getSource(sourceType);
|
|
6271
|
-
if (!source || source.isActive)
|
|
6272
|
-
return;
|
|
6273
|
-
if (this.config.keepSingleActiveSource) {
|
|
6274
|
-
this.sources.forEach((s) => {
|
|
6275
|
-
if (s.type !== sourceType) {
|
|
6276
|
-
s.deactivate();
|
|
6277
|
-
}
|
|
6278
|
-
});
|
|
6279
|
-
}
|
|
6280
|
-
source.activate();
|
|
6281
|
-
this.state.partialNext({ sources: [...this.sources] });
|
|
6282
|
-
};
|
|
6283
|
-
this.deactivateSource = (sourceType) => {
|
|
6284
|
-
const source = this.getSource(sourceType);
|
|
6285
|
-
if (!source?.isActive)
|
|
6286
|
-
return;
|
|
6287
|
-
if (this.activeSources.length === 1)
|
|
6288
|
-
return;
|
|
6289
|
-
source.deactivate();
|
|
6290
|
-
this.state.partialNext({ sources: [...this.sources] });
|
|
6291
|
-
};
|
|
6292
|
-
this.activate = () => {
|
|
6293
|
-
if (!this.activeSources.length) {
|
|
6294
|
-
const sourcesToActivate = this.config.keepSingleActiveSource
|
|
6295
|
-
? this.sources.slice(0, 1)
|
|
6296
|
-
: this.sources;
|
|
6297
|
-
sourcesToActivate.forEach((s) => s.activate());
|
|
6298
|
-
}
|
|
6299
|
-
if (this.isActive)
|
|
6300
|
-
return;
|
|
6301
|
-
this.state.partialNext({ isActive: true });
|
|
6302
|
-
};
|
|
6303
|
-
this.search = async (searchQuery) => {
|
|
6304
|
-
const searchedSources = this.activeSources;
|
|
6305
|
-
this.state.partialNext({
|
|
6306
|
-
searchQuery,
|
|
6307
|
-
});
|
|
6308
|
-
await Promise.all(searchedSources.map((source) => source.search(searchQuery)));
|
|
6309
|
-
};
|
|
6310
|
-
this.cancelSearchQueries = () => {
|
|
6311
|
-
this.activeSources.forEach((s) => s.cancelScheduledQuery());
|
|
6312
|
-
};
|
|
6313
|
-
this.clear = () => {
|
|
6314
|
-
this.cancelSearchQueries();
|
|
6315
|
-
this.sources.forEach((source) => source.state.next({ ...source.initialState, isActive: source.isActive }));
|
|
6316
|
-
this.state.next((current) => ({
|
|
6317
|
-
...current,
|
|
6318
|
-
isActive: true,
|
|
6319
|
-
queriesInProgress: [],
|
|
6320
|
-
searchQuery: '',
|
|
6321
|
-
}));
|
|
6322
|
-
};
|
|
6323
|
-
this.exit = () => {
|
|
6324
|
-
this.cancelSearchQueries();
|
|
6325
|
-
this.sources.forEach((source) => source.state.next({ ...source.initialState, isActive: source.isActive }));
|
|
6326
|
-
this.state.next((current) => ({
|
|
6327
|
-
...current,
|
|
6328
|
-
isActive: false,
|
|
6329
|
-
queriesInProgress: [],
|
|
6330
|
-
searchQuery: '',
|
|
6331
|
-
}));
|
|
6397
|
+
class BaseSearchSourceSync extends BaseSearchSourceBase {
|
|
6398
|
+
constructor(options) {
|
|
6399
|
+
const { debounceMs } = { ...DEFAULT_SEARCH_SOURCE_OPTIONS, ...options };
|
|
6400
|
+
super(options);
|
|
6401
|
+
this.setDebounceOptions = ({ debounceMs }) => {
|
|
6402
|
+
this.searchDebounced = debounce(this.executeQuery.bind(this), debounceMs);
|
|
6332
6403
|
};
|
|
6333
|
-
this.
|
|
6334
|
-
|
|
6335
|
-
searchQuery: '',
|
|
6336
|
-
sources: sources ?? [],
|
|
6337
|
-
});
|
|
6338
|
-
this._internalState = new StateStore({});
|
|
6339
|
-
this.config = { keepSingleActiveSource: true, ...config };
|
|
6340
|
-
}
|
|
6341
|
-
get hasNext() {
|
|
6342
|
-
return this.sources.some((source) => source.hasNext);
|
|
6343
|
-
}
|
|
6344
|
-
get sources() {
|
|
6345
|
-
return this.state.getLatestValue().sources;
|
|
6346
|
-
}
|
|
6347
|
-
get activeSources() {
|
|
6348
|
-
return this.state.getLatestValue().sources.filter((s) => s.isActive);
|
|
6349
|
-
}
|
|
6350
|
-
get isActive() {
|
|
6351
|
-
return this.state.getLatestValue().isActive;
|
|
6404
|
+
this.search = (searchQuery) => this.searchDebounced(searchQuery);
|
|
6405
|
+
this.setDebounceOptions({ debounceMs });
|
|
6352
6406
|
}
|
|
6353
|
-
|
|
6354
|
-
|
|
6407
|
+
executeQuery(newSearchString) {
|
|
6408
|
+
if (!this.canExecuteQuery(newSearchString))
|
|
6409
|
+
return;
|
|
6410
|
+
const { hasNewSearchQuery, searchString } = this.prepareStateForQuery(newSearchString);
|
|
6411
|
+
let stateUpdate = {};
|
|
6412
|
+
try {
|
|
6413
|
+
const results = this.query(searchString);
|
|
6414
|
+
if (!results)
|
|
6415
|
+
return;
|
|
6416
|
+
const { items } = results;
|
|
6417
|
+
stateUpdate = this.updatePaginationStateFromQuery(results);
|
|
6418
|
+
stateUpdate.items = this.filterQueryResults(items);
|
|
6419
|
+
}
|
|
6420
|
+
catch (e) {
|
|
6421
|
+
stateUpdate.lastQueryError = e;
|
|
6422
|
+
}
|
|
6423
|
+
finally {
|
|
6424
|
+
this.state.next(this.getStateAfterQuery(stateUpdate, hasNewSearchQuery));
|
|
6425
|
+
}
|
|
6355
6426
|
}
|
|
6356
|
-
|
|
6357
|
-
|
|
6427
|
+
cancelScheduledQuery() {
|
|
6428
|
+
this.searchDebounced.cancel();
|
|
6358
6429
|
}
|
|
6359
6430
|
}
|
|
6360
6431
|
|
|
@@ -6383,36 +6454,6 @@ class ActivitySearchSource extends BaseSearchSource {
|
|
|
6383
6454
|
}
|
|
6384
6455
|
}
|
|
6385
6456
|
|
|
6386
|
-
class UserSearchSource extends BaseSearchSource {
|
|
6387
|
-
constructor(client, options) {
|
|
6388
|
-
super(options);
|
|
6389
|
-
this.type = 'user';
|
|
6390
|
-
this.client = client;
|
|
6391
|
-
}
|
|
6392
|
-
async query(searchQuery) {
|
|
6393
|
-
const { connected_user: connectedUser } = this.client.state.getLatestValue();
|
|
6394
|
-
if (!connectedUser)
|
|
6395
|
-
return { items: [] };
|
|
6396
|
-
const { users: items } = await this.client.queryUsers({
|
|
6397
|
-
payload: {
|
|
6398
|
-
filter_conditions: {
|
|
6399
|
-
...(!this.allowEmptySearchString || searchQuery.length > 0
|
|
6400
|
-
? {
|
|
6401
|
-
name: {
|
|
6402
|
-
$autocomplete: searchQuery,
|
|
6403
|
-
},
|
|
6404
|
-
}
|
|
6405
|
-
: {}),
|
|
6406
|
-
},
|
|
6407
|
-
},
|
|
6408
|
-
});
|
|
6409
|
-
return { items, next: undefined };
|
|
6410
|
-
}
|
|
6411
|
-
filterQueryResults(items) {
|
|
6412
|
-
return items;
|
|
6413
|
-
}
|
|
6414
|
-
}
|
|
6415
|
-
|
|
6416
6457
|
class FeedSearchSource extends BaseSearchSource {
|
|
6417
6458
|
constructor(client, options) {
|
|
6418
6459
|
super(options);
|
|
@@ -6446,5 +6487,35 @@ class FeedSearchSource extends BaseSearchSource {
|
|
|
6446
6487
|
}
|
|
6447
6488
|
}
|
|
6448
6489
|
|
|
6449
|
-
|
|
6490
|
+
class UserSearchSource extends BaseSearchSource {
|
|
6491
|
+
constructor(client, options) {
|
|
6492
|
+
super(options);
|
|
6493
|
+
this.type = 'user';
|
|
6494
|
+
this.client = client;
|
|
6495
|
+
}
|
|
6496
|
+
async query(searchQuery) {
|
|
6497
|
+
const { connected_user: connectedUser } = this.client.state.getLatestValue();
|
|
6498
|
+
if (!connectedUser)
|
|
6499
|
+
return { items: [] };
|
|
6500
|
+
const { users: items } = await this.client.queryUsers({
|
|
6501
|
+
payload: {
|
|
6502
|
+
filter_conditions: {
|
|
6503
|
+
...(!this.allowEmptySearchString || searchQuery.length > 0
|
|
6504
|
+
? {
|
|
6505
|
+
name: {
|
|
6506
|
+
$autocomplete: searchQuery,
|
|
6507
|
+
},
|
|
6508
|
+
}
|
|
6509
|
+
: {}),
|
|
6510
|
+
},
|
|
6511
|
+
},
|
|
6512
|
+
});
|
|
6513
|
+
return { items, next: undefined };
|
|
6514
|
+
}
|
|
6515
|
+
filterQueryResults(items) {
|
|
6516
|
+
return items;
|
|
6517
|
+
}
|
|
6518
|
+
}
|
|
6519
|
+
|
|
6520
|
+
export { ActivitySearchSource, BaseSearchSource, BaseSearchSourceSync, ChannelOwnCapability, Constants, Feed, FeedOwnCapability, FeedSearchSource, FeedsClient, MergedStateStore, SearchController, StateStore, StreamApiError, StreamPoll, UserSearchSource, checkHasAnotherPage, getStateUpdateQueueId, isCommentResponse, isFollowResponse, isImageFile, isPatch, isVideoFile, isVoteAnswer, shouldUpdateState, uniqueArrayMerge, updateEntityInArray };
|
|
6450
6521
|
//# sourceMappingURL=index.node.js.map
|