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
@@ -9,6 +9,8 @@ import type {
9
9
  BulkDeleteActionConfigResponse,
10
10
  BulkUpsertActionConfigRequest,
11
11
  BulkUpsertActionConfigResponse,
12
+ CountReviewQueueRequest,
13
+ CountReviewQueueResponse,
12
14
  CreateQueueRequest,
13
15
  DeleteActionConfigResponse,
14
16
  DeleteModerationConfigResponse,
@@ -473,6 +475,21 @@ export class ModerationApi {
473
475
  );
474
476
  }
475
477
 
478
+ countReviewQueue(
479
+ request?: CountReviewQueueRequest,
480
+ requestOptions?: StreamRequestOptions,
481
+ ): Promise<StreamResponse<CountReviewQueueResponse>> {
482
+ return this.apiClient.sendRequest<CountReviewQueueResponse>(
483
+ 'POST',
484
+ '/api/v2/moderation/review_queue/count',
485
+ undefined,
486
+ undefined,
487
+ request ?? {},
488
+ 'application/json',
489
+ requestOptions,
490
+ );
491
+ }
492
+
476
493
  submitAction(
477
494
  request: SubmitActionRequest,
478
495
  requestOptions?: StreamRequestOptions,
@@ -489,11 +506,15 @@ export class ModerationApi {
489
506
  }
490
507
 
491
508
  unban(
492
- request: UnbanRequest & { target_user_id: string; channel_cid?: string },
509
+ request: UnbanRequest & {
510
+ target_user_id: string;
511
+ channel_cid?: string;
512
+ remove_future_channels_ban?: boolean;
513
+ },
493
514
  requestOptions?: StreamRequestOptions,
494
515
  ): Promise<StreamResponse<UnbanResponse>> {
495
- const { target_user_id, channel_cid, ...body } = request;
496
- const queryParams = { target_user_id, channel_cid };
516
+ const { target_user_id, channel_cid, remove_future_channels_ban, ...body } = request;
517
+ const queryParams = { target_user_id, channel_cid, remove_future_channels_ban };
497
518
 
498
519
  return this.apiClient.sendRequest<UnbanResponse>(
499
520
  'POST',
package/src/index.ts CHANGED
@@ -64,6 +64,8 @@ export * from './pagination';
64
64
  export * from './poll';
65
65
  export * from './poll_manager';
66
66
  export * from './reminders';
67
+ export * from './messageMarks';
68
+ export * from './scheduledMessages';
67
69
  export * from './search';
68
70
  export * from './signing';
69
71
  export * from './languageNames';
@@ -91,6 +91,31 @@ const toUploadError = (rejection: unknown) =>
91
91
  ? (rejection as Error)
92
92
  : new Error('unknown error', { cause: rejection });
93
93
 
94
+ const isUploading = (attachment: LocalAttachment) =>
95
+ attachment.localMetadata.uploadState === 'uploading';
96
+
97
+ const toFailedUpload = (attachment: LocalAttachment) =>
98
+ ({
99
+ ...attachment,
100
+ localMetadata: {
101
+ ...attachment.localMetadata,
102
+ uploadConfirmationPending: false,
103
+ uploadProgress: undefined,
104
+ uploadState: 'failed',
105
+ },
106
+ }) as LocalAttachment;
107
+
108
+ const mapSnapshotAttachments = (
109
+ snapshot: AttachmentManagerSnapshot,
110
+ mapAttachment: (attachment: LocalAttachment) => LocalAttachment,
111
+ ): AttachmentManagerSnapshot => {
112
+ const attachments = snapshot.attachments.map(mapAttachment);
113
+ const hasUpdates = attachments.some(
114
+ (attachment, index) => attachment !== snapshot.attachments[index],
115
+ );
116
+ return hasUpdates ? { ...snapshot, attachments } : snapshot;
117
+ };
118
+
94
119
  export class AttachmentManager {
95
120
  readonly state: StateStore<AttachmentManagerState>;
96
121
  readonly composer: MessageComposer;
@@ -270,19 +295,22 @@ export class AttachmentManager {
270
295
  };
271
296
 
272
297
  private normalizeSnapshotAttachment = (attachment: LocalAttachment) => {
273
- if (attachment.localMetadata.uploadState !== 'uploading') return attachment;
298
+ if (!isUploading(attachment)) return attachment;
274
299
 
275
300
  this.client.uploadManager.deleteUploadRecord(attachment.localMetadata.id);
276
301
 
277
- return {
278
- ...attachment,
279
- localMetadata: {
280
- ...attachment.localMetadata,
281
- uploadConfirmationPending: false,
282
- uploadProgress: undefined,
283
- uploadState: 'failed',
284
- },
285
- } as LocalAttachment;
302
+ return toFailedUpload(attachment);
303
+ };
304
+
305
+ private failUntrackedUpload = (attachment: LocalAttachment) => {
306
+ if (
307
+ !isUploading(attachment) ||
308
+ this.client.uploadManager.getUpload(attachment.localMetadata.id)
309
+ ) {
310
+ return attachment;
311
+ }
312
+
313
+ return toFailedUpload(attachment);
286
314
  };
287
315
 
288
316
  initState = ({ message }: { message?: DraftMessage | LocalMessage } = {}) => {
@@ -305,24 +333,15 @@ export class AttachmentManager {
305
333
  }
306
334
  };
307
335
 
308
- getSnapshot = (): AttachmentManagerSnapshot => {
309
- const state = this.state.getLatestValue();
310
- let hasUpdates = false;
311
- const attachments = state.attachments.map(this.normalizeSnapshotAttachment);
336
+ getSnapshot = (): AttachmentManagerSnapshot =>
337
+ mapSnapshotAttachments(this.state.getLatestValue(), this.normalizeSnapshotAttachment);
312
338
 
313
- for (let i = 0; i < attachments.length; i++) {
314
- if (attachments[i] !== state.attachments[i]) {
315
- hasUpdates = true;
316
- break;
317
- }
318
- }
319
-
320
- return hasUpdates ? { ...state, attachments } : state;
321
- };
339
+ getSnapshotKeepingUploads = (): AttachmentManagerSnapshot =>
340
+ this.state.getLatestValue();
322
341
 
323
342
  restoreSnapshot = (snapshot: AttachmentManagerSnapshot) => {
324
343
  this.cancelAttachmentUploads(this.attachments);
325
- this.state.next(snapshot);
344
+ this.state.next(mapSnapshotAttachments(snapshot, this.failUntrackedUpload));
326
345
  };
327
346
 
328
347
  setAttachments = (attachments: LocalAttachment[]) => {
@@ -12,3 +12,4 @@ export * from './pollComposer';
12
12
  export * from './textComposer';
13
13
  export * from './types';
14
14
  export type { CustomTextComposerSuggestion } from './types.custom';
15
+ export type { ScheduledMessageSubmitResult } from './scheduledMessageComposition';
@@ -1,5 +1,5 @@
1
1
  import { CORE_NOTIFICATION_TYPE } from '../notifications';
2
- import type { CoreNotificationType } from '../notifications';
2
+ import type { CoreNotificationType, NotificationOptions } from '../notifications';
3
3
  import { AttachmentManager } from './attachmentManager';
4
4
  import { isResolvableUpload, isSendableAttachment } from './attachmentIdentity';
5
5
  import { CustomDataManager } from './CustomDataManager';
@@ -36,6 +36,7 @@ import type {
36
36
  EventType,
37
37
  LocalMessage,
38
38
  MessageResponse,
39
+ SendMessageOptions,
39
40
  TimestampNS,
40
41
  UserResponse,
41
42
  } from '../types';
@@ -60,6 +61,10 @@ import {
60
61
  getMentionedUsersInText,
61
62
  stripCommandFromText,
62
63
  } from './middleware/textComposer/commandUtils';
64
+ import { CommandSearchSource } from './middleware/textComposer/commands';
65
+ import { ScheduledMessageComposition } from './scheduledMessageComposition';
66
+ import type { ScheduledMessageResponse } from '../gen/models';
67
+ import { toComposerContent } from '../scheduledMessages/composition';
63
68
 
64
69
  type UnregisterSubscriptions = Unsubscribe;
65
70
 
@@ -118,6 +123,11 @@ export type MessageComposerState = {
118
123
  showReplyInChannel: boolean;
119
124
  /** Baseline of the message being edited, unchanged during the session (for restore or cancel). */
120
125
  editedMessage: LocalMessage | null;
126
+ editedScheduledMessage: ScheduledMessageResponse | null;
127
+ };
128
+
129
+ export type MessageComposerComposeOptions = {
130
+ sendOptions?: SendMessageOptions;
121
131
  };
122
132
 
123
133
  export type MessageComposerOptions = {
@@ -132,12 +142,21 @@ export type MessageComposerOptions = {
132
142
  const compositionIsDraftResponse = (composition: unknown): composition is DraftResponse =>
133
143
  !!(composition as { message?: DraftMessage })?.message;
134
144
 
145
+ const compositionIsScheduledMessage = (
146
+ composition: unknown,
147
+ ): composition is ScheduledMessageResponse =>
148
+ (composition as Partial<ScheduledMessageResponse> | undefined)?.scheduled_at !==
149
+ undefined;
150
+
135
151
  const initEditingAuditState = (
136
- composition?: DraftResponse | MessageResponse | LocalMessage,
152
+ composition?: DraftResponse | MessageResponse | LocalMessage | ScheduledMessageResponse,
137
153
  ): EditingAuditState => {
138
154
  let draftUpdate = null;
139
155
  let stateUpdate = nowNs();
140
- if (compositionIsDraftResponse(composition)) {
156
+
157
+ if (compositionIsScheduledMessage(composition)) {
158
+ stateUpdate = composition.updated_at;
159
+ } else if (compositionIsDraftResponse(composition)) {
141
160
  stateUpdate = draftUpdate = composition.created_at;
142
161
  } else if (composition && isLocalMessage(composition)) {
143
162
  stateUpdate = composition.updated_at;
@@ -151,7 +170,7 @@ const initEditingAuditState = (
151
170
  };
152
171
 
153
172
  const initState = (
154
- composition?: DraftResponse | MessageResponse | LocalMessage,
173
+ composition?: DraftResponse | MessageResponse | LocalMessage | ScheduledMessageResponse,
155
174
  ): MessageComposerState => {
156
175
  if (!composition) {
157
176
  return {
@@ -161,6 +180,22 @@ const initState = (
161
180
  quotedMessage: null,
162
181
  showReplyInChannel: false,
163
182
  editedMessage: null,
183
+ editedScheduledMessage: null,
184
+ };
185
+ }
186
+
187
+ if (compositionIsScheduledMessage(composition)) {
188
+ const { poll_id: pollId = null, show_in_channel: showReplyInChannel = false } =
189
+ composition.message;
190
+
191
+ return {
192
+ draftId: null,
193
+ id: MessageComposer.generateId(),
194
+ pollId,
195
+ quotedMessage: null,
196
+ showReplyInChannel,
197
+ editedMessage: null,
198
+ editedScheduledMessage: composition,
164
199
  };
165
200
  }
166
201
 
@@ -186,6 +221,7 @@ const initState = (
186
221
  quotedMessage: quotedMessage ? formatMessage(quotedMessage) : null,
187
222
  showReplyInChannel: false,
188
223
  editedMessage,
224
+ editedScheduledMessage: null,
189
225
  };
190
226
  };
191
227
 
@@ -210,7 +246,9 @@ export class MessageComposer extends WithSubscriptions {
210
246
  pollComposer: PollComposer;
211
247
  locationComposer: LocationComposer;
212
248
  customDataManager: CustomDataManager;
249
+ private readonly scheduledMessageComposition: ScheduledMessageComposition;
213
250
  private snapshots: MessageComposerSnapshot[] = [];
251
+ private _commandSearchSource?: CommandSearchSource;
214
252
  private effectHandlers: MessageComposerEffectHandlers;
215
253
  private readonly configController: ConfigController<
216
254
  MessageComposerConfig,
@@ -274,6 +312,9 @@ export class MessageComposer extends WithSubscriptions {
274
312
  this.textComposer = new TextComposer({ composer: this, message });
275
313
  this.pollComposer = new PollComposer({ composer: this });
276
314
  this.customDataManager = new CustomDataManager({ composer: this, message });
315
+ this.scheduledMessageComposition = new ScheduledMessageComposition({
316
+ composer: this,
317
+ });
277
318
 
278
319
  this.editingAuditState = new StateStore<EditingAuditState>(
279
320
  this.initEditingAuditState(composition),
@@ -328,6 +369,22 @@ export class MessageComposer extends WithSubscriptions {
328
369
  }
329
370
  };
330
371
 
372
+ get hasEditInProgress() {
373
+ return !!this.editedMessage || this.scheduledMessageComposition.blocksNewComposition;
374
+ }
375
+
376
+ private get pausesDrafts() {
377
+ return !!this.editedMessage || !!this.editedScheduledMessage;
378
+ }
379
+
380
+ get editedScheduledMessage(): ScheduledMessageResponse | undefined {
381
+ return this.state.getLatestValue().editedScheduledMessage ?? undefined;
382
+ }
383
+
384
+ get scheduleBlockReason() {
385
+ return this.scheduledMessageComposition.scheduleBlockReason;
386
+ }
387
+
331
388
  get contextType() {
332
389
  return MessageComposer.evaluateContextType(this.compositionContext);
333
390
  }
@@ -389,7 +446,7 @@ export class MessageComposer extends WithSubscriptions {
389
446
  getCommandDisabledReason = (
390
447
  command: Command,
391
448
  ): CommandSuggestionDisabledReason | undefined => {
392
- if (this.editedMessage) return 'editing';
449
+ if (this.hasEditInProgress) return 'editing';
393
450
 
394
451
  if (
395
452
  this.quotedMessage &&
@@ -433,6 +490,10 @@ export class MessageComposer extends WithSubscriptions {
433
490
  return !currentCommand || this.validateCommandSendability(currentCommand).ready;
434
491
  }
435
492
 
493
+ get commandSearchSource(): CommandSearchSource {
494
+ return (this._commandSearchSource ??= new CommandSearchSource(this.channel));
495
+ }
496
+
436
497
  /** See {@link AttachmentManagerConfig.pendingUploadsEnabled}. */
437
498
  get allowsPendingUploads() {
438
499
  return this.attachmentManager.config.pendingUploadsEnabled;
@@ -595,16 +656,24 @@ export class MessageComposer extends WithSubscriptions {
595
656
 
596
657
  initState = ({
597
658
  composition,
598
- }: { composition?: DraftResponse | MessageResponse | LocalMessage } = {}) => {
659
+ }: {
660
+ composition?:
661
+ | DraftResponse
662
+ | MessageResponse
663
+ | LocalMessage
664
+ | ScheduledMessageResponse;
665
+ } = {}) => {
599
666
  this.clearSnapshots();
600
667
  this.editingAuditState.partialNext(this.initEditingAuditState(composition));
601
668
 
602
- const message: LocalMessage | DraftMessage | undefined =
603
- typeof composition === 'undefined'
604
- ? composition
605
- : compositionIsDraftResponse(composition)
606
- ? composition.message
607
- : formatMessage(composition);
669
+ let message: LocalMessage | DraftMessage | undefined;
670
+ if (compositionIsScheduledMessage(composition)) {
671
+ message = toComposerContent(composition);
672
+ } else if (compositionIsDraftResponse(composition)) {
673
+ message = composition.message;
674
+ } else if (composition) {
675
+ message = formatMessage(composition);
676
+ }
608
677
  this.attachmentManager.initState({ message });
609
678
  this.linkPreviewsManager.initState({ message });
610
679
  this.locationComposer.initState({ message });
@@ -618,6 +687,7 @@ export class MessageComposer extends WithSubscriptions {
618
687
  if (this.channel.cid !== channelApiResponse.channel?.cid) {
619
688
  return;
620
689
  }
690
+ if (this.editedScheduledMessage) return;
621
691
  if (channelApiResponse.draft) {
622
692
  this.initState({ composition: channelApiResponse.draft });
623
693
  } else if (this.state.getLatestValue().draftId) {
@@ -634,7 +704,11 @@ export class MessageComposer extends WithSubscriptions {
634
704
  };
635
705
 
636
706
  initEditingAuditState = (
637
- composition?: DraftResponse | MessageResponse | LocalMessage,
707
+ composition?:
708
+ | DraftResponse
709
+ | MessageResponse
710
+ | LocalMessage
711
+ | ScheduledMessageResponse,
638
712
  ) => initEditingAuditState(composition);
639
713
 
640
714
  clearSnapshots = () => {
@@ -642,7 +716,12 @@ export class MessageComposer extends WithSubscriptions {
642
716
  };
643
717
 
644
718
  getSnapshot = (): MessageComposerSnapshot => ({
719
+ ...this.getSnapshotKeepingUploads(),
645
720
  attachmentManager: this.attachmentManager.getSnapshot(),
721
+ });
722
+
723
+ getSnapshotKeepingUploads = (): MessageComposerSnapshot => ({
724
+ attachmentManager: this.attachmentManager.getSnapshotKeepingUploads(),
646
725
  customDataManager: this.customDataManager.getSnapshot(),
647
726
  linkPreviewsManager: this.linkPreviewsManager.getSnapshot(),
648
727
  locationComposer: this.locationComposer.getSnapshot(),
@@ -725,6 +804,9 @@ export class MessageComposer extends WithSubscriptions {
725
804
  this.addUnsubscribeFunction(this.subscribeChannelConfigChanged());
726
805
  this.addUnsubscribeFunction(this.subscribeMessageUpdated());
727
806
  this.addUnsubscribeFunction(this.subscribeMessageDeleted());
807
+ this.addUnsubscribeFunction(
808
+ this.scheduledMessageComposition.registerSubscriptions(),
809
+ );
728
810
 
729
811
  this.addUnsubscribeFunction(this.subscribeTextComposerStateChanged());
730
812
  this.addUnsubscribeFunction(this.subscribeAttachmentManagerStateChanged());
@@ -803,7 +885,7 @@ export class MessageComposer extends WithSubscriptions {
803
885
  draft.channel_cid !== this.channel.cid
804
886
  )
805
887
  return;
806
- if (this.editedMessage) return;
888
+ if (this.pausesDrafts) return;
807
889
  this.initState({ composition: draft });
808
890
  }).unsubscribe;
809
891
 
@@ -817,7 +899,7 @@ export class MessageComposer extends WithSubscriptions {
817
899
  ) {
818
900
  return;
819
901
  }
820
- if (this.editedMessage) return;
902
+ if (this.pausesDrafts) return;
821
903
 
822
904
  this.logDraftUpdateTimestamp();
823
905
 
@@ -981,7 +1063,9 @@ export class MessageComposer extends WithSubscriptions {
981
1063
  this.clear();
982
1064
  };
983
1065
 
984
- compose = async (): Promise<MessageComposerMiddlewareValue['state'] | undefined> => {
1066
+ compose = async ({ sendOptions = {} }: MessageComposerComposeOptions = {}): Promise<
1067
+ MessageComposerMiddlewareValue['state'] | undefined
1068
+ > => {
985
1069
  const created_at = this.editedMessage?.created_at ?? nowNs();
986
1070
 
987
1071
  const text = '';
@@ -1009,7 +1093,7 @@ export class MessageComposer extends WithSubscriptions {
1009
1093
  type: 'regular',
1010
1094
  updated_at: created_at,
1011
1095
  } as LocalMessage,
1012
- sendOptions: {},
1096
+ sendOptions,
1013
1097
  },
1014
1098
  });
1015
1099
 
@@ -1038,7 +1122,7 @@ export class MessageComposer extends WithSubscriptions {
1038
1122
  createDraft = async () => {
1039
1123
  // Server drafts live on the thread or channel, not on a message, so none for an edit. Nor for a
1040
1124
  // provisional channel (no ID yet).
1041
- if (this.editedMessage || !this.config.drafts.enabled || this.channel.isProvisional)
1125
+ if (this.pausesDrafts || !this.config.drafts.enabled || this.channel.isProvisional)
1042
1126
  return;
1043
1127
  const composition = await this.composeDraft();
1044
1128
  if (!composition) return;
@@ -1066,7 +1150,7 @@ export class MessageComposer extends WithSubscriptions {
1066
1150
 
1067
1151
  deleteDraft = async () => {
1068
1152
  if (
1069
- this.editedMessage ||
1153
+ this.pausesDrafts ||
1070
1154
  !this.config.drafts.enabled ||
1071
1155
  !this.draftId ||
1072
1156
  this.channel.isProvisional
@@ -1091,7 +1175,7 @@ export class MessageComposer extends WithSubscriptions {
1091
1175
  };
1092
1176
 
1093
1177
  getDraft = async () => {
1094
- if (this.editedMessage || !this.config.drafts.enabled || !this.client.userId) return;
1178
+ if (this.pausesDrafts || !this.config.drafts.enabled || !this.client.userId) return;
1095
1179
 
1096
1180
  const draftFromOfflineDB = await this.client.offlineDb?.getDraft({
1097
1181
  cid: this.channel.cid,
@@ -1153,8 +1237,12 @@ export class MessageComposer extends WithSubscriptions {
1153
1237
  }
1154
1238
  };
1155
1239
 
1156
- /** Clears the composer, or only detaches the poll when `retainsCompositionOnSubmit`. */
1157
- private releaseSubmittedComposition = () => {
1240
+ /**
1241
+ * Clears the composer, or only detaches the poll when `retainsCompositionOnSubmit`.
1242
+ *
1243
+ * @internal
1244
+ */
1245
+ releaseSubmittedComposition = () => {
1158
1246
  if (this.retainsCompositionOnSubmit) {
1159
1247
  this.state.partialNext({
1160
1248
  id: MessageComposer.generateId(),
@@ -1168,17 +1256,23 @@ export class MessageComposer extends WithSubscriptions {
1168
1256
  this.clear();
1169
1257
  };
1170
1258
 
1171
- private reportSubmitFailure = (
1172
- type: CoreNotificationType,
1173
- message: string,
1174
- error: unknown,
1175
- ) => {
1259
+ private get notificationOrigin() {
1260
+ return { emitter: 'MessageComposer' as const, context: { composer: this } };
1261
+ }
1262
+
1263
+ notifyWarning = (message: string, options?: NotificationOptions) => {
1264
+ this.client.notifications.addWarning({
1265
+ message,
1266
+ origin: this.notificationOrigin,
1267
+ options,
1268
+ });
1269
+ };
1270
+
1271
+ /** @internal */
1272
+ reportSubmitFailure = (type: CoreNotificationType, message: string, error: unknown) => {
1176
1273
  this.client.notifications.addError({
1177
1274
  message,
1178
- origin: {
1179
- emitter: 'MessageComposer',
1180
- context: { composer: this },
1181
- },
1275
+ origin: this.notificationOrigin,
1182
1276
  options: {
1183
1277
  type,
1184
1278
  metadata: { reason: (error as Error).message },
@@ -1192,13 +1286,16 @@ export class MessageComposer extends WithSubscriptions {
1192
1286
  * reported through `client.notifications`.
1193
1287
  */
1194
1288
  send = async (): Promise<MessageComposerSubmitResult> => {
1289
+ if (this.hasEditInProgress) return 'nothing-to-send';
1290
+
1195
1291
  const composition = await this.compose();
1196
1292
  if (!composition?.message) return 'nothing-to-send';
1197
1293
 
1198
1294
  const { localMessage, message, sendOptions } = composition;
1199
1295
 
1296
+ const sendClaim = this.scheduledMessageComposition.claimSend();
1200
1297
  // Released before the request, so the user's next keystrokes cannot race the clear.
1201
- this.releaseSubmittedComposition();
1298
+ if (!sendClaim) this.releaseSubmittedComposition();
1202
1299
 
1203
1300
  try {
1204
1301
  await this.defaultSubmitTarget.messageOperations.send({
@@ -1206,6 +1303,7 @@ export class MessageComposer extends WithSubscriptions {
1206
1303
  message,
1207
1304
  options: sendOptions,
1208
1305
  });
1306
+ sendClaim?.onSent();
1209
1307
  return 'sent';
1210
1308
  } catch (error) {
1211
1309
  // Nothing is restored: the failed message in the list owns the content and its upload IDs.
@@ -1244,6 +1342,16 @@ export class MessageComposer extends WithSubscriptions {
1244
1342
  }
1245
1343
  };
1246
1344
 
1345
+ scheduleMessage = (scheduledAt: Date) =>
1346
+ this.scheduledMessageComposition.schedule(scheduledAt);
1347
+
1348
+ editScheduledMessage = (scheduledMessage: ScheduledMessageResponse) =>
1349
+ this.scheduledMessageComposition.editScheduledMessage(scheduledMessage);
1350
+
1351
+ updateScheduledMessage = () => this.scheduledMessageComposition.update();
1352
+
1353
+ cancelScheduledMessageEdit = () => this.scheduledMessageComposition.cancelEdit();
1354
+
1247
1355
  sendLocation = async () => {
1248
1356
  const location = this.locationComposer.validLocation;
1249
1357
  if (this.threadId || !location) return;
@@ -36,6 +36,7 @@ import {
36
36
  } from './customData';
37
37
  import { createUserDataInjectionMiddleware } from './userDataInjection';
38
38
  import { createPollOnlyCompositionMiddleware } from './pollOnly';
39
+ import { createScheduledMessageCompositionMiddleware } from './scheduledMessage';
39
40
  import { createSharedLocationCompositionMiddleware } from './sharedLocation';
40
41
 
41
42
  export class MessageComposerMiddlewareExecutor extends MiddlewareExecutor<
@@ -48,6 +49,7 @@ export class MessageComposerMiddlewareExecutor extends MiddlewareExecutor<
48
49
  // or adding custom composer components (apart from AttachmentsManager, TextComposer etc.)
49
50
  this.use([
50
51
  createUserDataInjectionMiddleware(composer),
52
+ createScheduledMessageCompositionMiddleware(composer),
51
53
  createPollOnlyCompositionMiddleware(composer),
52
54
  createTextComposerCompositionMiddleware(composer),
53
55
  createAttachmentsCompositionMiddleware(composer),
@@ -1,8 +1,8 @@
1
1
  import { textIsEmpty } from '../../textComposer';
2
2
  import type { Command } from '../../../types';
3
- import { CommandSearchSource } from '../textComposer/commands';
4
3
  import {
5
4
  getCommandByName,
5
+ getCurrentCommand,
6
6
  getRawCommandName,
7
7
  notifyCommandDisabled,
8
8
  notifyCommandNotReady,
@@ -18,10 +18,10 @@ import type { MiddlewareHandlerParams } from '../../../middleware';
18
18
 
19
19
  const getDisabledRawCommand = (
20
20
  composer: MessageComposer,
21
- searchSource: CommandSearchSource,
21
+ commandSearchSource: MessageComposer['commandSearchSource'],
22
22
  text?: string,
23
23
  ): Command | undefined => {
24
- const rawCommand = getCommandByName(searchSource, getRawCommandName(text));
24
+ const rawCommand = getCommandByName(commandSearchSource, getRawCommandName(text));
25
25
  if (rawCommand && composer.isCommandDisabled(rawCommand)) {
26
26
  return rawCommand;
27
27
  }
@@ -29,57 +29,50 @@ const getDisabledRawCommand = (
29
29
 
30
30
  export const createCompositionValidationMiddleware = (
31
31
  composer: MessageComposer,
32
- commandSearchSource?: CommandSearchSource,
33
- ): MessageCompositionMiddleware => {
34
- const effectiveCommandSearchSource =
35
- commandSearchSource ?? new CommandSearchSource(composer.channel);
32
+ commandSearchSource: MessageComposer['commandSearchSource'] = composer.commandSearchSource,
33
+ ): MessageCompositionMiddleware => ({
34
+ id: 'stream-io/message-composer-middleware/data-validation',
35
+ handlers: {
36
+ compose: async ({
37
+ state,
38
+ discard,
39
+ forward,
40
+ }: MiddlewareHandlerParams<MessageComposerMiddlewareState>) => {
41
+ const { maxLengthOnSend } = composer.config.text ?? {};
42
+ const inputText = state.message.text ?? '';
36
43
 
37
- return {
38
- id: 'stream-io/message-composer-middleware/data-validation',
39
- handlers: {
40
- compose: async ({
41
- state,
42
- discard,
43
- forward,
44
- }: MiddlewareHandlerParams<MessageComposerMiddlewareState>) => {
45
- const { maxLengthOnSend } = composer.config.text ?? {};
46
- const inputText = state.message.text ?? '';
44
+ const disabledRawCommand = getDisabledRawCommand(
45
+ composer,
46
+ commandSearchSource,
47
+ inputText,
48
+ );
49
+ if (disabledRawCommand) {
50
+ notifyCommandDisabled(composer, disabledRawCommand);
51
+ return await discard();
52
+ }
47
53
 
48
- const disabledRawCommand = getDisabledRawCommand(
54
+ const currentCommand = getCurrentCommand(composer, inputText, commandSearchSource);
55
+ if (
56
+ currentCommand &&
57
+ notifyCommandNotReady({
49
58
  composer,
50
- effectiveCommandSearchSource,
51
- inputText,
52
- );
53
- if (disabledRawCommand) {
54
- notifyCommandDisabled(composer, disabledRawCommand);
55
- return await discard();
56
- }
57
-
58
- const currentCommand =
59
- composer.textComposer.command ??
60
- getCommandByName(effectiveCommandSearchSource, getRawCommandName(inputText));
61
- if (
62
- currentCommand &&
63
- notifyCommandNotReady({
64
- composer,
65
- sendability: composer.validateCommandSendability(currentCommand, inputText),
66
- })
67
- ) {
68
- return await discard();
69
- }
59
+ sendability: composer.validateCommandSendability(currentCommand, inputText),
60
+ })
61
+ ) {
62
+ return await discard();
63
+ }
70
64
 
71
- const hasExceededMaxLength =
72
- typeof maxLengthOnSend === 'number' && inputText.length > maxLengthOnSend;
65
+ const hasExceededMaxLength =
66
+ typeof maxLengthOnSend === 'number' && inputText.length > maxLengthOnSend;
73
67
 
74
- if (composer.compositionIsEmpty || hasExceededMaxLength) {
75
- return await discard();
76
- }
68
+ if (composer.compositionIsEmpty || hasExceededMaxLength) {
69
+ return await discard();
70
+ }
77
71
 
78
- return await forward();
79
- },
72
+ return await forward();
80
73
  },
81
- };
82
- };
74
+ },
75
+ });
83
76
 
84
77
  export const createDraftCompositionValidationMiddleware = (
85
78
  composer: MessageComposer,