stream-chat 10.2.0 → 10.3.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.
Files changed (108) hide show
  1. package/dist/cjs/index.browser.js +4712 -2818
  2. package/dist/cjs/index.browser.js.map +4 -4
  3. package/dist/cjs/index.node.js +4733 -2818
  4. package/dist/cjs/index.node.js.map +4 -4
  5. package/dist/esm/index.mjs +4712 -2818
  6. package/dist/esm/index.mjs.map +4 -4
  7. package/dist/types/channel.d.ts +62 -3
  8. package/dist/types/client.d.ts +9 -1
  9. package/dist/types/configuration/types.d.ts +2 -0
  10. package/dist/types/connection/ConnectionRecoveryManager.d.ts +1 -0
  11. package/dist/types/gen/chat/ChatApi.d.ts +12 -1
  12. package/dist/types/gen/models/index.d.ts +659 -11
  13. package/dist/types/gen/moderation/ModerationApi.d.ts +3 -1
  14. package/dist/types/index.d.ts +2 -0
  15. package/dist/types/messageComposer/attachmentManager.d.ts +2 -0
  16. package/dist/types/messageComposer/index.d.ts +1 -0
  17. package/dist/types/messageComposer/linkPreviewsManager.d.ts +1 -0
  18. package/dist/types/messageComposer/messageComposer.d.ts +33 -7
  19. package/dist/types/messageComposer/middleware/messageComposer/compositionValidation.d.ts +1 -2
  20. package/dist/types/messageComposer/middleware/messageComposer/index.d.ts +1 -0
  21. package/dist/types/messageComposer/middleware/messageComposer/scheduledMessage.d.ts +4 -0
  22. package/dist/types/messageComposer/middleware/textComposer/commandUtils.d.ts +1 -0
  23. package/dist/types/messageComposer/scheduledMessageComposition.d.ts +32 -0
  24. package/dist/types/messageMarks/MessageMarkManager.d.ts +44 -0
  25. package/dist/types/messageMarks/index.d.ts +1 -0
  26. package/dist/types/messageOperations/MessageOperations.d.ts +12 -1
  27. package/dist/types/messageOperations/index.d.ts +1 -0
  28. package/dist/types/messageOperations/reflectMessageMarkEvent.d.ts +9 -0
  29. package/dist/types/messageOperations/sendOrdering.d.ts +4 -3
  30. package/dist/types/messageOperations/types.d.ts +6 -2
  31. package/dist/types/notifications/types.d.ts +4 -0
  32. package/dist/types/offline-support/offline_support_api.d.ts +19 -1
  33. package/dist/types/offline-support/types.d.ts +19 -1
  34. package/dist/types/pagination/PaginatorView.d.ts +55 -0
  35. package/dist/types/pagination/index.d.ts +1 -0
  36. package/dist/types/pagination/paginators/BasePaginator.d.ts +41 -0
  37. package/dist/types/pagination/paginators/ChannelPaginator.d.ts +0 -9
  38. package/dist/types/pagination/paginators/MessageMarkPaginator.d.ts +61 -0
  39. package/dist/types/pagination/paginators/ScheduledMessagePaginator.d.ts +83 -0
  40. package/dist/types/pagination/paginators/index.d.ts +2 -0
  41. package/dist/types/scheduledMessages/ScheduledMessagePaginatorsManager.d.ts +47 -0
  42. package/dist/types/scheduledMessages/ScheduledMessageStatePolicy.d.ts +12 -0
  43. package/dist/types/scheduledMessages/ScheduledMessagesView.d.ts +38 -0
  44. package/dist/types/scheduledMessages/composition.d.ts +5 -0
  45. package/dist/types/scheduledMessages/constants.d.ts +56 -0
  46. package/dist/types/scheduledMessages/editResolvers.d.ts +4 -0
  47. package/dist/types/scheduledMessages/errors.d.ts +3 -0
  48. package/dist/types/scheduledMessages/eventHandlers.d.ts +8 -0
  49. package/dist/types/scheduledMessages/index.d.ts +7 -0
  50. package/dist/types/scheduledMessages/limits.d.ts +6 -0
  51. package/dist/types/scheduledMessages/types.d.ts +65 -0
  52. package/dist/types/thread.d.ts +12 -1
  53. package/dist/types/utils.d.ts +7 -0
  54. package/package.json +1 -1
  55. package/src/channel.ts +231 -7
  56. package/src/client.ts +46 -2
  57. package/src/configuration/keys.ts +2 -0
  58. package/src/configuration/shape.ts +15 -0
  59. package/src/configuration/types.ts +3 -1
  60. package/src/connection/ConnectionRecoveryManager.ts +7 -0
  61. package/src/errors.ts +11 -0
  62. package/src/gen/chat/ChatApi.ts +60 -3
  63. package/src/gen/models/index.ts +794 -23
  64. package/src/gen/moderation/ModerationApi.ts +24 -3
  65. package/src/index.ts +2 -0
  66. package/src/messageComposer/attachmentManager.ts +43 -24
  67. package/src/messageComposer/index.ts +1 -0
  68. package/src/messageComposer/messageComposer.ts +140 -32
  69. package/src/messageComposer/middleware/messageComposer/MessageComposerMiddlewareExecutor.ts +2 -0
  70. package/src/messageComposer/middleware/messageComposer/compositionValidation.ts +40 -47
  71. package/src/messageComposer/middleware/messageComposer/index.ts +1 -0
  72. package/src/messageComposer/middleware/messageComposer/scheduledMessage.ts +38 -0
  73. package/src/messageComposer/middleware/textComposer/commandUtils.ts +8 -0
  74. package/src/messageComposer/scheduledMessageComposition.ts +324 -0
  75. package/src/messageMarks/MessageMarkManager.ts +145 -0
  76. package/src/messageMarks/index.ts +1 -0
  77. package/src/messageOperations/MessageOperationStatePolicy.ts +7 -0
  78. package/src/messageOperations/MessageOperations.ts +154 -1
  79. package/src/messageOperations/index.ts +1 -0
  80. package/src/messageOperations/reflectMessageMarkEvent.ts +47 -0
  81. package/src/messageOperations/reflectReactionEvent.ts +3 -0
  82. package/src/messageOperations/sendOrdering.ts +11 -4
  83. package/src/messageOperations/types.ts +6 -2
  84. package/src/notifications/types.ts +4 -0
  85. package/src/offline-support/offline_support_api.ts +61 -1
  86. package/src/offline-support/queueableOperations.ts +6 -0
  87. package/src/offline-support/types.ts +28 -0
  88. package/src/pagination/PaginatorView.ts +103 -0
  89. package/src/pagination/index.ts +1 -0
  90. package/src/pagination/paginators/BasePaginator.ts +179 -27
  91. package/src/pagination/paginators/ChannelPaginator.ts +8 -28
  92. package/src/pagination/paginators/MessageIntervalPaginator.ts +4 -1
  93. package/src/pagination/paginators/MessageMarkPaginator.ts +222 -0
  94. package/src/pagination/paginators/ScheduledMessagePaginator.ts +352 -0
  95. package/src/pagination/paginators/index.ts +2 -0
  96. package/src/scheduledMessages/ScheduledMessagePaginatorsManager.ts +268 -0
  97. package/src/scheduledMessages/ScheduledMessageStatePolicy.ts +42 -0
  98. package/src/scheduledMessages/ScheduledMessagesView.ts +57 -0
  99. package/src/scheduledMessages/composition.ts +129 -0
  100. package/src/scheduledMessages/constants.ts +79 -0
  101. package/src/scheduledMessages/editResolvers.ts +51 -0
  102. package/src/scheduledMessages/errors.ts +45 -0
  103. package/src/scheduledMessages/eventHandlers.ts +58 -0
  104. package/src/scheduledMessages/index.ts +7 -0
  105. package/src/scheduledMessages/limits.ts +32 -0
  106. package/src/scheduledMessages/types.ts +124 -0
  107. package/src/thread.ts +41 -17
  108. package/src/utils.ts +18 -0
@@ -323,6 +323,15 @@ export type PaginatorOptions<T, Q> = {
323
323
  * Does not hold across interval changes or page jumps.
324
324
  */
325
325
  lockItemOrder?: boolean;
326
+ /**
327
+ * Where a newly ingested item lands in a loaded list that is already empty and complete. When the
328
+ * sort order follows arrival (recency lists: messages by `created_at`, channels by
329
+ * `last_message_at`), a new item is the newest and waits in the logical head, leaving the list
330
+ * re-queryable — so this stays `false`. When the sort order is independent of arrival (scheduled
331
+ * messages, by `scheduled_at`), completeness makes its slot known, so it anchors a real interval
332
+ * there instead; such paginators set this `true`. Defaults to `false`.
333
+ */
334
+ newItemsAnchorBySortPosition?: boolean;
326
335
  /**
327
336
  * Caps the loaded items: when the head interval exceeds it, the oldest are released as new ones
328
337
  * arrive and the tailward edge re-opens, so scrolling back re-fetches. Unset: unbounded. Values
@@ -416,6 +425,11 @@ export declare abstract class BasePaginator<T, Q, R = PaginationQueryReturnValue
416
425
  protected _lastQueryShape?: Q;
417
426
  /** Set by `setItems`, which loads a page (even an empty one) without a query. */
418
427
  private _pageSetWithoutQuery;
428
+ /**
429
+ * The IDs of the offline database's page (see {@link preloadFirstPageFromOfflineDb}) that no live
430
+ * event has touched since, until a page from the server takes their place.
431
+ */
432
+ private _offlineOnlyItemIds;
419
433
  /**
420
434
  * Stable, purely data-driven comparison (age, timestamps, ...). Default for
421
435
  * `itemOrderComparator`, which orders items and intervals and breaks `boostComparator` ties.
@@ -465,6 +479,8 @@ export declare abstract class BasePaginator<T, Q, R = PaginationQueryReturnValue
465
479
  * queries) still skips such a list. Cleared by `resetState`.
466
480
  */
467
481
  get hasLoadedPage(): boolean;
482
+ private get isLoadedEmptyAndComplete();
483
+ private placeEmptyCompleteFirstPage;
468
484
  get isOfflineSupportEnabled(): boolean;
469
485
  get isCursorPagination(): boolean;
470
486
  get initialState(): PaginatorState<T>;
@@ -951,7 +967,32 @@ export declare abstract class BasePaginator<T, Q, R = PaginationQueryReturnValue
951
967
  /** The page size a query's results are measured against when deriving the head/tail flags. */
952
968
  protected getRequestedPageSize(_queryShape: Q | undefined): number;
953
969
  protected getStateAfterQuery(stateUpdate: Partial<PaginatorState<T>>, _isFirstPage: boolean): PaginatorState<T>;
970
+ /**
971
+ * The offline database's copy of the first page, shown while the first query of a paginator not
972
+ * initialized yet runs. It is stored like a page, so live items join it. The first page from the
973
+ * server takes the place of its items no live event touched, as the copy can be arbitrarily old,
974
+ * and merges with the rest, as a loaded page would. A failed query leaves it shown. `undefined`
975
+ * (the default) shows nothing until the server answers.
976
+ */
954
977
  preloadFirstPageFromOfflineDb: (_params: PaginationQueryParams<Q>) => Promise<T[] | undefined> | T[] | undefined;
978
+ /** Whether the shown items are the offline database's page, not yet replaced by the server's. */
979
+ protected get showsOfflinePage(): boolean;
980
+ /**
981
+ * Stores the offline database's page as the head interval and returns its items, ordered. Without
982
+ * an interval behind them, the next live item would rebuild `state.items` without them.
983
+ */
984
+ private storeOfflinePage;
985
+ /**
986
+ * Shows the offline database's page without a query, for a subclass that defers its first query
987
+ * (see `ChannelPaginator.executeQuery`). Like the page of {@link preloadFirstPageFromOfflineDb},
988
+ * the first page from the server takes its place.
989
+ */
990
+ protected setItemsFromOfflineDb(items: T[]): void;
991
+ /**
992
+ * Takes the offline database's items no live event touched out of storage, without publishing:
993
+ * the server's page placed next publishes the list once.
994
+ */
995
+ private removeOfflineOnlyItems;
955
996
  populateOfflineDbAfterQuery: (_params: {
956
997
  items: T[] | undefined;
957
998
  queryShape: Q | undefined;
@@ -75,15 +75,6 @@ export declare class ChannelPaginator extends BasePaginator<Channel, ChannelQuer
75
75
  protected _predefinedFilter: ParsedPredefinedFilterResponse | undefined;
76
76
  /** Metadata of the in-flight response, committed by `placeQueryPage` on a first page only. */
77
77
  private _pendingPredefinedFilter;
78
- /**
79
- * True while the loaded items came only from the offline cache (seeded by `setItems`, never
80
- * confirmed by a query). The seed's offset and query shape would make the next query a
81
- * continuation, but a cache has no pagination position, so `executeQuery` forces a first page that
82
- * keeps the items.
83
- */
84
- private _itemsLoadedFromOfflineDB;
85
- /** The query in flight refreshes a cache-only interval, so its response replaces the interval. */
86
- private _replaceOfflineSeedOnResponse;
87
78
  /** The query handed to the sync manager, from the cache read until it runs. See `executeQuery`. */
88
79
  private _queryAwaitingSync;
89
80
  /** The cids of the page the latest query returned, `undefined` when it failed. */
@@ -0,0 +1,61 @@
1
+ import { BasePaginator } from './BasePaginator';
2
+ import type { ExecuteQueryReturnValue, PaginationQueryParams, PaginationQueryReturnValue, PaginatorOptions, PaginatorState, PlaceQueryPageParams } from './BasePaginator';
3
+ import type { MessageMarkWithUserResponse, QueryMessageMarksFilter, QueryMessageMarksRequest } from '../../types';
4
+ import type { StreamChat } from '../../client';
5
+ export type MessageMarkPaginatorOptions = {
6
+ /** Identifies the list in `client.messageMarks`. Generated when left out. */
7
+ id?: string;
8
+ /** The message whose marks are listed. */
9
+ messageId: string;
10
+ /** Lists only the marks it matches, for example `{ type: 'played' }`. */
11
+ filter?: QueryMessageMarksFilter;
12
+ /** How the list is fetched, for example its `pageSize`. */
13
+ paginatorOptions?: PaginatorOptions<MessageMarkWithUserResponse, QueryMessageMarksRequest>;
14
+ };
15
+ /**
16
+ * Lists the marks on one message, with the users who made them, newest first. The API pages
17
+ * forward only, so the headward cursor starts exhausted (`null`). New marks are added at the head
18
+ * through `ingestItem`, which `client.messageMarks` calls for `message.mark_added`.
19
+ *
20
+ * With offline support, the first page opens with the marks the offline database holds while the
21
+ * request runs, and keeps them when the request fails.
22
+ */
23
+ export declare class MessageMarkPaginator extends BasePaginator<MessageMarkWithUserResponse, QueryMessageMarksRequest> {
24
+ private client;
25
+ private readonly _id;
26
+ readonly messageId: string;
27
+ readonly filter: QueryMessageMarksFilter | undefined;
28
+ private activeRefCount;
29
+ private _isStateStale;
30
+ constructor(client: StreamChat, { id, messageId, filter, paginatorOptions }: MessageMarkPaginatorOptions);
31
+ get initialState(): PaginatorState<MessageMarkWithUserResponse>;
32
+ get id(): string;
33
+ getItemId(item: MessageMarkWithUserResponse): string;
34
+ /** See {@link MessageMarkPaginator.activate}. */
35
+ get active(): boolean;
36
+ /** Whether marks may have been missed, for example while the connection was down. */
37
+ get isStateStale(): boolean;
38
+ /**
39
+ * Call this when a screen starts showing the list, and call the returned function when it stops.
40
+ * A stale list reloads as soon as it is shown. The list counts as shown until every caller has
41
+ * released it, and releasing twice does nothing.
42
+ */
43
+ activate: () => (() => void);
44
+ /**
45
+ * Flags the loaded marks as possibly incomplete. An active list reloads now, an inactive one when
46
+ * it is next activated.
47
+ */
48
+ markStale: () => void;
49
+ private reloadIfStale;
50
+ get isOfflineSupportEnabled(): boolean;
51
+ preloadFirstPageFromOfflineDb: () => Promise<MessageMarkWithUserResponse[] | undefined>;
52
+ placeQueryPage(params: PlaceQueryPageParams<MessageMarkWithUserResponse, QueryMessageMarksRequest>): ExecuteQueryReturnValue<MessageMarkWithUserResponse>;
53
+ protected buildMatchFilters(): {
54
+ type?: string;
55
+ message_id: string;
56
+ };
57
+ protected getNextQueryShape(): QueryMessageMarksRequest;
58
+ protected fetchQueryResponse: ({ direction, queryShape, }: PaginationQueryParams<QueryMessageMarksRequest>) => Promise<PaginationQueryReturnValue<MessageMarkWithUserResponse>>;
59
+ /** The extracting step of the query pipeline: the response is the page. */
60
+ protected extractQueryPage(response: PaginationQueryReturnValue<MessageMarkWithUserResponse>, _params: PaginationQueryParams<QueryMessageMarksRequest>): PaginationQueryReturnValue<MessageMarkWithUserResponse>;
61
+ }
@@ -0,0 +1,83 @@
1
+ import type { PaginationQueryParams, PaginationQueryReturnValue, PaginatorOptions } from './BasePaginator';
2
+ import { BasePaginator } from './BasePaginator';
3
+ import type { EntityStore, EntityStoreChangeBatch } from '../../entityStore/EntityStore';
4
+ import type { StreamChat } from '../../client';
5
+ import type { QueryScheduledMessagesRequest, ScheduledMessageResponse, ScheduledMessagesFilter } from '../../gen/models';
6
+ export type ScheduledMessagePaginatorOptions = {
7
+ client: StreamChat;
8
+ /**
9
+ * The query filter, also deciding which ingested messages the list takes. `status` defaults to all
10
+ * the query accepts. Changed later through the `filter` setter.
11
+ */
12
+ filter?: ScheduledMessagesFilter;
13
+ /** Generated when omitted. */
14
+ id?: string;
15
+ paginatorOptions?: PaginatorOptions<ScheduledMessageResponse, QueryScheduledMessagesRequest>;
16
+ /** Defaults to `client.scheduledMessageStore`. */
17
+ store?: EntityStore<ScheduledMessageResponse>;
18
+ };
19
+ /** The current user's scheduled messages, earliest `scheduled_at` first. */
20
+ export declare class ScheduledMessagePaginator extends BasePaginator<ScheduledMessageResponse, QueryScheduledMessagesRequest> {
21
+ private readonly client;
22
+ private readonly _id;
23
+ private _filter;
24
+ constructor({ client, filter, id, paginatorOptions, store, }: ScheduledMessagePaginatorOptions);
25
+ get id(): string;
26
+ /** The query filter, sent as given: without a `status` the server lists all it lists. */
27
+ get filter(): ScheduledMessagesFilter;
28
+ /** Replaces the filter and resets the list; load it again with `reload()`. */
29
+ set filter(filter: ScheduledMessagesFilter);
30
+ get cid(): string | undefined;
31
+ getItemId(item: ScheduledMessageResponse): string;
32
+ protected getNextQueryShape(): QueryScheduledMessagesRequest;
33
+ /**
34
+ * The query filter, with the server's default statuses when it names none: matching on `status`
35
+ * is what takes sent and canceled messages out of the list. The matcher reads the array as any of
36
+ * them.
37
+ */
38
+ protected buildMatchFilters(): ScheduledMessagesFilter;
39
+ protected fetchQueryResponse: ({ direction, queryShape, }: PaginationQueryParams<QueryScheduledMessagesRequest>) => Promise<PaginationQueryReturnValue<ScheduledMessageResponse>>;
40
+ protected extractQueryPage(response: PaginationQueryReturnValue<ScheduledMessageResponse>): PaginationQueryReturnValue<ScheduledMessageResponse>;
41
+ filterQueryResults(items: ScheduledMessageResponse[]): ScheduledMessageResponse[];
42
+ ingestItem(item: ScheduledMessageResponse): boolean;
43
+ /** Places `item` by the list's filter and order: moves it, or takes it out when it no longer matches. */
44
+ private placeItem;
45
+ /** The IDs the list holds. */
46
+ getItemIds(): ReadonlySet<string>;
47
+ /** A page loaded and nothing more to load either way: the list holds every message it matches. */
48
+ private get holdsCompleteList();
49
+ /**
50
+ * Applies a complete set (e.g. a channel query's `scheduled_messages`) through the paginator's own
51
+ * operations: removes what was held at `itemIdsAtRequest` and is missing, and ingests the rest. A
52
+ * list that does not hold a complete set yet is replaced by it instead. Messages taken since the
53
+ * snapshot stay. Publishes once.
54
+ */
55
+ hydrate(scheduledMessages: ScheduledMessageResponse[], itemIdsAtRequest?: ReadonlySet<string>): void;
56
+ /**
57
+ * Re-queries the first page and applies it in place: the current messages stay until the response
58
+ * lands, unlike the base `reload()`, which empties the list first. A complete response is applied
59
+ * as {@link hydrate} does; a longer list is replaced by its first page. Messages taken by events
60
+ * while the request was out stay. A failed query keeps the list and records `lastQueryError`; a
61
+ * success clears it. Only the first load publishes `isLoading`. A call while one is in flight
62
+ * joins it.
63
+ */
64
+ reload: () => Promise<void>;
65
+ private reloadInFlight?;
66
+ private reloadGeneration;
67
+ private reloadWasSuperseded;
68
+ private reloadFirstPage;
69
+ /**
70
+ * Replaces the list with `page` as its first page. Messages taken by events since the request went
71
+ * out (held now, not at `itemIdsAtRequest`) stay; the others the page leaves out go. Publishes once.
72
+ */
73
+ private replaceWithFirstPage;
74
+ /**
75
+ * Another list stored a newer copy of items this one holds. A change can move a scheduled message
76
+ * (`scheduled_at`) or take it out of this list (`status`), so each changed item is placed by this
77
+ * list's filter and order.
78
+ */
79
+ onEntitiesChanged({ changedIds }: EntityStoreChangeBatch): void;
80
+ onEntityRemoved(id: string, item: unknown): void;
81
+ flushState(): void;
82
+ resetState(): void;
83
+ }
@@ -2,7 +2,9 @@ export * from './BasePaginator';
2
2
  export * from './ChannelPaginator';
3
3
  export { MessageIntervalPaginator } from './MessageIntervalPaginator';
4
4
  export * from './MessagePaginator';
5
+ export * from './MessageMarkPaginator';
5
6
  export * from './PinnedMessagePaginator';
6
7
  export * from './ReminderPaginator';
8
+ export * from './ScheduledMessagePaginator';
7
9
  export * from './UserGroupPaginator';
8
10
  export * from './ThreadPaginator';
@@ -0,0 +1,47 @@
1
+ import { StateStore } from '@stream-io/state-store';
2
+ import { EventHandlerPipeline } from '../EventHandlerPipeline';
3
+ import { WithSubscriptions } from '../utils/WithSubscriptions';
4
+ import type { Unsubscribe } from '@stream-io/state-store';
5
+ import type { StreamChat } from '../client';
6
+ import type { ScheduledMessageResponse } from '../gen/models';
7
+ import type { ScheduledMessagePaginator } from '../pagination/paginators/ScheduledMessagePaginator';
8
+ import type { AddScheduledMessageEventHandlerParams, RemoveScheduledMessageEventHandlersParams, ScheduledMessagePaginatorsManagerEventHandlerContext, ScheduledMessagePaginatorsManagerEventHandlers, ScheduledMessagePaginatorsManagerEventType, ScheduledMessagePaginatorsManagerOptions, ScheduledMessagePaginatorsManagerState, SetScheduledMessageEventHandlersParams } from './types';
9
+ export declare class ScheduledMessagePaginatorsManager extends WithSubscriptions {
10
+ private eventHandlerPipelines;
11
+ private queryErrorUnsubscribeByPaginator;
12
+ readonly client: StreamChat;
13
+ state: StateStore<ScheduledMessagePaginatorsManagerState>;
14
+ constructor({ client, eventHandlers, }: ScheduledMessagePaginatorsManagerOptions);
15
+ static getDefaultHandlers(): ScheduledMessagePaginatorsManagerEventHandlers;
16
+ get paginators(): ScheduledMessagePaginator[];
17
+ get isDisabled(): boolean;
18
+ get pipelines(): Map<ScheduledMessagePaginatorsManagerEventType, EventHandlerPipeline<ScheduledMessagePaginatorsManagerEventHandlerContext>>;
19
+ private get eventHandlerContext();
20
+ private installEventHandlers;
21
+ private watchQueryErrors;
22
+ private unwatchQueryErrors;
23
+ private updateIsDisabled;
24
+ ensurePipeline(eventType: ScheduledMessagePaginatorsManagerEventType): EventHandlerPipeline<ScheduledMessagePaginatorsManagerEventHandlerContext>;
25
+ addEventHandler({ eventType, ...payload }: AddScheduledMessageEventHandlerParams): Unsubscribe;
26
+ setEventHandlers({ eventType, handlers, }: SetScheduledMessageEventHandlersParams): void;
27
+ removeEventHandlers({ eventType, handlers, }: RemoveScheduledMessageEventHandlersParams): void;
28
+ getPaginatorById(id: string): ScheduledMessagePaginator | undefined;
29
+ setPaginators(paginators: ScheduledMessagePaginator[]): void;
30
+ clearPaginators(): ScheduledMessagePaginator[];
31
+ insertPaginator({ index, paginator, }: {
32
+ paginator: ScheduledMessagePaginator;
33
+ index?: number;
34
+ }): void;
35
+ removePaginator(paginatorOrId: ScheduledMessagePaginator | string): ScheduledMessagePaginator | undefined;
36
+ resetPaginatorStates(): void;
37
+ ingest: (scheduledMessage: ScheduledMessageResponse) => void;
38
+ recover: () => Promise<void>;
39
+ /**
40
+ * Starts syncing the registered lists with the client's WS events. Nothing keeps them in sync
41
+ * until this is called, so an integration has to call it once a user is connected and call the
42
+ * returned unsubscribe (or {@link unregisterSubscriptions}) on teardown. The Stream UI SDKs do
43
+ * this for you; a pure-LLC integration must do it itself. Ref-counted, so several holders can
44
+ * share one manager and only the last unsubscribe tears the subscriptions down.
45
+ */
46
+ registerSubscriptions(): Unsubscribe;
47
+ }
@@ -0,0 +1,12 @@
1
+ import type { ScheduledMessageResponse } from '../gen/models';
2
+ export type ScheduledMessageOperationKind = 'schedule' | 'update' | 'cancel' | 'sendNow';
3
+ export type ScheduledMessageStatePolicyContext = {
4
+ ingest: (scheduledMessage: ScheduledMessageResponse) => void;
5
+ get: (id: string) => ScheduledMessageResponse | undefined;
6
+ };
7
+ export declare class ScheduledMessageStatePolicy {
8
+ private ctx;
9
+ constructor(ctx: ScheduledMessageStatePolicyContext);
10
+ success(kind: ScheduledMessageOperationKind, scheduledMessage: ScheduledMessageResponse | undefined): void;
11
+ failure(kind: ScheduledMessageOperationKind, id: string | undefined, error: unknown): void;
12
+ }
@@ -0,0 +1,38 @@
1
+ import type { PaginatorViewState } from '../pagination/PaginatorView';
2
+ import { PaginatorView } from '../pagination/PaginatorView';
3
+ import type { ScheduledMessageResponse } from '../gen/models';
4
+ import type { ScheduledMessagePaginator } from '../pagination/paginators/ScheduledMessagePaginator';
5
+ /**
6
+ * Which of its paginator's scheduled messages a view shows.
7
+ * - `all`: every one, e.g. of a list registered with `client.scheduledMessagePaginators`.
8
+ * - `channel`: a channel's own, without thread replies.
9
+ * - `thread`: the replies of the thread whose parent message is `parentId`.
10
+ */
11
+ export type ScheduledMessagesViewScope = {
12
+ type: 'all';
13
+ } | {
14
+ type: 'channel';
15
+ } | {
16
+ parentId: string;
17
+ type: 'thread';
18
+ };
19
+ export type ScheduledMessagesViewState = PaginatorViewState<ScheduledMessageResponse>;
20
+ export type ScheduledMessagesViewOptions = {
21
+ /** The list the messages come from. The view only reads it. */
22
+ paginator: ScheduledMessagePaginator;
23
+ /** Defaults to `{ type: 'all' }`. */
24
+ scope?: ScheduledMessagesViewScope;
25
+ };
26
+ /**
27
+ * A scope of a `ScheduledMessagePaginator`, e.g. a channel's own scheduled messages or a thread's
28
+ * scheduled replies. The server cannot filter scheduled messages by thread, so a channel's
29
+ * paginator holds both, and each scope is a `PaginatorView` of it rather than a list of
30
+ * its own. `Channel` and `Thread` hold theirs registered while they are.
31
+ */
32
+ export declare class ScheduledMessagesView extends PaginatorView<ScheduledMessageResponse> {
33
+ readonly paginator: ScheduledMessagePaginator;
34
+ readonly scope: ScheduledMessagesViewScope;
35
+ constructor({ paginator, scope }: ScheduledMessagesViewOptions);
36
+ /** The thread's parent message ID, for a `thread` scope. */
37
+ get parentId(): string | undefined;
38
+ }
@@ -0,0 +1,5 @@
1
+ import type { MessageRequest, ScheduledMessageResponse } from '../gen/models';
2
+ import type { DraftMessage, LocalMessage } from '../types';
3
+ export declare const toComposerContent: (scheduledMessage: ScheduledMessageResponse) => DraftMessage;
4
+ export declare const toScheduledMessagePayload: (composedMessage: MessageRequest, scheduledMessage: ScheduledMessageResponse) => MessageRequest;
5
+ export declare const toScheduledMessagePreview: (scheduledMessage: ScheduledMessageResponse) => LocalMessage;
@@ -0,0 +1,56 @@
1
+ import type { ScheduledMessageQueryStatus } from '../gen/models';
2
+ export declare const SCHEDULED_MESSAGE_STATUS: {
3
+ readonly Canceled: "canceled";
4
+ readonly Failed: "failed";
5
+ readonly Scheduled: "scheduled";
6
+ readonly Sending: "sending";
7
+ readonly Sent: "sent";
8
+ };
9
+ export declare const SCHEDULED_MESSAGE_ACTIVE_STATUSES: ScheduledMessageQueryStatus[];
10
+ export declare const SCHEDULED_MESSAGE_FAILURE_REASON: {
11
+ readonly Banned: "banned";
12
+ readonly ChannelDeleted: "channel_deleted";
13
+ readonly ChannelFrozen: "channel_frozen";
14
+ readonly Expired: "expired";
15
+ readonly HookRejected: "hook_rejected";
16
+ readonly InternalError: "internal_error";
17
+ readonly InvalidMessage: "invalid_message";
18
+ readonly ModerationBlocked: "moderation_blocked";
19
+ readonly NoPermission: "no_permission";
20
+ readonly PendingNotSupported: "pending_not_supported";
21
+ readonly UserDeleted: "user_deleted";
22
+ };
23
+ export declare const ScheduledMessageErrorReason: {
24
+ readonly AlreadySent: "scheduled_message_already_sent";
25
+ readonly Canceled: "scheduled_message_canceled";
26
+ readonly ChannelLimit: "scheduled_limit_channel";
27
+ readonly Conflict: "scheduled_message_conflict";
28
+ readonly Disabled: "scheduled_messages_disabled";
29
+ readonly IdTaken: "scheduled_message_id_taken";
30
+ readonly NotEditable: "scheduled_message_not_editable";
31
+ readonly Sending: "scheduled_message_sending";
32
+ readonly TooFar: "scheduled_at_too_far";
33
+ readonly TooSoon: "scheduled_at_too_soon";
34
+ readonly UserLimit: "scheduled_limit_user";
35
+ };
36
+ export type ScheduledMessageErrorReason = (typeof ScheduledMessageErrorReason)[keyof typeof ScheduledMessageErrorReason];
37
+ export declare const ScheduledMessageBlockReason: {
38
+ readonly Command: "command";
39
+ readonly SharedLocation: "shared_location";
40
+ readonly Unavailable: "unavailable";
41
+ };
42
+ export type ScheduledMessageBlockReason = (typeof ScheduledMessageBlockReason)[keyof typeof ScheduledMessageBlockReason];
43
+ export declare const ScheduledMessageCompositionEndReason: {
44
+ readonly Deleted: "deleted";
45
+ readonly Failed: "failed";
46
+ readonly Sent: "sent";
47
+ };
48
+ export type ScheduledMessageCompositionEndReason = (typeof ScheduledMessageCompositionEndReason)[keyof typeof ScheduledMessageCompositionEndReason];
49
+ export declare const ScheduledMessageEventType: {
50
+ readonly Created: "scheduled_message.created";
51
+ readonly Deleted: "scheduled_message.deleted";
52
+ readonly Failed: "scheduled_message.failed";
53
+ readonly Sent: "scheduled_message.sent";
54
+ readonly Updated: "scheduled_message.updated";
55
+ };
56
+ export type ScheduledMessageEventType = (typeof ScheduledMessageEventType)[keyof typeof ScheduledMessageEventType];
@@ -0,0 +1,4 @@
1
+ import type { StreamChat } from '../client';
2
+ import type { LocalMessage, UserResponse } from '../types';
3
+ export declare const resolveUsersByIds: (client: StreamChat, userIds?: string[]) => Promise<UserResponse[]>;
4
+ export declare const resolveMessageById: (client: StreamChat, id: string) => Promise<LocalMessage | null>;
@@ -0,0 +1,3 @@
1
+ import { ScheduledMessageErrorReason } from './constants';
2
+ export declare const getScheduledMessageErrorReason: (error: unknown) => ScheduledMessageErrorReason | undefined;
3
+ export declare const isScheduledMessageNotFoundError: (error: unknown) => boolean;
@@ -0,0 +1,8 @@
1
+ import type { ScheduledMessageResponse } from '../gen/models';
2
+ import type { ScheduledMessagePaginatorsManagerEventHandlers } from './types';
3
+ /** The event's scheduled message in the status the event leaves it in (`deleted` → canceled, `sent` → sent). */
4
+ export declare const getScheduledMessageFromEvent: ({ scheduled_message: scheduledMessage, type, }: {
5
+ scheduled_message?: ScheduledMessageResponse;
6
+ type: string;
7
+ }) => ScheduledMessageResponse | undefined;
8
+ export declare const DEFAULT_SCHEDULED_MESSAGE_EVENT_HANDLERS: ScheduledMessagePaginatorsManagerEventHandlers;
@@ -0,0 +1,7 @@
1
+ export * from './ScheduledMessagePaginatorsManager';
2
+ export { toScheduledMessagePreview } from './composition';
3
+ export * from './constants';
4
+ export * from './errors';
5
+ export * from './limits';
6
+ export * from './types';
7
+ export * from './ScheduledMessagesView';
@@ -0,0 +1,6 @@
1
+ import type { Channel } from '../channel';
2
+ import type { ScheduledMessageLimits } from './types';
3
+ type ChannelServerConfig = Channel['serverConfig'];
4
+ export declare const getScheduledMessageLimitsFromServerConfig: (serverConfig: ChannelServerConfig) => ScheduledMessageLimits | undefined;
5
+ export declare const getScheduledMessageLimits: (channel: Channel) => ScheduledMessageLimits | undefined;
6
+ export {};
@@ -0,0 +1,65 @@
1
+ import type { StreamChat } from '../client';
2
+ import type { FindEventHandlerParams, InsertEventHandlerPayload, LabeledEventHandler } from '../EventHandlerPipeline';
3
+ import type { DeleteScheduledMessageResponse, MessageRequest, SendMessageRequest, SendMessageResponse, SendScheduledMessageNowResponse, UpdateScheduledMessageRequest, UpdateScheduledMessageResponse } from '../gen/models';
4
+ import type { EventType, LocalMessage, SendMessageOptions, StreamResponse } from '../types';
5
+ import type { ScheduledMessagePaginator } from '../pagination/paginators/ScheduledMessagePaginator';
6
+ import type { ScheduledMessagePaginatorsManager } from './ScheduledMessagePaginatorsManager';
7
+ export type ScheduledMessagePaginatorsManagerState = {
8
+ /** A registered list's last query failed with error 114 (feature off). */
9
+ isDisabled: boolean;
10
+ paginators: ScheduledMessagePaginator[];
11
+ };
12
+ export type ScheduledMessagePaginatorsManagerEventHandlerContext = {
13
+ scheduledMessagePaginators: ScheduledMessagePaginatorsManager;
14
+ };
15
+ export type ScheduledMessagePaginatorsManagerEventType = EventType | (string & {});
16
+ export type ScheduledMessagePaginatorsManagerEventHandlers = Partial<Record<ScheduledMessagePaginatorsManagerEventType, LabeledEventHandler<ScheduledMessagePaginatorsManagerEventHandlerContext>[]>>;
17
+ export type AddScheduledMessageEventHandlerParams = {
18
+ eventType: ScheduledMessagePaginatorsManagerEventType;
19
+ } & InsertEventHandlerPayload<ScheduledMessagePaginatorsManagerEventHandlerContext>;
20
+ export type SetScheduledMessageEventHandlersParams = {
21
+ eventType: ScheduledMessagePaginatorsManagerEventType;
22
+ handlers: LabeledEventHandler<ScheduledMessagePaginatorsManagerEventHandlerContext>[];
23
+ };
24
+ export type RemoveScheduledMessageEventHandlersParams = {
25
+ eventType: ScheduledMessagePaginatorsManagerEventType;
26
+ handlers: FindEventHandlerParams<ScheduledMessagePaginatorsManagerEventHandlerContext>[];
27
+ };
28
+ export type DefaultScheduledMessageRequest<TParams, TResponse> = (params: TParams) => Promise<StreamResponse<TResponse>>;
29
+ export type ScheduledMessageRequestFn<TParams, TResponse> = (params: TParams, defaultRequest: DefaultScheduledMessageRequest<TParams, TResponse>) => Promise<StreamResponse<TResponse>>;
30
+ export type ScheduleMessageParams = {
31
+ message: MessageRequest;
32
+ options?: SendMessageOptions;
33
+ localMessage?: LocalMessage;
34
+ };
35
+ export type UpdateScheduledMessageParams = {
36
+ request: UpdateScheduledMessageRequest;
37
+ localMessage?: LocalMessage;
38
+ };
39
+ export type ScheduledMessageIdRequestParams = {
40
+ id: string;
41
+ };
42
+ export type UpdateScheduledMessageRequestParams = {
43
+ id: string;
44
+ request: UpdateScheduledMessageRequest;
45
+ };
46
+ export type ScheduleMessageRequestFn = ScheduledMessageRequestFn<SendMessageRequest, SendMessageResponse>;
47
+ export type UpdateScheduledMessageRequestFn = ScheduledMessageRequestFn<UpdateScheduledMessageRequestParams, UpdateScheduledMessageResponse>;
48
+ export type DeleteScheduledMessageRequestFn = ScheduledMessageRequestFn<ScheduledMessageIdRequestParams, DeleteScheduledMessageResponse>;
49
+ export type SendScheduledMessageNowRequestFn = ScheduledMessageRequestFn<ScheduledMessageIdRequestParams, SendScheduledMessageNowResponse>;
50
+ export type ScheduledMessageRequestHandlers = {
51
+ deleteScheduledMessageRequest?: DeleteScheduledMessageRequestFn;
52
+ scheduleMessageRequest?: ScheduleMessageRequestFn;
53
+ sendScheduledMessageNowRequest?: SendScheduledMessageNowRequestFn;
54
+ updateScheduledMessageRequest?: UpdateScheduledMessageRequestFn;
55
+ };
56
+ export type ScheduledMessagePaginatorsManagerOptions = {
57
+ client: StreamChat;
58
+ eventHandlers?: ScheduledMessagePaginatorsManagerEventHandlers;
59
+ };
60
+ export type ScheduledMessageLimits = {
61
+ maxLeadTimeSeconds: number;
62
+ maxPerChannel: number;
63
+ maxPerUser: number;
64
+ minLeadTimeSeconds: number;
65
+ };
@@ -6,6 +6,7 @@ import type { CustomThreadData } from './custom_types';
6
6
  import { MessageComposer } from './messageComposer';
7
7
  import type { MessageOperations } from './messageOperations';
8
8
  import { WithSubscriptions } from './utils/WithSubscriptions';
9
+ import { ScheduledMessagesView } from './scheduledMessages/ScheduledMessagesView';
9
10
  import { MessagePaginator } from './pagination';
10
11
  import type { ReconcileNewestMessagesOptions } from './pagination';
11
12
  import type { ThreadDeclarativeConfig } from './configuration/types';
@@ -57,6 +58,13 @@ export declare class Thread extends WithSubscriptions {
57
58
  readonly messageComposer: MessageComposer;
58
59
  readonly messageOperations: MessageOperations;
59
60
  readonly messagePaginator: MessagePaginator;
61
+ /**
62
+ * The current user's scheduled replies in this thread: a view of the channel's
63
+ * `scheduledMessagesPaginator`, which holds the channel's scheduled messages and replies alike
64
+ * (the server cannot filter them by thread). Follows it while the thread's subscriptions are
65
+ * registered.
66
+ */
67
+ readonly scheduledMessages: ScheduledMessagesView;
60
68
  private client;
61
69
  private failedRepliesMap;
62
70
  private _activeRefCount;
@@ -123,6 +131,7 @@ export declare class Thread extends WithSubscriptions {
123
131
  handleThreadUpdated: (event: EventPayload<"thread.updated">) => void;
124
132
  private subscribeMarkActiveThreadRead;
125
133
  private subscribeReloadActiveStaleThread;
134
+ private subscribeLoadScheduledMessagesWhenActive;
126
135
  /**
127
136
  * A watch stopped while the connection stays up (`NotWatching`) ends the channel's events with no
128
137
  * reconnect to catch it. A dropped connection (`WasWatching`) is left to recovery.
@@ -162,5 +171,7 @@ export declare class Thread extends WithSubscriptions {
162
171
  }
163
172
  /** `participant_limit` of the single-thread requests (`getThreadAndHydrate`, `reload()`). */
164
173
  export declare const DEFAULT_THREAD_PARTICIPANT_LIMIT = 100;
165
- /** The thread's channel, with the members and custom data of `threadData` applied. */
174
+ /**
175
+ * The thread's channel, with the members, custom data and server config of `threadData` applied.
176
+ */
166
177
  export declare const ensureThreadChannel: (client: StreamChat, threadData: ThreadStateResponse) => Channel;
@@ -16,6 +16,10 @@ export declare function logChatPromiseExecution<T>(promise: Promise<T>, name: st
16
16
  export declare const invokeEventListener: <T>(listener: (event: T) => unknown, event: T, scopedLogger: ScopedLogger) => void;
17
17
  export declare const sleep: (m: number) => Promise<void>;
18
18
  export declare function isFunction(value: unknown): value is (...args: unknown[]) => unknown;
19
+ export declare const pickFields: <T extends object, K extends keyof T>(source: T, fields: readonly K[]) => Pick<T, K>;
20
+ export declare const omitFields: <T extends object>(source: T, fields: ReadonlySet<string>) => {
21
+ [k: string]: any;
22
+ };
19
23
  export declare const chatCodes: {
20
24
  TOKEN_EXPIRED: number;
21
25
  WS_CLOSED_SUCCESS: number;
@@ -24,6 +28,7 @@ export declare function isOwnUser(user?: OwnUserResponse | UserResponse): user i
24
28
  export declare function isOwnUserBaseProperty(property: string): boolean;
25
29
  /** Whether `read-events` is among the own capabilities (true while they are not loaded). */
26
30
  export declare const channelHasReadEvents: (channel?: Channel) => boolean;
31
+ export declare const channelCanScheduleMessages: (channel?: Channel) => boolean;
27
32
  /** Whether read events are off and the channel keeps a client-local unread count. */
28
33
  export declare const channelTracksReadLocally: (channel?: Channel) => boolean;
29
34
  /** A random retry delay in milliseconds that grows with `numberOfFailures`. */
@@ -136,10 +141,12 @@ export declare const toDeletedMessage: ({ message, deletedAt, hardDelete, }: {
136
141
  mentioned_group_ids?: Array<string>;
137
142
  mentioned_groups?: Array<import(".").UserGroupResponse>;
138
143
  mentioned_roles?: Array<string>;
144
+ own_marks?: Array<import(".").OwnMarkResponse>;
139
145
  thread_participants?: Array<UserResponse>;
140
146
  draft?: import(".").DraftResponse;
141
147
  i18n?: Record<string, string>;
142
148
  image_labels?: Record<string, Array<string>>;
149
+ mark_groups?: Record<string, import(".").MarkGroupResponse>;
143
150
  member?: import(".").ChannelMemberPartialResponse;
144
151
  mentioned_channel_members?: Record<string, import(".").ChannelMemberPartialResponse>;
145
152
  moderation?: import(".").ModerationV2Response;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stream-chat",
3
- "version": "10.2.0",
3
+ "version": "10.3.0",
4
4
  "description": "JS SDK for the Stream Chat API",
5
5
  "homepage": "https://getstream.io/chat/",
6
6
  "author": {