stream-chat 9.50.3 → 10.0.0-rc.2
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 +19798 -14472
- package/dist/cjs/index.browser.js.map +4 -4
- package/dist/cjs/index.node.js +19817 -14482
- package/dist/cjs/index.node.js.map +4 -4
- package/dist/esm/index.mjs +19795 -14469
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/ChannelManager.d.ts +221 -0
- package/dist/types/EventHandlerPipeline.d.ts +104 -0
- package/dist/types/api-client.d.ts +26 -0
- package/dist/types/campaign.d.ts +0 -44
- package/dist/types/channel.d.ts +454 -479
- package/dist/types/channel_batch_updater.d.ts +0 -93
- package/dist/types/channel_state.d.ts +53 -201
- package/dist/types/client.d.ts +451 -1920
- package/dist/types/client_state.d.ts +4 -4
- package/dist/types/configuration/InstanceConfigurationService.d.ts +26 -0
- package/dist/types/configuration/index.d.ts +1 -0
- package/dist/types/configuration/types.d.ts +53 -0
- package/dist/types/connection.d.ts +49 -41
- package/dist/types/connection_fallback.d.ts +6 -4
- package/dist/types/constants.d.ts +0 -4
- package/dist/types/custom_types.d.ts +2 -0
- package/dist/types/entityStore/EntityStore.d.ts +111 -0
- package/dist/types/entityStore/StoreBackedItemIndex.d.ts +60 -0
- package/dist/types/entityStore/applyReactionLocally.d.ts +26 -0
- package/dist/types/entityStore/index.d.ts +2 -0
- package/dist/types/errors.d.ts +10 -2
- package/dist/types/gen/chat/ChannelApi.d.ts +45 -0
- package/dist/types/gen/chat/ChatApi.d.ts +334 -0
- package/dist/types/gen/model-decoders/decoders.d.ts +3 -0
- package/dist/types/gen/model-decoders/event-decoder-mapping.d.ts +6 -0
- package/dist/types/gen/models/index.d.ts +8836 -0
- package/dist/types/gen/moderation/ModerationApi.d.ts +50 -0
- package/dist/types/gen-imports.d.ts +3 -0
- package/dist/types/index.d.ts +8 -7
- package/dist/types/insights.d.ts +9 -8
- package/dist/types/logger.d.ts +9 -0
- package/dist/types/messageComposer/LocationComposer.d.ts +7 -4
- package/dist/types/messageComposer/attachmentIdentity.d.ts +2 -2
- package/dist/types/messageComposer/attachmentManager.d.ts +8 -4
- package/dist/types/messageComposer/configuration/types.d.ts +11 -11
- package/dist/types/messageComposer/linkPreviewsManager.d.ts +25 -13
- package/dist/types/messageComposer/messageComposer.d.ts +10 -10
- package/dist/types/messageComposer/middleware/messageComposer/types.d.ts +3 -3
- package/dist/types/messageComposer/middleware/pollComposer/types.d.ts +4 -7
- package/dist/types/messageComposer/middleware/textComposer/commandUtils.d.ts +3 -3
- package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +7 -7
- package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +218 -4
- package/dist/types/messageComposer/middleware/textComposer/types.d.ts +9 -4
- package/dist/types/messageComposer/pollComposer.d.ts +5 -4
- package/dist/types/messageComposer/textComposer.d.ts +8 -3
- package/dist/types/messageComposer/types.d.ts +6 -28
- package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +40 -25
- package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +53 -12
- package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +19 -0
- package/dist/types/messageOperations/MessageOperations.d.ts +17 -0
- package/dist/types/messageOperations/index.d.ts +3 -0
- package/dist/types/messageOperations/types.d.ts +49 -0
- package/dist/types/moderation.d.ts +21 -203
- package/dist/types/notifications/types.d.ts +8 -7
- package/dist/types/offline-support/offline_support_api.d.ts +111 -87
- package/dist/types/offline-support/offline_sync_manager.d.ts +0 -7
- package/dist/types/offline-support/types.d.ts +19 -23
- package/dist/types/offline-support/util.d.ts +4 -2
- package/dist/types/pagination/FilterBuilder.d.ts +1 -1
- package/dist/types/pagination/ItemIndex.d.ts +25 -0
- package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +9 -0
- package/dist/types/pagination/cursorDerivation/idAroundPaginationFlags.d.ts +6 -0
- package/dist/types/pagination/cursorDerivation/index.d.ts +1 -0
- package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +6 -0
- package/dist/types/pagination/filterCompiler.d.ts +7 -0
- package/dist/types/pagination/index.d.ts +1 -3
- package/dist/types/pagination/paginators/BasePaginator.d.ts +848 -0
- package/dist/types/pagination/paginators/ChannelPaginator.d.ts +212 -0
- package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +282 -0
- package/dist/types/pagination/paginators/MessagePaginator.d.ts +208 -0
- package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +39 -0
- package/dist/types/pagination/paginators/ReminderPaginator.d.ts +19 -0
- package/dist/types/pagination/paginators/UserGroupPaginator.d.ts +24 -0
- package/dist/types/pagination/paginators/index.d.ts +7 -0
- package/dist/types/pagination/paginators/stateThrottling.d.ts +2 -0
- package/dist/types/pagination/sortCompiler.d.ts +49 -0
- package/dist/types/pagination/types.normalization.d.ts +11 -0
- package/dist/types/pagination/utility.normalization.d.ts +18 -0
- package/dist/types/pagination/utility.queryChannel.d.ts +26 -0
- package/dist/types/pagination/utility.search.d.ts +13 -0
- package/dist/types/permissions.d.ts +1 -1
- package/dist/types/poll.d.ts +29 -32
- package/dist/types/poll_manager.d.ts +2 -2
- package/dist/types/reminders/Reminder.d.ts +2 -5
- package/dist/types/reminders/ReminderManager.d.ts +2 -9
- package/dist/types/search/MessageSearchSource.d.ts +4 -4
- package/dist/types/search/UserSearchSource.d.ts +1 -1
- package/dist/types/search/types.d.ts +3 -3
- package/dist/types/segment.d.ts +0 -34
- package/dist/types/signing.d.ts +105 -65
- package/dist/types/store.d.ts +1 -0
- package/dist/types/thread.d.ts +70 -34
- package/dist/types/thread_manager.d.ts +3 -3
- package/dist/types/token_manager.d.ts +15 -10
- package/dist/types/types.d.ts +197 -3404
- package/dist/types/utils/FixedSizeQueueCache.d.ts +12 -6
- package/dist/types/utils/WithSubscriptions.d.ts +2 -1
- package/dist/types/utils/concurrency.d.ts +4 -4
- package/dist/types/utils/mergeWith/mergeWith.d.ts +3 -3
- package/dist/types/utils/mergeWith/mergeWithCore.d.ts +8 -3
- package/dist/types/utils/retryable.d.ts +34 -0
- package/dist/types/utils/throttling/throttle.d.ts +36 -0
- package/dist/types/utils.d.ts +100 -194
- package/package.json +7 -3
- package/src/ChannelManager.ts +724 -0
- package/src/CooldownTimer.ts +2 -2
- package/src/EventHandlerPipeline.ts +228 -0
- package/src/LiveLocationManager.ts +12 -11
- package/src/api-client.ts +275 -0
- package/src/campaign.ts +1 -77
- package/src/channel.ts +1344 -1282
- package/src/channel_batch_updater.ts +1 -211
- package/src/channel_state.ts +144 -1013
- package/src/client.ts +936 -3995
- package/src/client_state.ts +4 -4
- package/src/configuration/InstanceConfigurationService.ts +73 -0
- package/src/configuration/index.ts +1 -0
- package/src/configuration/types.ts +81 -0
- package/src/connection.ts +145 -94
- package/src/connection_fallback.ts +29 -27
- package/src/constants.ts +1 -5
- package/src/custom_types.ts +4 -1
- package/src/entityStore/EntityStore.ts +208 -0
- package/src/entityStore/StoreBackedItemIndex.ts +115 -0
- package/src/entityStore/applyReactionLocally.ts +113 -0
- package/src/entityStore/index.ts +2 -0
- package/src/errors.ts +14 -2
- package/src/gen/chat/ChannelApi.ts +275 -0
- package/src/gen/chat/ChatApi.ts +2554 -0
- package/src/gen/model-decoders/decoders.ts +2680 -0
- package/src/gen/model-decoders/event-decoder-mapping.ts +198 -0
- package/src/gen/models/index.ts +12673 -0
- package/src/gen/moderation/ModerationApi.ts +607 -0
- package/src/gen-imports.ts +3 -0
- package/src/index.ts +11 -12
- package/src/insights.ts +6 -5
- package/src/logger.ts +28 -0
- package/src/messageComposer/LocationComposer.ts +9 -5
- package/src/messageComposer/MessageComposerEffectHandlers.ts +1 -0
- package/src/messageComposer/attachmentIdentity.ts +16 -9
- package/src/messageComposer/attachmentManager.ts +13 -8
- package/src/messageComposer/configuration/types.ts +11 -11
- package/src/messageComposer/linkPreviewsManager.ts +9 -10
- package/src/messageComposer/messageComposer.ts +57 -53
- package/src/messageComposer/middleware/messageComposer/attachments.ts +1 -2
- package/src/messageComposer/middleware/messageComposer/cleanData.ts +1 -1
- package/src/messageComposer/middleware/messageComposer/compositionValidation.ts +2 -2
- package/src/messageComposer/middleware/messageComposer/messageComposerState.ts +2 -2
- package/src/messageComposer/middleware/messageComposer/sharedLocation.ts +4 -3
- package/src/messageComposer/middleware/messageComposer/textComposer.ts +2 -2
- package/src/messageComposer/middleware/messageComposer/types.ts +3 -4
- package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +9 -5
- package/src/messageComposer/middleware/pollComposer/state.ts +0 -2
- package/src/messageComposer/middleware/pollComposer/types.ts +4 -7
- package/src/messageComposer/middleware/textComposer/TextComposerMiddlewareExecutor.ts +10 -1
- package/src/messageComposer/middleware/textComposer/commandEffects.ts +4 -4
- package/src/messageComposer/middleware/textComposer/commandUtils.ts +3 -6
- package/src/messageComposer/middleware/textComposer/commands.ts +3 -3
- package/src/messageComposer/middleware/textComposer/mentionUtils.ts +1 -1
- package/src/messageComposer/middleware/textComposer/mentions.ts +31 -15
- package/src/messageComposer/middleware/textComposer/types.ts +9 -4
- package/src/messageComposer/pollComposer.ts +6 -8
- package/src/messageComposer/textComposer.ts +27 -2
- package/src/messageComposer/types.ts +6 -28
- package/src/messageDelivery/MessageDeliveryReporter.ts +101 -45
- package/src/messageDelivery/MessageReceiptsTracker.ts +294 -21
- package/src/messageOperations/MessageOperationStatePolicy.ts +77 -0
- package/src/messageOperations/MessageOperations.ts +212 -0
- package/src/messageOperations/index.ts +10 -0
- package/src/messageOperations/types.ts +64 -0
- package/src/moderation.ts +38 -431
- package/src/notifications/types.ts +8 -7
- package/src/offline-support/offline_support_api.ts +200 -133
- package/src/offline-support/offline_sync_manager.ts +23 -44
- package/src/offline-support/types.ts +23 -26
- package/src/offline-support/util.ts +5 -4
- package/src/pagination/FilterBuilder.ts +4 -1
- package/src/pagination/ItemIndex.ts +25 -0
- package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +73 -0
- package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +53 -0
- package/src/pagination/cursorDerivation/index.ts +1 -0
- package/src/pagination/cursorDerivation/linearPaginationFlags.ts +86 -0
- package/src/pagination/filterCompiler.ts +196 -0
- package/src/pagination/index.ts +1 -3
- package/src/pagination/paginators/BasePaginator.ts +2859 -0
- package/src/pagination/paginators/ChannelPaginator.ts +729 -0
- package/src/pagination/paginators/MessageIntervalPaginator.ts +1116 -0
- package/src/pagination/paginators/MessagePaginator.ts +508 -0
- package/src/pagination/paginators/PinnedMessagePaginator.ts +108 -0
- package/src/pagination/paginators/ReminderPaginator.ts +107 -0
- package/src/pagination/paginators/UserGroupPaginator.ts +127 -0
- package/src/pagination/paginators/index.ts +7 -0
- package/src/pagination/paginators/stateThrottling.ts +31 -0
- package/src/pagination/sortCompiler.ts +193 -0
- package/src/pagination/types.normalization.ts +14 -0
- package/src/pagination/utility.normalization.ts +106 -0
- package/src/pagination/utility.queryChannel.ts +84 -0
- package/src/pagination/utility.search.ts +80 -0
- package/src/permissions.ts +7 -8
- package/src/poll.ts +101 -110
- package/src/poll_manager.ts +14 -8
- package/src/reminders/Reminder.ts +2 -5
- package/src/reminders/ReminderManager.ts +19 -21
- package/src/search/BaseSearchSource.ts +0 -3
- package/src/search/ChannelMemberSearchSource.ts +7 -1
- package/src/search/ChannelSearchSource.ts +10 -3
- package/src/search/MessageSearchSource.ts +29 -30
- package/src/search/UserSearchSource.ts +12 -8
- package/src/search/types.ts +3 -4
- package/src/segment.ts +1 -95
- package/src/signing.ts +107 -67
- package/src/store.ts +2 -1
- package/src/thread.ts +562 -238
- package/src/thread_manager.ts +37 -16
- package/src/token_manager.ts +21 -10
- package/src/types.ts +364 -4533
- package/src/uploadManager.ts +8 -0
- package/src/utils/FixedSizeQueueCache.ts +12 -6
- package/src/utils/WithSubscriptions.ts +2 -1
- package/src/utils/concurrency.ts +4 -4
- package/src/utils/mergeWith/mergeWith.ts +3 -3
- package/src/utils/mergeWith/mergeWithCore.ts +140 -164
- package/src/utils/mergeWith/mergeWithDiff.ts +3 -3
- package/src/utils/retryable.ts +117 -0
- package/src/utils/throttling/throttle.ts +130 -0
- package/src/utils.ts +208 -754
- package/dist/types/channel_manager.d.ts +0 -122
- package/dist/types/events.d.ts +0 -72
- package/dist/types/pagination/BasePaginator.d.ts +0 -69
- package/dist/types/pagination/ReminderPaginator.d.ts +0 -16
- package/dist/types/pagination/UserGroupPaginator.d.ts +0 -21
- package/src/channel_manager.ts +0 -830
- package/src/events.ts +0 -75
- package/src/pagination/BasePaginator.ts +0 -184
- package/src/pagination/ReminderPaginator.ts +0 -56
- package/src/pagination/UserGroupPaginator.ts +0 -93
|
@@ -8,10 +8,9 @@ import type { StreamChat } from '../client';
|
|
|
8
8
|
import type {
|
|
9
9
|
CreateReminderOptions,
|
|
10
10
|
Event,
|
|
11
|
-
|
|
11
|
+
EventPayload,
|
|
12
12
|
LocalMessage,
|
|
13
13
|
MessageResponse,
|
|
14
|
-
ReminderResponse,
|
|
15
14
|
} from '../types';
|
|
16
15
|
|
|
17
16
|
const oneMinute = 60 * 1000;
|
|
@@ -38,14 +37,9 @@ const isReminderDoesNotExistError = (error: Error) =>
|
|
|
38
37
|
|
|
39
38
|
type MessageId = string;
|
|
40
39
|
|
|
41
|
-
export type ReminderEvent =
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
message_id: MessageId;
|
|
45
|
-
reminder: ReminderResponse;
|
|
46
|
-
type: EventTypes;
|
|
47
|
-
user_id: string;
|
|
48
|
-
};
|
|
40
|
+
export type ReminderEvent = EventPayload<
|
|
41
|
+
`reminder.${string}` | 'notification.reminder_due'
|
|
42
|
+
>;
|
|
49
43
|
|
|
50
44
|
export type ReminderManagerState = {
|
|
51
45
|
reminders: Map<MessageId, Reminder>;
|
|
@@ -167,6 +161,7 @@ export class ReminderManager extends WithSubscriptions {
|
|
|
167
161
|
|
|
168
162
|
// WS event handling START //
|
|
169
163
|
static isReminderWsEventPayload = (event: Event): event is ReminderEvent =>
|
|
164
|
+
'reminder' in event &&
|
|
170
165
|
!!event.reminder &&
|
|
171
166
|
(event.type.startsWith('reminder.') || event.type === 'notification.reminder_due');
|
|
172
167
|
|
|
@@ -186,14 +181,17 @@ export class ReminderManager extends WithSubscriptions {
|
|
|
186
181
|
this.client.on('reminder.created', (event) => {
|
|
187
182
|
if (!ReminderManager.isReminderWsEventPayload(event)) return;
|
|
188
183
|
const { reminder } = event;
|
|
189
|
-
|
|
184
|
+
// TODO: OAPI discrepancy?
|
|
185
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
186
|
+
this.upsertToState({ data: reminder! });
|
|
190
187
|
}).unsubscribe;
|
|
191
188
|
|
|
192
189
|
private subscribeReminderUpdated = () =>
|
|
193
190
|
this.client.on('reminder.updated', (event) => {
|
|
194
191
|
if (!ReminderManager.isReminderWsEventPayload(event)) return;
|
|
195
192
|
const { reminder } = event;
|
|
196
|
-
|
|
193
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
194
|
+
this.upsertToState({ data: reminder! });
|
|
197
195
|
}).unsubscribe;
|
|
198
196
|
|
|
199
197
|
private subscribeReminderDeleted = () =>
|
|
@@ -249,8 +247,8 @@ export class ReminderManager extends WithSubscriptions {
|
|
|
249
247
|
|
|
250
248
|
// API calls START //
|
|
251
249
|
upsertReminder = async (options: CreateReminderOptions) => {
|
|
252
|
-
const {
|
|
253
|
-
if (this.getFromState(
|
|
250
|
+
const { message_id } = options;
|
|
251
|
+
if (this.getFromState(message_id)) {
|
|
254
252
|
try {
|
|
255
253
|
return await this.updateReminder(options);
|
|
256
254
|
} catch (error) {
|
|
@@ -272,26 +270,26 @@ export class ReminderManager extends WithSubscriptions {
|
|
|
272
270
|
};
|
|
273
271
|
|
|
274
272
|
createReminder = async (options: CreateReminderOptions) => {
|
|
275
|
-
const
|
|
276
|
-
return this.upsertToState({ data:
|
|
273
|
+
const response = await this.client.createReminder(options);
|
|
274
|
+
return this.upsertToState({ data: response, overwrite: false });
|
|
277
275
|
};
|
|
278
276
|
|
|
279
277
|
updateReminder = async (options: CreateReminderOptions) => {
|
|
280
|
-
const
|
|
281
|
-
return this.upsertToState({ data: reminder });
|
|
278
|
+
const response = await this.client.updateReminder(options);
|
|
279
|
+
return this.upsertToState({ data: response.reminder });
|
|
282
280
|
};
|
|
283
281
|
|
|
284
282
|
deleteReminder = async (messageId: MessageId) => {
|
|
285
|
-
await this.client.deleteReminder(messageId);
|
|
283
|
+
await this.client.deleteReminder({ message_id: messageId });
|
|
286
284
|
this.removeFromState(messageId);
|
|
287
285
|
};
|
|
288
286
|
|
|
289
287
|
queryNextReminders = async () => {
|
|
290
|
-
await this.paginator.
|
|
288
|
+
await this.paginator.toTail();
|
|
291
289
|
};
|
|
292
290
|
|
|
293
291
|
queryPreviousReminders = async () => {
|
|
294
|
-
await this.paginator.
|
|
292
|
+
await this.paginator.toHead();
|
|
295
293
|
};
|
|
296
294
|
|
|
297
295
|
// API calls END //
|
|
@@ -14,7 +14,6 @@ export type DebounceOptions = {
|
|
|
14
14
|
};
|
|
15
15
|
type DebouncedExecQueryFunction = DebouncedFunc<(searchString?: string) => Promise<void>>;
|
|
16
16
|
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
17
|
interface ISearchSource<T = any> {
|
|
19
18
|
activate(): void;
|
|
20
19
|
|
|
@@ -40,14 +39,12 @@ interface ISearchSource<T = any> {
|
|
|
40
39
|
readonly type: SearchSourceType;
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
42
|
export interface SearchSource<T = any> extends ISearchSource<T> {
|
|
45
43
|
cancelScheduledQuery(): void;
|
|
46
44
|
setDebounceOptions(options: DebounceOptions): void;
|
|
47
45
|
search(text?: string): Promise<void> | undefined;
|
|
48
46
|
}
|
|
49
47
|
|
|
50
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
48
|
export interface SearchSourceSync<T = any> extends ISearchSource<T> {
|
|
52
49
|
cancelScheduledQuery(): void;
|
|
53
50
|
setDebounceOptions(options: DebounceOptions): void;
|
|
@@ -75,7 +75,13 @@ export class ChannelMemberSearchSource<
|
|
|
75
75
|
});
|
|
76
76
|
const sort = this.sort ?? [];
|
|
77
77
|
const options = { ...this.searchOptions, limit: this.pageSize, offset: this.offset };
|
|
78
|
-
const { members } = await this.channel.queryMembers(
|
|
78
|
+
const { members } = await this.channel.queryMembers({
|
|
79
|
+
payload: {
|
|
80
|
+
filter_conditions: filters ?? {},
|
|
81
|
+
sort,
|
|
82
|
+
...options,
|
|
83
|
+
},
|
|
84
|
+
});
|
|
79
85
|
return { items: members };
|
|
80
86
|
}
|
|
81
87
|
|
|
@@ -54,16 +54,23 @@ export class ChannelSearchSource<
|
|
|
54
54
|
protected async query(searchQuery: string) {
|
|
55
55
|
const filters = this.filterBuilder.buildFilters({
|
|
56
56
|
baseFilters: {
|
|
57
|
-
...(this.client.
|
|
57
|
+
...(this.client.userId ? { members: { $in: [this.client.userId] } } : {}),
|
|
58
58
|
...this.filters,
|
|
59
59
|
},
|
|
60
60
|
context: { searchQuery } as Partial<
|
|
61
61
|
ChannelSearchSourceFilterBuilderContext<TFilterContext>
|
|
62
62
|
>,
|
|
63
63
|
});
|
|
64
|
-
const sort = this.sort
|
|
64
|
+
const sort = this.sort;
|
|
65
65
|
const options = { ...this.searchOptions, limit: this.pageSize, offset: this.offset };
|
|
66
|
-
const items = await this.client.
|
|
66
|
+
const items = await this.client.queryChannelsAndHydrate(
|
|
67
|
+
{
|
|
68
|
+
filter_conditions: filters,
|
|
69
|
+
sort,
|
|
70
|
+
...options,
|
|
71
|
+
},
|
|
72
|
+
{ withResponse: false },
|
|
73
|
+
);
|
|
67
74
|
return { items };
|
|
68
75
|
}
|
|
69
76
|
|
|
@@ -6,7 +6,7 @@ import type {
|
|
|
6
6
|
MessageFilters,
|
|
7
7
|
MessageResponse,
|
|
8
8
|
SearchMessageSort,
|
|
9
|
-
|
|
9
|
+
SearchPayload,
|
|
10
10
|
} from '../types';
|
|
11
11
|
import type { StreamChat } from '../client';
|
|
12
12
|
import type { SearchSourceOptions } from './types';
|
|
@@ -60,7 +60,7 @@ export class MessageSearchSource<
|
|
|
60
60
|
readonly type = 'messages';
|
|
61
61
|
private client: StreamChat;
|
|
62
62
|
|
|
63
|
-
messageSearchChannelFilters:
|
|
63
|
+
messageSearchChannelFilters: SearchPayload['filter_conditions'] | undefined;
|
|
64
64
|
messageSearchFilters: MessageFilters | undefined;
|
|
65
65
|
messageSearchSort: SearchMessageSort | undefined;
|
|
66
66
|
|
|
@@ -69,7 +69,7 @@ export class MessageSearchSource<
|
|
|
69
69
|
channelQueryOptions: Omit<ChannelOptions, 'limit' | 'offset'> | undefined;
|
|
70
70
|
|
|
71
71
|
messageSearchChannelFilterBuilder: FilterBuilder<
|
|
72
|
-
|
|
72
|
+
SearchPayload['filter_conditions'],
|
|
73
73
|
MergeContext<
|
|
74
74
|
BuiltInContexts['messageSearchChannel'],
|
|
75
75
|
TContexts['messageSearchChannelContext']
|
|
@@ -130,11 +130,11 @@ export class MessageSearchSource<
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
protected async query(searchQuery: string) {
|
|
133
|
-
if (!this.client.
|
|
133
|
+
if (!this.client.userId || this.next === null) return { items: [] };
|
|
134
134
|
|
|
135
135
|
const channelFilters = this.messageSearchChannelFilterBuilder.buildFilters({
|
|
136
136
|
baseFilters: {
|
|
137
|
-
...(this.client.
|
|
137
|
+
...(this.client.userId ? { members: { $in: [this.client.userId] } } : {}),
|
|
138
138
|
...this.messageSearchChannelFilters,
|
|
139
139
|
},
|
|
140
140
|
context: { searchQuery } as Partial<
|
|
@@ -155,23 +155,25 @@ export class MessageSearchSource<
|
|
|
155
155
|
>,
|
|
156
156
|
});
|
|
157
157
|
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const items = results
|
|
158
|
+
const { next, results } = await this.client.search({
|
|
159
|
+
payload: {
|
|
160
|
+
filter_conditions: channelFilters,
|
|
161
|
+
message_filter_conditions: messageFilters,
|
|
162
|
+
limit: this.pageSize,
|
|
163
|
+
next: this.next,
|
|
164
|
+
sort: [
|
|
165
|
+
{
|
|
166
|
+
field: 'created_at',
|
|
167
|
+
direction: -1,
|
|
168
|
+
},
|
|
169
|
+
...(this.messageSearchSort ?? []),
|
|
170
|
+
],
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
const items = results
|
|
175
|
+
.map(({ message }) => message)
|
|
176
|
+
.filter((m): m is NonNullable<typeof m> => Boolean(m));
|
|
175
177
|
|
|
176
178
|
const cids = Array.from(
|
|
177
179
|
items.reduce((acc, message) => {
|
|
@@ -187,14 +189,11 @@ export class MessageSearchSource<
|
|
|
187
189
|
MergeContext<BuiltInContexts['channelQuery'], TContexts['channelQueryContext']>
|
|
188
190
|
>,
|
|
189
191
|
});
|
|
190
|
-
await this.client.
|
|
191
|
-
channelQueryFilters,
|
|
192
|
-
{
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
},
|
|
196
|
-
this.channelQueryOptions,
|
|
197
|
-
);
|
|
192
|
+
await this.client.queryChannelsAndHydrate({
|
|
193
|
+
filter_conditions: channelQueryFilters,
|
|
194
|
+
sort: [{ direction: -1, field: 'last_message_at' }],
|
|
195
|
+
...this.channelQueryOptions,
|
|
196
|
+
});
|
|
198
197
|
}
|
|
199
198
|
|
|
200
199
|
return { items, next };
|
|
@@ -60,15 +60,19 @@ export class UserSearchSource<
|
|
|
60
60
|
baseFilters: this.filters,
|
|
61
61
|
context: { searchQuery } as UserSearchSourceFilterBuilderContext<TFilterContext>,
|
|
62
62
|
});
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
sort = { id: 1, ...this.sort };
|
|
69
|
-
}
|
|
63
|
+
const baseSort = this.sort ?? [];
|
|
64
|
+
const hasIdSort = baseSort.some((entry) => entry.field === 'id');
|
|
65
|
+
const sort: UserSort = hasIdSort
|
|
66
|
+
? baseSort
|
|
67
|
+
: [...baseSort, { field: 'id', direction: 1 }];
|
|
70
68
|
const options = { ...this.searchOptions, limit: this.pageSize, offset: this.offset };
|
|
71
|
-
const { users } = await this.client.queryUsers(
|
|
69
|
+
const { users } = await this.client.queryUsers({
|
|
70
|
+
payload: {
|
|
71
|
+
filter_conditions: filters,
|
|
72
|
+
sort,
|
|
73
|
+
...options,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
72
76
|
return { items: users };
|
|
73
77
|
}
|
|
74
78
|
|
package/src/search/types.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2
1
|
export type SearchSourceState<T = any> = {
|
|
3
2
|
hasNext: boolean;
|
|
4
3
|
isActive: boolean;
|
|
@@ -11,12 +10,12 @@ export type SearchSourceState<T = any> = {
|
|
|
11
10
|
};
|
|
12
11
|
|
|
13
12
|
export type SearchSourceOptions = {
|
|
14
|
-
/** The number of milliseconds to debounce the search query
|
|
13
|
+
/** The number of milliseconds to debounce the search query (defaults to `300`). */
|
|
15
14
|
debounceMs?: number;
|
|
16
15
|
pageSize?: number;
|
|
17
|
-
/** When true
|
|
16
|
+
/** When `true`, the source can execute queries with an empty search string (defaults to `false`). */
|
|
18
17
|
allowEmptySearchString?: boolean;
|
|
19
|
-
/** When true
|
|
18
|
+
/** When `true`, previously loaded items are cleared at the start of a new search query (defaults to `true`). */
|
|
20
19
|
resetOnNewSearchQuery?: boolean;
|
|
21
20
|
};
|
|
22
21
|
|
package/src/segment.ts
CHANGED
|
@@ -1,95 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type {
|
|
3
|
-
QuerySegmentTargetsFilter,
|
|
4
|
-
SegmentData,
|
|
5
|
-
SegmentResponse,
|
|
6
|
-
SortParam,
|
|
7
|
-
} from './types';
|
|
8
|
-
|
|
9
|
-
type SegmentType = 'user' | 'channel';
|
|
10
|
-
|
|
11
|
-
type SegmentUpdatableFields = {
|
|
12
|
-
description?: string;
|
|
13
|
-
filter?: {};
|
|
14
|
-
name?: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export class Segment {
|
|
18
|
-
type: SegmentType;
|
|
19
|
-
id: string | null;
|
|
20
|
-
client: StreamChat;
|
|
21
|
-
data?: SegmentData | SegmentResponse;
|
|
22
|
-
|
|
23
|
-
constructor(
|
|
24
|
-
client: StreamChat,
|
|
25
|
-
type: SegmentType,
|
|
26
|
-
id: string | null,
|
|
27
|
-
data?: SegmentData,
|
|
28
|
-
) {
|
|
29
|
-
this.client = client;
|
|
30
|
-
this.type = type;
|
|
31
|
-
this.id = id;
|
|
32
|
-
this.data = data;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
create() {
|
|
36
|
-
const body = {
|
|
37
|
-
name: this.data?.name,
|
|
38
|
-
filter: this.data?.filter,
|
|
39
|
-
description: this.data?.description,
|
|
40
|
-
all_sender_channels: this.data?.all_sender_channels,
|
|
41
|
-
all_users: this.data?.all_users,
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
return this.client.createSegment(this.type, this.id, body);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
verifySegmentId() {
|
|
48
|
-
if (!this.id) {
|
|
49
|
-
throw new Error(
|
|
50
|
-
'Segment id is missing. Either create the segment using segment.create() or set the id during instantiation - const segment = client.segment(id)',
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
get() {
|
|
56
|
-
this.verifySegmentId();
|
|
57
|
-
return this.client.getSegment(this.id as string);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
update(data: Partial<SegmentUpdatableFields>) {
|
|
61
|
-
this.verifySegmentId();
|
|
62
|
-
|
|
63
|
-
return this.client.updateSegment(this.id as string, data);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
addTargets(targets: string[]) {
|
|
67
|
-
this.verifySegmentId();
|
|
68
|
-
return this.client.addSegmentTargets(this.id as string, targets);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
removeTargets(targets: string[]) {
|
|
72
|
-
this.verifySegmentId();
|
|
73
|
-
return this.client.removeSegmentTargets(this.id as string, targets);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
delete() {
|
|
77
|
-
this.verifySegmentId();
|
|
78
|
-
return this.client.deleteSegment(this.id as string);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
targetExists(targetId: string) {
|
|
82
|
-
this.verifySegmentId();
|
|
83
|
-
return this.client.segmentTargetExists(this.id as string, targetId);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
queryTargets(
|
|
87
|
-
filter: QuerySegmentTargetsFilter | null = {},
|
|
88
|
-
sort: SortParam[] | null | [] = [],
|
|
89
|
-
options = {},
|
|
90
|
-
) {
|
|
91
|
-
this.verifySegmentId();
|
|
92
|
-
|
|
93
|
-
return this.client.querySegmentTargets(this.id as string, filter, sort, options);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
1
|
+
// Segment functionality has been moved to the server-side SDK.
|