stream-chat 10.0.0-rc.21 → 10.0.0-rc.22
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 +308 -216
- package/dist/cjs/index.browser.js.map +3 -3
- package/dist/cjs/index.node.js +308 -216
- package/dist/cjs/index.node.js.map +3 -3
- package/dist/esm/index.mjs +311 -219
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/client.d.ts +22 -21
- package/dist/types/configuration/types.d.ts +31 -0
- package/dist/types/messageComposer/linkPreviewsManager.d.ts +2 -2
- package/dist/types/pagination/cursorDerivation/aroundPaginationFlags.d.ts +14 -0
- package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +2 -4
- package/dist/types/pagination/paginators/BasePaginator.d.ts +5 -1
- package/dist/types/pagination/paginators/ChannelPaginator.d.ts +2 -0
- package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +5 -3
- package/dist/types/pagination/paginators/MessagePaginator.d.ts +5 -1
- package/dist/types/types.d.ts +1 -39
- package/package.json +7 -2
- package/src/ChannelManager.ts +7 -0
- package/src/EventHandlerPipeline.ts +2 -1
- package/src/api-client.ts +14 -8
- package/src/channel.ts +10 -0
- package/src/client.ts +44 -43
- package/src/configuration/keys.ts +5 -0
- package/src/configuration/shape.ts +36 -0
- package/src/configuration/types.ts +31 -0
- package/src/pagination/cursorDerivation/aroundPaginationFlags.ts +30 -0
- package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +12 -60
- package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +11 -39
- package/src/pagination/paginators/BasePaginator.ts +43 -18
- package/src/pagination/paginators/ChannelPaginator.ts +39 -14
- package/src/pagination/paginators/MessageIntervalPaginator.ts +17 -11
- package/src/pagination/paginators/MessagePaginator.ts +51 -5
- package/src/types.ts +1 -40
|
@@ -32,6 +32,13 @@ import type { FieldToDataResolver, PathResolver } from '../types.normalization';
|
|
|
32
32
|
import { resolveDotPathValue } from '../utility.normalization';
|
|
33
33
|
import { isEqual } from '../../utils/mergeWith/mergeWithCore';
|
|
34
34
|
|
|
35
|
+
const hasSameItems = (current: Channel[] | undefined, next: Channel[] | undefined) => {
|
|
36
|
+
if (current === next) return false;
|
|
37
|
+
if (!current || !next || current.length !== next.length) return false;
|
|
38
|
+
for (let i = 0; i < next.length; i++) if (current[i] !== next[i]) return false;
|
|
39
|
+
return true;
|
|
40
|
+
};
|
|
41
|
+
|
|
35
42
|
const DEFAULT_BACKEND_SORT: SortParamRequest[] = [
|
|
36
43
|
{ direction: -1, field: 'last_message_at' },
|
|
37
44
|
{ direction: -1, field: 'updated_at' },
|
|
@@ -165,16 +172,9 @@ const hiddenFilterResolver: FieldToDataResolver<Channel> = {
|
|
|
165
172
|
|
|
166
173
|
const lastUpdatedFilterResolver: FieldToDataResolver<Channel> = {
|
|
167
174
|
matchesField: (field) => field === 'last_updated',
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
// in different units and make `updated_at` win every comparison.
|
|
172
|
-
const lastMessageAt = channel.messagePaginator.lastMessageAt ?? null;
|
|
173
|
-
const updatedAt = channel.data?.updated_at;
|
|
174
|
-
return lastMessageAt !== null && updatedAt !== undefined
|
|
175
|
-
? Math.max(lastMessageAt, updatedAt)
|
|
176
|
-
: (lastMessageAt ?? updatedAt);
|
|
177
|
-
},
|
|
175
|
+
// the server uses the creation time for a channel without messages
|
|
176
|
+
resolve: (channel) =>
|
|
177
|
+
channel.messagePaginator.lastMessageAt ?? channel.data?.created_at,
|
|
178
178
|
};
|
|
179
179
|
|
|
180
180
|
const membersFilterResolver: FieldToDataResolver<Channel> = {
|
|
@@ -313,6 +313,8 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
313
313
|
private _itemsLoadedFromOfflineDB = false;
|
|
314
314
|
/** The query in flight refreshes a cache-only window, so its response replaces the window. */
|
|
315
315
|
private _replaceOfflineSeedOnResponse = false;
|
|
316
|
+
/** The query handed to the sync manager, from the cache read until it runs. See `executeQuery`. */
|
|
317
|
+
private _queryAwaitingSync: ChannelQueryShape | undefined;
|
|
316
318
|
protected _sortComparatorFactory: ChannelSortComparatorFactory | undefined;
|
|
317
319
|
sortComparator: (a: Channel, b: Channel) => number;
|
|
318
320
|
filterBuilder: FilterBuilder<ChannelFilters>;
|
|
@@ -364,6 +366,12 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
364
366
|
memberUserNameFilterResolver,
|
|
365
367
|
dataFieldFilterResolver,
|
|
366
368
|
]);
|
|
369
|
+
// since channels are reactive objects, we only really care about updating the
|
|
370
|
+
// list if their order of membership in the list changes.
|
|
371
|
+
this.state.addPreprocessor((next, previous) => {
|
|
372
|
+
if (previous && hasSameItems(previous.items, next.items))
|
|
373
|
+
next.items = previous.items;
|
|
374
|
+
});
|
|
367
375
|
}
|
|
368
376
|
|
|
369
377
|
/**
|
|
@@ -716,11 +724,25 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
716
724
|
|
|
717
725
|
if (!shouldDeferUntilSynced) return await super.executeQuery(effectiveParams);
|
|
718
726
|
|
|
727
|
+
if (
|
|
728
|
+
this._queryAwaitingSync &&
|
|
729
|
+
!this.config.hasPaginationQueryShapeChanged(this._queryAwaitingSync, queryShape)
|
|
730
|
+
) {
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
this._queryAwaitingSync = queryShape;
|
|
734
|
+
|
|
719
735
|
if (!this.isInitialized) {
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
736
|
+
let cachedChannels: Channel[] | undefined;
|
|
737
|
+
try {
|
|
738
|
+
cachedChannels = await this.preloadFirstPageFromOfflineDb({
|
|
739
|
+
...effectiveParams,
|
|
740
|
+
queryShape,
|
|
741
|
+
});
|
|
742
|
+
} catch (error) {
|
|
743
|
+
this._queryAwaitingSync = undefined;
|
|
744
|
+
throw error;
|
|
745
|
+
}
|
|
724
746
|
if (cachedChannels?.length) {
|
|
725
747
|
// Seed via `setItems` (which ingests the page into the interval/index storage), so that the items
|
|
726
748
|
// actually appear within the adequate index.
|
|
@@ -745,10 +767,12 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
745
767
|
// Otherwise, the sync status change will never fire and so `executeQuery` will never really be
|
|
746
768
|
// run.
|
|
747
769
|
if (offlineDb.syncManager.isSynced) {
|
|
770
|
+
this._queryAwaitingSync = undefined;
|
|
748
771
|
return await super.executeQuery(refreshParams);
|
|
749
772
|
}
|
|
750
773
|
|
|
751
774
|
offlineDb.syncManager.scheduleSyncStatusChangeCallback(this.id, async () => {
|
|
775
|
+
this._queryAwaitingSync = undefined;
|
|
752
776
|
await this.executeQuery(refreshParams);
|
|
753
777
|
});
|
|
754
778
|
}
|
|
@@ -825,6 +849,7 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
|
|
|
825
849
|
super.resetState();
|
|
826
850
|
// nothing is listed anymore, so the list holds no channels
|
|
827
851
|
this._itemIndex.clear();
|
|
852
|
+
this._queryAwaitingSync = undefined;
|
|
828
853
|
}
|
|
829
854
|
|
|
830
855
|
removeItem(params: { id?: string; item?: Channel }): ItemCoordinates {
|
|
@@ -641,6 +641,15 @@ export class MessageIntervalPaginator extends BasePaginator<
|
|
|
641
641
|
);
|
|
642
642
|
}
|
|
643
643
|
|
|
644
|
+
/** A jump sends its own `limit`, so its head/tail flags are derived against that, not `pageSize`. */
|
|
645
|
+
protected override getRequestedPageSize(
|
|
646
|
+
queryShape: MessageQueryShape | undefined,
|
|
647
|
+
): number {
|
|
648
|
+
return queryShape && this.isJumpQueryShape(queryShape)
|
|
649
|
+
? (queryShape.limit ?? this.pageSize)
|
|
650
|
+
: this.pageSize;
|
|
651
|
+
}
|
|
652
|
+
|
|
644
653
|
jumpToMessage = async (
|
|
645
654
|
messageId: string,
|
|
646
655
|
{
|
|
@@ -688,7 +697,9 @@ export class MessageIntervalPaginator extends BasePaginator<
|
|
|
688
697
|
};
|
|
689
698
|
} else {
|
|
690
699
|
const result = await this.executeQuery({
|
|
691
|
-
|
|
700
|
+
// Always send a limit, since the replies endpoint ignores `id_around` without one and returns the
|
|
701
|
+
// newest replies instead.
|
|
702
|
+
queryShape: { id_around: messageId, limit: pageSize ?? this.pageSize },
|
|
692
703
|
...(watch && { requestOptions: { watch: true } }),
|
|
693
704
|
updateState: false,
|
|
694
705
|
});
|
|
@@ -1321,7 +1332,7 @@ export class MessageIntervalPaginator extends BasePaginator<
|
|
|
1321
1332
|
* `isTail`/`hasMoreTail` are set; intervals entirely newer keep their flags (unloaded older
|
|
1322
1333
|
* messages may still sit between them and the cutoff). The active window is re-emitted once.
|
|
1323
1334
|
*/
|
|
1324
|
-
truncate
|
|
1335
|
+
truncate({ truncatedAt }: { truncatedAt: TimestampNS }) {
|
|
1325
1336
|
const cutoff = truncatedAt;
|
|
1326
1337
|
if (!Number.isFinite(cutoff)) return;
|
|
1327
1338
|
|
|
@@ -1389,7 +1400,7 @@ export class MessageIntervalPaginator extends BasePaginator<
|
|
|
1389
1400
|
// Nothing loaded survived the truncation.
|
|
1390
1401
|
this.state.partialNext({ items: [] });
|
|
1391
1402
|
}
|
|
1392
|
-
}
|
|
1403
|
+
}
|
|
1393
1404
|
|
|
1394
1405
|
applyMessageDeletionForUser = ({
|
|
1395
1406
|
userId,
|
|
@@ -1475,7 +1486,7 @@ export class MessageIntervalPaginator extends BasePaginator<
|
|
|
1475
1486
|
* re-emits the active window a single time (if it held an affected message) rather than one
|
|
1476
1487
|
* `ingestItem` re-emit per message.
|
|
1477
1488
|
*/
|
|
1478
|
-
reflectUserUpdate
|
|
1489
|
+
reflectUserUpdate(user: UserResponse) {
|
|
1479
1490
|
const activeIds = new Set((this.items ?? []).map((m) => this.getItemId(m)));
|
|
1480
1491
|
let activeAffected = false;
|
|
1481
1492
|
// Batch: a user rename can touch many messages; coalesce the shared-store fan-out to sibling
|
|
@@ -1493,7 +1504,7 @@ export class MessageIntervalPaginator extends BasePaginator<
|
|
|
1493
1504
|
items: (this.items ?? []).map((m) => this.getItem(this.getItemId(m)) ?? m),
|
|
1494
1505
|
});
|
|
1495
1506
|
}
|
|
1496
|
-
}
|
|
1507
|
+
}
|
|
1497
1508
|
|
|
1498
1509
|
/**
|
|
1499
1510
|
* Map a timestamp to a loaded message — the first message in the latest (head) window whose
|
|
@@ -1595,13 +1606,8 @@ const makeDeriveCursor =
|
|
|
1595
1606
|
|
|
1596
1607
|
if ((ctx.queryShape as MessagePaginationParams)?.created_at_around) {
|
|
1597
1608
|
return injectCursor(
|
|
1598
|
-
deriveCreatedAtAroundPaginationFlags<
|
|
1599
|
-
LocalMessage,
|
|
1600
|
-
MessagePaginationParams,
|
|
1601
|
-
MessageIntervalPaginator
|
|
1602
|
-
>({
|
|
1609
|
+
deriveCreatedAtAroundPaginationFlags<LocalMessage, MessagePaginationParams>({
|
|
1603
1610
|
...ctx,
|
|
1604
|
-
paginator,
|
|
1605
1611
|
page: pageWithPermittedMessages,
|
|
1606
1612
|
requestedPageSize: requestedPageSizeAfterAdjustment,
|
|
1607
1613
|
}),
|
|
@@ -11,7 +11,8 @@ import {
|
|
|
11
11
|
MessageIntervalPaginator,
|
|
12
12
|
type MessageQueryShape,
|
|
13
13
|
} from './MessageIntervalPaginator';
|
|
14
|
-
import type { LocalMessage, TimestampNS } from '../../types';
|
|
14
|
+
import type { LocalMessage, TimestampNS, UserResponse } from '../../types';
|
|
15
|
+
import type { EntityStoreChangeBatch } from '../../entityStore/EntityStore';
|
|
15
16
|
import { asTimestampNS, nsToDate } from '../../utils/time';
|
|
16
17
|
import { StateStore } from '@stream-io/state-store';
|
|
17
18
|
|
|
@@ -276,22 +277,67 @@ export class MessagePaginator extends MessageIntervalPaginator {
|
|
|
276
277
|
return interval;
|
|
277
278
|
}
|
|
278
279
|
|
|
280
|
+
onEntitiesChanged(batch: EntityStoreChangeBatch) {
|
|
281
|
+
super.onEntitiesChanged(batch);
|
|
282
|
+
const { lastMessage } = this.aggregateState.getLatestValue();
|
|
283
|
+
if (!lastMessage || !batch.changedIds.has(lastMessage.id)) return;
|
|
284
|
+
const stored = this.getItem(lastMessage.id);
|
|
285
|
+
if (stored) this.aggregateState.partialNext({ lastMessage: stored });
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
reflectUserUpdate(user: UserResponse) {
|
|
289
|
+
super.reflectUserUpdate(user);
|
|
290
|
+
const { lastMessage } = this.aggregateState.getLatestValue();
|
|
291
|
+
if (lastMessage?.user?.id !== user.id) return;
|
|
292
|
+
this.aggregateState.partialNext({ lastMessage: { ...lastMessage, user } });
|
|
293
|
+
}
|
|
294
|
+
|
|
279
295
|
removeItem(
|
|
280
296
|
params: Parameters<MessageIntervalPaginator['removeItem']>[0],
|
|
281
297
|
): ReturnType<MessageIntervalPaginator['removeItem']> {
|
|
282
298
|
const removedId =
|
|
283
299
|
params.id ?? (params.item ? this.getItemId(params.item) : undefined);
|
|
284
|
-
const
|
|
285
|
-
|
|
300
|
+
const { lastMessage, seededLastMessageAt } = this.aggregateState.getLatestValue();
|
|
301
|
+
const wasLatest = !!removedId && lastMessage?.id === removedId;
|
|
286
302
|
const result = super.removeItem(params);
|
|
287
303
|
if (wasLatest) {
|
|
288
304
|
// The tracked latest was hard-removed; fall back to the newest still-loaded message that
|
|
289
305
|
// passes the filter. `trackLastMessage` cannot do this (it only advances), so recompute here.
|
|
290
|
-
|
|
306
|
+
const previous = this.recomputeLastMessage();
|
|
307
|
+
const previousAt = getMessageCreatedAtTimestamp(previous);
|
|
308
|
+
const removedAt = getMessageCreatedAtTimestamp(lastMessage);
|
|
309
|
+
const isSeedFromRemovedMessage =
|
|
310
|
+
seededLastMessageAt !== null &&
|
|
311
|
+
removedAt !== null &&
|
|
312
|
+
seededLastMessageAt <= removedAt;
|
|
313
|
+
// The server moves `last_message_at` back to the previous message without sending it, so the
|
|
314
|
+
// seed takes the previous loaded message's time. With none loaded the new value is unknown,
|
|
315
|
+
// and the seed stays.
|
|
316
|
+
this.aggregateState.partialNext({
|
|
317
|
+
lastMessage: previous,
|
|
318
|
+
seededLastMessageAt:
|
|
319
|
+
isSeedFromRemovedMessage && previousAt !== null
|
|
320
|
+
? previousAt
|
|
321
|
+
: seededLastMessageAt,
|
|
322
|
+
});
|
|
291
323
|
}
|
|
292
324
|
return result;
|
|
293
325
|
}
|
|
294
326
|
|
|
327
|
+
truncate(params: Parameters<MessageIntervalPaginator['truncate']>[0]) {
|
|
328
|
+
super.truncate(params);
|
|
329
|
+
const { lastMessage, seededLastMessageAt } = this.aggregateState.getLatestValue();
|
|
330
|
+
const isTruncated = (timestamp: TimestampNS | null) =>
|
|
331
|
+
timestamp !== null && timestamp < params.truncatedAt;
|
|
332
|
+
const isLastMessageTruncated = isTruncated(getMessageCreatedAtTimestamp(lastMessage));
|
|
333
|
+
const isSeedTruncated = isTruncated(seededLastMessageAt);
|
|
334
|
+
if (!isLastMessageTruncated && !isSeedTruncated) return;
|
|
335
|
+
this.aggregateState.partialNext({
|
|
336
|
+
lastMessage: isLastMessageTruncated ? this.recomputeLastMessage() : lastMessage,
|
|
337
|
+
seededLastMessageAt: isSeedTruncated ? null : seededLastMessageAt,
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
|
|
295
341
|
/**
|
|
296
342
|
* The still-loaded message with the greatest `created_at` that passes
|
|
297
343
|
* {@link shouldAdvanceLastMessage} (skips system / thread-only per config), from the newest-loaded
|
|
@@ -442,7 +488,7 @@ export class MessagePaginator extends MessageIntervalPaginator {
|
|
|
442
488
|
queryShape: {
|
|
443
489
|
// `created_at_around` is a request field and still takes a `Date`.
|
|
444
490
|
created_at_around: nsToDate(lastReadBoundary),
|
|
445
|
-
limit: options?.pageSize,
|
|
491
|
+
limit: options?.pageSize ?? this.pageSize,
|
|
446
492
|
},
|
|
447
493
|
updateState: false,
|
|
448
494
|
});
|
package/src/types.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AxiosResponse } from 'axios';
|
|
2
2
|
import type { CustomEventTypes } from './custom_types';
|
|
3
|
-
import type { NotificationManager } from './notifications';
|
|
4
|
-
import type { InstanceConfigTree } from './configuration/types';
|
|
5
|
-
import type { DeepPartial } from './types.utility';
|
|
6
3
|
import type {
|
|
7
4
|
APIError,
|
|
8
5
|
Attachment,
|
|
@@ -138,42 +135,6 @@ export type PinnedMessagePaginationOptions = Omit<
|
|
|
138
135
|
|
|
139
136
|
export type QueryMembersOptions = Partial<Omit<QueryMembersPayload, 'filter_conditions'>>;
|
|
140
137
|
|
|
141
|
-
export type StreamChatOptions = {
|
|
142
|
-
/**
|
|
143
|
-
* Used to disable warnings that are triggered by using connectUser or connectAnonymousUser server-side.
|
|
144
|
-
*/
|
|
145
|
-
allowServerSideConnect?: boolean;
|
|
146
|
-
axiosRequestConfig?: AxiosRequestConfig;
|
|
147
|
-
/**
|
|
148
|
-
* Base url to use for API
|
|
149
|
-
* such as https://chat-proxy-dublin.stream-io-api.com
|
|
150
|
-
*/
|
|
151
|
-
baseURL?: string;
|
|
152
|
-
browser?: boolean;
|
|
153
|
-
/**
|
|
154
|
-
* Custom notification manager service to use for the client.
|
|
155
|
-
* If not provided, a default notification manager will be created.
|
|
156
|
-
* Notifications are used to communicate events like errors, warnings, info, etc. Other services can publish notifications or subscribe to the NotificationManager state changes.
|
|
157
|
-
*/
|
|
158
|
-
notifications?: NotificationManager;
|
|
159
|
-
/**
|
|
160
|
-
* Declarative configuration for instances the SDK creates on your behalf, seeded before the client's
|
|
161
|
-
* own managers are constructed.
|
|
162
|
-
*
|
|
163
|
-
* Equivalent to calling `client.config.set(tree)` immediately after construction, except for the
|
|
164
|
-
* `client` subtree — the configuration registry is created inside the constructor, so this is the only
|
|
165
|
-
* way to configure `reminders` / `notifications` before they are built.
|
|
166
|
-
*/
|
|
167
|
-
config?: DeepPartial<InstanceConfigTree>;
|
|
168
|
-
/**
|
|
169
|
-
* When true, user will be persisted on client. Otherwise if `connectUser` call fails, then you need to
|
|
170
|
-
* call `connectUser` again to retry.
|
|
171
|
-
* This is mainly useful for chat application working in offline mode, where you will need client.user to
|
|
172
|
-
* persist even if connectUser call fails.
|
|
173
|
-
*/
|
|
174
|
-
persistUserOnConnectionFailure?: boolean;
|
|
175
|
-
};
|
|
176
|
-
|
|
177
138
|
export type UnBanUserOptions = {
|
|
178
139
|
client_id?: string;
|
|
179
140
|
connection_id?: string;
|