stream-chat 10.0.0-rc.32 → 10.0.0-rc.33

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.
@@ -229,10 +229,13 @@ __export(src_exports, {
229
229
  isLocalVideoAttachment: () => isLocalVideoAttachment,
230
230
  isLocalVoiceRecordingAttachment: () => isLocalVoiceRecordingAttachment,
231
231
  isLogicalInterval: () => isLogicalInterval,
232
+ isNonUploadAttachment: () => isNonUploadAttachment,
232
233
  isOwnUser: () => isOwnUser,
233
234
  isPendingUpload: () => isPendingUpload,
234
235
  isPollComposerValidationError: () => isPollComposerValidationError,
236
+ isResolvableUpload: () => isResolvableUpload,
235
237
  isScrapedContent: () => isScrapedContent,
238
+ isSendableAttachment: () => isSendableAttachment,
236
239
  isSharedLocationResponseData: () => isSharedLocationResponseData,
237
240
  isTargetedOptionTextUpdate: () => isTargetedOptionTextUpdate,
238
241
  isUploadCancellation: () => isUploadCancellation,
@@ -1754,6 +1757,9 @@ var PENDING_UPLOAD_STATES = [
1754
1757
  var isPendingUpload = (attachment) => isLocalUploadAttachment(attachment) && PENDING_UPLOAD_STATES.includes(attachment.localMetadata.uploadState);
1755
1758
  var isFinishedUpload = (attachment) => isLocalUploadAttachment(attachment) && attachment.localMetadata.uploadState === "finished";
1756
1759
  var isFailedUpload = (attachment) => isLocalUploadAttachment(attachment) && attachment.localMetadata.uploadState === "failed";
1760
+ var isResolvableUpload = (attachment) => isPendingUpload(attachment) || isFailedUpload(attachment);
1761
+ var isNonUploadAttachment = (attachment) => isLocalAttachment(attachment) && !isLocalUploadAttachment(attachment) && !attachment.localMetadata.file;
1762
+ var isSendableAttachment = (attachment) => isFinishedUpload(attachment) || isNonUploadAttachment(attachment);
1757
1763
  var isFileAttachment = (attachment, supportedVideoFormat = []) => attachment.type === "file" || !!(attachment.custom?.mime_type && supportedVideoFormat.indexOf(
1758
1764
  attachment.custom?.mime_type
1759
1765
  ) === -1 && attachment.type !== "video");
@@ -2913,24 +2919,29 @@ var _AttachmentManager = class _AttachmentManager {
2913
2919
  const attachmentsById = this.attachmentsById;
2914
2920
  return this.attachments.indexOf(attachmentsById[localId]);
2915
2921
  };
2916
- this.prepareAttachmentUpdate = (attachmentToUpdate) => {
2917
- const stateAttachments = this.attachments;
2918
- const attachments = [...this.attachments];
2919
- const attachmentIndex = this.getAttachmentIndex(attachmentToUpdate.localMetadata.id);
2922
+ /**
2923
+ * `attachments` with `attachmentToUpdate` merged in place of the one with its `localMetadata.id`:
2924
+ * `null` when none has it, `attachments` itself when the merge changes nothing.
2925
+ */
2926
+ this.prepareAttachmentUpdate = (attachmentToUpdate, attachments = this.attachments) => {
2927
+ const attachmentIndex = attachments.findIndex(
2928
+ ({ localMetadata }) => localMetadata?.id === attachmentToUpdate.localMetadata.id
2929
+ );
2920
2930
  if (attachmentIndex === -1) return null;
2921
2931
  const merged = mergeWithDiff(
2922
- stateAttachments[attachmentIndex],
2932
+ attachments[attachmentIndex],
2923
2933
  attachmentToUpdate
2924
2934
  );
2925
2935
  const updatesOnMerge = merged.diff && Object.keys(merged.diff.children).length;
2926
2936
  if (updatesOnMerge) {
2927
2937
  const localAttachment = ensureIsLocalAttachment(merged.result);
2928
2938
  if (localAttachment) {
2929
- attachments.splice(attachmentIndex, 1, localAttachment);
2930
- return attachments;
2939
+ const updatedAttachments = [...attachments];
2940
+ updatedAttachments.splice(attachmentIndex, 1, localAttachment);
2941
+ return updatedAttachments;
2931
2942
  }
2932
2943
  }
2933
- return stateAttachments;
2944
+ return attachments;
2934
2945
  };
2935
2946
  this.updateAttachment = (attachmentToUpdate) => {
2936
2947
  const updatedAttachments = this.prepareAttachmentUpdate(attachmentToUpdate);
@@ -2938,24 +2949,24 @@ var _AttachmentManager = class _AttachmentManager {
2938
2949
  this.state.partialNext({ attachments: updatedAttachments });
2939
2950
  }
2940
2951
  };
2952
+ /**
2953
+ * Merges each attachment into the one with its `localMetadata.id`, or appends it. An attachment
2954
+ * without a local id (e.g. a custom-type one the app builds) is appended with a new one, on every
2955
+ * call: to update or remove it later, pass `{ ...attachment, localMetadata: { id } }` with your own
2956
+ * id instead.
2957
+ */
2941
2958
  this.upsertAttachments = (attachmentsToUpsert) => {
2942
2959
  if (!attachmentsToUpsert.length) return;
2943
- let attachments = [...this.attachments];
2944
- let hasUpdates = false;
2960
+ let attachments = this.attachments;
2945
2961
  attachmentsToUpsert.forEach((attachment) => {
2946
- const updatedAttachments = this.prepareAttachmentUpdate(attachment);
2947
- if (updatedAttachments === null) {
2948
- const localAttachment = ensureIsLocalAttachment(attachment);
2949
- if (localAttachment) {
2950
- attachments.push(localAttachment);
2951
- hasUpdates = true;
2952
- }
2953
- } else if (updatedAttachments !== this.attachments) {
2954
- attachments = updatedAttachments;
2955
- hasUpdates = true;
2956
- }
2962
+ const localAttachment = ensureIsLocalAttachment(attachment);
2963
+ if (!localAttachment) return;
2964
+ attachments = this.prepareAttachmentUpdate(localAttachment, attachments) ?? [
2965
+ ...attachments,
2966
+ localAttachment
2967
+ ];
2957
2968
  });
2958
- if (hasUpdates) {
2969
+ if (attachments !== this.attachments) {
2959
2970
  this.state.partialNext({ attachments });
2960
2971
  }
2961
2972
  };
@@ -3277,6 +3288,10 @@ var _AttachmentManager = class _AttachmentManager {
3277
3288
  get pendingUploadsCount() {
3278
3289
  return this.getUploadsByState("pending").length;
3279
3290
  }
3291
+ /**
3292
+ * Slots left for files. Each finished or uploading attachment takes one. Pending, failed and blocked
3293
+ * uploads, and attachments with nothing to upload, take none.
3294
+ */
3280
3295
  get availableUploadSlots() {
3281
3296
  return this.config.maxNumberOfFilesPerMessage - this.successfulUploadsCount - this.uploadsInProgressCount;
3282
3297
  }
@@ -3364,24 +3379,23 @@ var localAttachmentToAttachment = (localAttachment) => {
3364
3379
  const { localMetadata: _localMetadata, ...attachment } = localAttachment;
3365
3380
  return attachment;
3366
3381
  };
3367
- var isSendable = (attachment) => isFinishedUpload(attachment) || !isLocalUploadAttachment(attachment);
3368
3382
  var composeWithPendingUploads = ({
3369
3383
  composer,
3370
3384
  state
3371
3385
  }) => {
3372
3386
  const composerIsKeptAsDraft = composer.retainsCompositionOnSubmit;
3373
3387
  const relevantAttachments = composer.attachmentManager.attachments.filter(
3374
- (attachment) => isSendable(attachment) || !composerIsKeptAsDraft && (isPendingUpload(attachment) || isFailedUpload(attachment))
3388
+ (attachment) => isSendableAttachment(attachment) || !composerIsKeptAsDraft && isResolvableUpload(attachment)
3375
3389
  );
3376
3390
  const localAttachments = (state.localMessage.attachments ?? []).concat(
3377
3391
  // A finished upload or a non-upload is final; the rest keep `localMetadata` (joined to the upload
3378
3392
  // record).
3379
3393
  relevantAttachments.map(
3380
- (attachment) => isSendable(attachment) ? localAttachmentToAttachment(attachment) : attachment
3394
+ (attachment) => isSendableAttachment(attachment) ? localAttachmentToAttachment(attachment) : attachment
3381
3395
  )
3382
3396
  );
3383
3397
  const messageAttachments = (state.message.attachments ?? []).concat(
3384
- relevantAttachments.filter(isSendable).map(localAttachmentToAttachment)
3398
+ relevantAttachments.filter(isSendableAttachment).map(localAttachmentToAttachment)
3385
3399
  );
3386
3400
  if (!localAttachments.length && !messageAttachments.length) return state;
3387
3401
  return {
@@ -3424,7 +3438,7 @@ var createAttachmentsCompositionMiddleware = (composer) => ({
3424
3438
  return discard();
3425
3439
  }
3426
3440
  const attachments = (state.message.attachments ?? []).concat(
3427
- attachmentManager.attachments.filter(isSendable).map(localAttachmentToAttachment)
3441
+ attachmentManager.attachments.filter(isSendableAttachment).map(localAttachmentToAttachment)
3428
3442
  );
3429
3443
  if (!attachments.length) return forward();
3430
3444
  return next({
@@ -3451,7 +3465,7 @@ var createDraftAttachmentsCompositionMiddleware = (composer) => ({
3451
3465
  }) => {
3452
3466
  const { attachmentManager } = composer;
3453
3467
  if (!attachmentManager) return forward();
3454
- const sendableAttachments = attachmentManager.attachments.filter(isSendable);
3468
+ const sendableAttachments = attachmentManager.attachments.filter(isSendableAttachment);
3455
3469
  const attachments = sendableAttachments.length ? (state.draft.attachments ?? []).concat(
3456
3470
  sendableAttachments.map(localAttachmentToAttachment)
3457
3471
  ) : void 0;
@@ -15107,7 +15121,7 @@ var settlePendingAttachmentUploads = async ({
15107
15121
  client
15108
15122
  }) => {
15109
15123
  const unsettledIndexes = attachments.reduce((indexes, attachment, index) => {
15110
- if (isPendingUpload(attachment) || isFailedUpload(attachment)) indexes.push(index);
15124
+ if (isResolvableUpload(attachment)) indexes.push(index);
15111
15125
  return indexes;
15112
15126
  }, []);
15113
15127
  if (!unsettledIndexes.length) return { attachments };
@@ -18547,12 +18561,12 @@ var _MessageComposer = class _MessageComposer extends WithSubscriptions {
18547
18561
  get hasSendableData() {
18548
18562
  if (!this.isCommandSendable) return false;
18549
18563
  if (this.allowsPendingUploads) {
18550
- const hasSendableAttachment = this.attachmentManager.attachments.some(
18551
- (attachment) => isFinishedUpload(attachment) || isPendingUpload(attachment) || isFailedUpload(attachment)
18564
+ const hasAttachmentContent = this.attachmentManager.attachments.some(
18565
+ (attachment) => isSendableAttachment(attachment) || isResolvableUpload(attachment)
18552
18566
  );
18553
- return !!(!this.textComposer.textIsEmpty || this.textComposer.activeCommandIsContent || hasSendableAttachment || this.pollId || this.locationComposer.validLocation);
18567
+ return !!(!this.textComposer.textIsEmpty || this.textComposer.activeCommandIsContent || hasAttachmentContent || this.pollId || this.locationComposer.validLocation);
18554
18568
  }
18555
- return !!(!this.attachmentManager.uploadsInProgressCount && (!this.textComposer.textIsEmpty || this.textComposer.activeCommandIsContent || this.attachmentManager.successfulUploadsCount > 0) || this.pollId || !!this.locationComposer.validLocation);
18569
+ return !!(!this.attachmentManager.uploadsInProgressCount && (!this.textComposer.textIsEmpty || this.textComposer.activeCommandIsContent || this.attachmentManager.attachments.some(isSendableAttachment)) || this.pollId || !!this.locationComposer.validLocation);
18556
18570
  }
18557
18571
  get compositionIsEmpty() {
18558
18572
  return !this.quotedMessage && this.contentIsEmpty;
@@ -21679,14 +21693,8 @@ var ConnectionRecoveryManager = class extends WithSubscriptions {
21679
21693
  wasHealthy = isHealthy;
21680
21694
  if (previous === void 0 || !isHealthy) return;
21681
21695
  if (!lastUnhealthyAt) return;
21682
- if (!this.config.enabled) return;
21683
21696
  const syncEdgeDrivesRecovery = this.ensureSyncStatusSubscription();
21684
- if (!syncEdgeDrivesRecovery) {
21685
- runDetached(this.recoverChannelLists(), { context: "recoverChannelLists" });
21686
- runDetached(this.recoverActiveChannels(), {
21687
- context: "recoverActiveChannels"
21688
- });
21689
- }
21697
+ if (!syncEdgeDrivesRecovery) this.handleReconnect();
21690
21698
  }
21691
21699
  )
21692
21700
  );
@@ -21708,9 +21716,7 @@ var ConnectionRecoveryManager = class extends WithSubscriptions {
21708
21716
  const { offlineDb } = this.client;
21709
21717
  if (!offlineDb?.state.getLatestValue().initialized) return false;
21710
21718
  const { unsubscribe } = offlineDb.syncManager.onSyncStatusChange((status) => {
21711
- if (!status || !this.config.enabled) return;
21712
- runDetached(this.recoverChannelLists(), { context: "recoverChannelLists" });
21713
- runDetached(this.recoverActiveChannels(), { context: "recoverActiveChannels" });
21719
+ if (status) this.handleReconnect();
21714
21720
  });
21715
21721
  this.unsubscribeSyncStatus = unsubscribe;
21716
21722
  return true;
@@ -21783,6 +21789,21 @@ var ConnectionRecoveryManager = class extends WithSubscriptions {
21783
21789
  initializeConfig(config) {
21784
21790
  this.configController.initialize(config);
21785
21791
  }
21792
+ /**
21793
+ * Recovers the lists, and the active channels and threads (that pass dispatches `connection.recovered`
21794
+ * when done). With recovery disabled it skips the refresh and only dispatches the event, so an app that
21795
+ * refreshes its own data knows when to do it.
21796
+ */
21797
+ handleReconnect() {
21798
+ if (this.config.enabled) {
21799
+ runDetached(this.recoverChannelLists(), { context: "recoverChannelLists" });
21800
+ runDetached(this.recoverActiveChannels(), { context: "recoverActiveChannels" });
21801
+ return;
21802
+ }
21803
+ if (this.client.wsConnection.isHealthy) {
21804
+ this.client.dispatchEvent({ type: "connection.recovered" });
21805
+ }
21806
+ }
21786
21807
  /**
21787
21808
  * Channels a consumer is reading. Not filtered on `watchStatus`: a channel opened while offline never
21788
21809
  * reached `Watching`, and `Channel.reload()` has its own `initialized || offlineMode` guard.
@@ -25165,7 +25186,7 @@ var StreamChat = class _StreamChat extends ChatApi {
25165
25186
  return this.userAgent;
25166
25187
  }
25167
25188
  if (!this.cachedUserAgent) {
25168
- const version = "10.0.0-rc.32";
25189
+ const version = "10.0.0-rc.33";
25169
25190
  const { name: sdkName, version: sdkVersion } = this.sdkIdentifier ?? {};
25170
25191
  const { name: appName, version: appVersion } = this.appIdentifier ?? {};
25171
25192
  const { os, model: deviceModel } = this.deviceIdentifier ?? {};