stream-chat 10.0.0-rc.31 → 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.
Files changed (33) hide show
  1. package/dist/cjs/index.browser.js +113 -190
  2. package/dist/cjs/index.browser.js.map +2 -2
  3. package/dist/cjs/index.node.js +116 -190
  4. package/dist/cjs/index.node.js.map +2 -2
  5. package/dist/esm/index.mjs +113 -190
  6. package/dist/esm/index.mjs.map +2 -2
  7. package/dist/types/channel.d.ts +2 -1
  8. package/dist/types/channel_state.d.ts +5 -0
  9. package/dist/types/client.d.ts +0 -1
  10. package/dist/types/connection/ConnectionRecoveryManager.d.ts +13 -1
  11. package/dist/types/custom_types.d.ts +0 -2
  12. package/dist/types/gen/models/index.d.ts +93 -11
  13. package/dist/types/index.d.ts +1 -1
  14. package/dist/types/messageComposer/attachmentIdentity.d.ts +18 -0
  15. package/dist/types/messageComposer/attachmentManager.d.ts +32 -5
  16. package/dist/types/messageComposer/types.d.ts +19 -1
  17. package/dist/types/types.d.ts +1 -7
  18. package/package.json +1 -1
  19. package/src/channel.ts +16 -40
  20. package/src/channel_state.ts +5 -0
  21. package/src/client.ts +9 -22
  22. package/src/connection/ConnectionRecoveryManager.ts +29 -14
  23. package/src/custom_types.ts +0 -1
  24. package/src/gen/models/index.ts +94 -11
  25. package/src/index.ts +0 -1
  26. package/src/messageComposer/attachmentIdentity.ts +26 -0
  27. package/src/messageComposer/attachmentManager.ts +82 -147
  28. package/src/messageComposer/messageComposer.ts +8 -9
  29. package/src/messageComposer/middleware/messageComposer/attachments.ts +12 -21
  30. package/src/messageComposer/types.ts +27 -1
  31. package/src/messageOperations/settlePendingAttachmentUploads.ts +2 -3
  32. package/src/pagination/paginators/ChannelPaginator.ts +1 -4
  33. package/src/types.ts +0 -6
@@ -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");
@@ -2841,6 +2847,8 @@ var initState2 = ({
2841
2847
  };
2842
2848
  })
2843
2849
  });
2850
+ var isUploadInputAttachment = (input) => "localMetadata" in input;
2851
+ var toUploadError = (rejection) => rejection instanceof Error || isUploadCancellation(rejection) ? rejection : new Error("unknown error", { cause: rejection });
2844
2852
  var _AttachmentManager = class _AttachmentManager {
2845
2853
  constructor({ composer, message }) {
2846
2854
  this.setCustomUploadFn = (doUploadRequest) => {
@@ -2911,24 +2919,29 @@ var _AttachmentManager = class _AttachmentManager {
2911
2919
  const attachmentsById = this.attachmentsById;
2912
2920
  return this.attachments.indexOf(attachmentsById[localId]);
2913
2921
  };
2914
- this.prepareAttachmentUpdate = (attachmentToUpdate) => {
2915
- const stateAttachments = this.attachments;
2916
- const attachments = [...this.attachments];
2917
- 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
+ );
2918
2930
  if (attachmentIndex === -1) return null;
2919
2931
  const merged = mergeWithDiff(
2920
- stateAttachments[attachmentIndex],
2932
+ attachments[attachmentIndex],
2921
2933
  attachmentToUpdate
2922
2934
  );
2923
2935
  const updatesOnMerge = merged.diff && Object.keys(merged.diff.children).length;
2924
2936
  if (updatesOnMerge) {
2925
2937
  const localAttachment = ensureIsLocalAttachment(merged.result);
2926
2938
  if (localAttachment) {
2927
- attachments.splice(attachmentIndex, 1, localAttachment);
2928
- return attachments;
2939
+ const updatedAttachments = [...attachments];
2940
+ updatedAttachments.splice(attachmentIndex, 1, localAttachment);
2941
+ return updatedAttachments;
2929
2942
  }
2930
2943
  }
2931
- return stateAttachments;
2944
+ return attachments;
2932
2945
  };
2933
2946
  this.updateAttachment = (attachmentToUpdate) => {
2934
2947
  const updatedAttachments = this.prepareAttachmentUpdate(attachmentToUpdate);
@@ -2936,24 +2949,24 @@ var _AttachmentManager = class _AttachmentManager {
2936
2949
  this.state.partialNext({ attachments: updatedAttachments });
2937
2950
  }
2938
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
+ */
2939
2958
  this.upsertAttachments = (attachmentsToUpsert) => {
2940
2959
  if (!attachmentsToUpsert.length) return;
2941
- let attachments = [...this.attachments];
2942
- let hasUpdates = false;
2960
+ let attachments = this.attachments;
2943
2961
  attachmentsToUpsert.forEach((attachment) => {
2944
- const updatedAttachments = this.prepareAttachmentUpdate(attachment);
2945
- if (updatedAttachments === null) {
2946
- const localAttachment = ensureIsLocalAttachment(attachment);
2947
- if (localAttachment) {
2948
- attachments.push(localAttachment);
2949
- hasUpdates = true;
2950
- }
2951
- } else if (updatedAttachments !== this.attachments) {
2952
- attachments = updatedAttachments;
2953
- hasUpdates = true;
2954
- }
2962
+ const localAttachment = ensureIsLocalAttachment(attachment);
2963
+ if (!localAttachment) return;
2964
+ attachments = this.prepareAttachmentUpdate(localAttachment, attachments) ?? [
2965
+ ...attachments,
2966
+ localAttachment
2967
+ ];
2955
2968
  });
2956
- if (hasUpdates) {
2969
+ if (attachments !== this.attachments) {
2957
2970
  this.state.partialNext({ attachments });
2958
2971
  }
2959
2972
  };
@@ -3029,7 +3042,11 @@ var _AttachmentManager = class _AttachmentManager {
3029
3042
  localAttachment.localMetadata.uploadState = uploadPermissionCheck.uploadBlocked ? "blocked" : "pending";
3030
3043
  return localAttachment;
3031
3044
  };
3032
- this.ensureLocalUploadAttachment = async (attachment) => {
3045
+ /**
3046
+ * Whether `attachment` carries what an upload needs: a file and a local id. Reports the missing one
3047
+ * as an error notification.
3048
+ */
3049
+ this.isUploadableOrNotify = (attachment) => {
3033
3050
  if (!attachment.localMetadata?.file) {
3034
3051
  this.client.notifications.addError({
3035
3052
  message: "File is required for upload attachment",
@@ -3039,7 +3056,7 @@ var _AttachmentManager = class _AttachmentManager {
3039
3056
  },
3040
3057
  options: { type: CORE_NOTIFICATION_TYPE.attachmentFileMissing }
3041
3058
  });
3042
- return;
3059
+ return false;
3043
3060
  }
3044
3061
  if (!attachment.localMetadata.id) {
3045
3062
  this.client.notifications.addError({
@@ -3050,16 +3067,9 @@ var _AttachmentManager = class _AttachmentManager {
3050
3067
  },
3051
3068
  options: { type: CORE_NOTIFICATION_TYPE.attachmentIdMissing }
3052
3069
  });
3053
- return;
3054
- }
3055
- if (!this.fileUploadFilter(attachment)) return;
3056
- const newAttachment = await this.fileToLocalUploadAttachment(
3057
- attachment.localMetadata.file
3058
- );
3059
- if (attachment.localMetadata.id) {
3060
- newAttachment.localMetadata.id = attachment.localMetadata.id;
3070
+ return false;
3061
3071
  }
3062
- return newAttachment;
3072
+ return true;
3063
3073
  };
3064
3074
  /** The default upload, skipping the custom `doUploadRequest` so a custom one can delegate here. */
3065
3075
  this.doDefaultUploadRequest = async (fileLike, options) => {
@@ -3100,99 +3110,27 @@ var _AttachmentManager = class _AttachmentManager {
3100
3110
  }
3101
3111
  return this.doDefaultUploadRequest(fileLike, options);
3102
3112
  };
3103
- // @deprecated use attachmentManager.uploadFile(file)
3104
- this.uploadAttachment = async (attachment) => {
3105
- if (!this.isUploadEnabled) return;
3106
- const localAttachment = await this.ensureLocalUploadAttachment(attachment);
3107
- if (typeof localAttachment === "undefined") return;
3108
- if (localAttachment.localMetadata.uploadState === "blocked") {
3109
- this.upsertAttachments([localAttachment]);
3110
- this.client.notifications.addError({
3111
- message: `The attachment upload was blocked`,
3112
- origin: {
3113
- emitter: "AttachmentManager",
3114
- context: {
3115
- attachment,
3116
- blockedAttachment: localAttachment,
3117
- composer: this.composer
3118
- }
3119
- },
3120
- options: {
3121
- type: CORE_NOTIFICATION_TYPE.attachmentUploadBlocked,
3122
- metadata: {
3123
- reason: localAttachment.localMetadata.uploadPermissionCheck?.reason
3124
- }
3125
- }
3126
- });
3127
- return localAttachment;
3128
- }
3129
- let response;
3130
- try {
3131
- response = await this.upload(attachment);
3132
- } catch (error) {
3133
- const reason = error instanceof Error ? error.message : "unknown error";
3134
- const failedAttachment = {
3135
- ...attachment,
3136
- localMetadata: {
3137
- ...attachment.localMetadata,
3138
- uploadState: "failed",
3139
- uploadProgress: void 0,
3140
- // `false`, not `undefined`: `mergeWith` skips `undefined`, which would leave a stale `true`.
3141
- uploadConfirmationPending: false
3142
- }
3143
- };
3144
- if (!isUploadCancellation(error)) {
3145
- this.client.notifications.addError({
3146
- message: "Error uploading attachment",
3147
- origin: {
3148
- emitter: "AttachmentManager",
3149
- context: { attachment, failedAttachment, composer: this.composer }
3150
- },
3151
- options: {
3152
- type: CORE_NOTIFICATION_TYPE.attachmentUploadFailed,
3153
- metadata: { reason },
3154
- originalError: error instanceof Error ? error : void 0
3155
- }
3156
- });
3157
- }
3158
- this.updateAttachment(failedAttachment);
3159
- return failedAttachment;
3160
- }
3161
- if (!response) {
3162
- this.removeAttachments([attachment.localMetadata.id]);
3163
- return;
3164
- }
3165
- const uploadedAttachment = {
3166
- ...attachment,
3167
- localMetadata: {
3168
- ...attachment.localMetadata,
3169
- uploadState: "finished",
3170
- uploadProgress: void 0,
3171
- uploadConfirmationPending: false
3172
- }
3173
- };
3174
- const previewUri = uploadedAttachment.localMetadata.previewUri;
3175
- if (previewUri) {
3176
- if (previewUri.startsWith("blob:")) URL.revokeObjectURL(previewUri);
3177
- delete uploadedAttachment.localMetadata.previewUri;
3178
- }
3179
- if (isLocalImageAttachment(uploadedAttachment)) {
3180
- uploadedAttachment.image_url = response.file;
3113
+ /**
3114
+ * Uploads a file, or an existing local attachment, through the pre- and post-upload middleware.
3115
+ *
3116
+ * A file becomes a new attachment. An attachment keeps its `localMetadata.id`, its fields and its
3117
+ * position in `attachments`: a failed upload is retried in place, and an attachment the caller built
3118
+ * is uploaded with its own fields. An attachment without a file or a local id is returned unchanged,
3119
+ * with an error notification.
3120
+ *
3121
+ * Unlike {@link uploadFiles}, it does not check {@link isUploadEnabled}.
3122
+ */
3123
+ this.uploadFile = async (fileOrAttachment) => {
3124
+ let initialAttachment;
3125
+ if (isUploadInputAttachment(fileOrAttachment)) {
3126
+ if (!this.isUploadableOrNotify(fileOrAttachment)) return fileOrAttachment;
3127
+ initialAttachment = fileOrAttachment;
3181
3128
  } else {
3182
- uploadedAttachment.asset_url = response.file;
3129
+ initialAttachment = _AttachmentManager.toLocalUploadAttachment(fileOrAttachment);
3183
3130
  }
3184
- if (response.thumb_url) {
3185
- uploadedAttachment.thumb_url = response.thumb_url;
3186
- }
3187
- this.updateAttachment(uploadedAttachment);
3188
- return uploadedAttachment;
3189
- };
3190
- this.uploadFile = async (file) => {
3191
3131
  const preUpload = await this.preUploadMiddlewareExecutor.execute({
3192
3132
  eventName: "prepare",
3193
- initialValue: {
3194
- attachment: _AttachmentManager.toLocalUploadAttachment(file)
3195
- },
3133
+ initialValue: { attachment: initialAttachment },
3196
3134
  mode: "concurrent"
3197
3135
  });
3198
3136
  const attachment = preUpload.state.attachment;
@@ -3222,7 +3160,7 @@ var _AttachmentManager = class _AttachmentManager {
3222
3160
  try {
3223
3161
  response = await this.upload(attachment);
3224
3162
  } catch (err) {
3225
- error = err instanceof Error ? err : void 0;
3163
+ error = toUploadError(err);
3226
3164
  }
3227
3165
  const postUpload = await this.postUploadMiddlewareExecutor.execute({
3228
3166
  eventName: "postProcess",
@@ -3350,6 +3288,10 @@ var _AttachmentManager = class _AttachmentManager {
3350
3288
  get pendingUploadsCount() {
3351
3289
  return this.getUploadsByState("pending").length;
3352
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
+ */
3353
3295
  get availableUploadSlots() {
3354
3296
  return this.config.maxNumberOfFilesPerMessage - this.successfulUploadsCount - this.uploadsInProgressCount;
3355
3297
  }
@@ -3437,24 +3379,23 @@ var localAttachmentToAttachment = (localAttachment) => {
3437
3379
  const { localMetadata: _localMetadata, ...attachment } = localAttachment;
3438
3380
  return attachment;
3439
3381
  };
3440
- var isSendable = (attachment) => isFinishedUpload(attachment) || !isLocalUploadAttachment(attachment);
3441
3382
  var composeWithPendingUploads = ({
3442
3383
  composer,
3443
3384
  state
3444
3385
  }) => {
3445
3386
  const composerIsKeptAsDraft = composer.retainsCompositionOnSubmit;
3446
3387
  const relevantAttachments = composer.attachmentManager.attachments.filter(
3447
- (attachment) => isSendable(attachment) || !composerIsKeptAsDraft && (isPendingUpload(attachment) || isFailedUpload(attachment))
3388
+ (attachment) => isSendableAttachment(attachment) || !composerIsKeptAsDraft && isResolvableUpload(attachment)
3448
3389
  );
3449
3390
  const localAttachments = (state.localMessage.attachments ?? []).concat(
3450
3391
  // A finished upload or a non-upload is final; the rest keep `localMetadata` (joined to the upload
3451
3392
  // record).
3452
3393
  relevantAttachments.map(
3453
- (attachment) => isSendable(attachment) ? localAttachmentToAttachment(attachment) : attachment
3394
+ (attachment) => isSendableAttachment(attachment) ? localAttachmentToAttachment(attachment) : attachment
3454
3395
  )
3455
3396
  );
3456
3397
  const messageAttachments = (state.message.attachments ?? []).concat(
3457
- relevantAttachments.filter(isSendable).map(localAttachmentToAttachment)
3398
+ relevantAttachments.filter(isSendableAttachment).map(localAttachmentToAttachment)
3458
3399
  );
3459
3400
  if (!localAttachments.length && !messageAttachments.length) return state;
3460
3401
  return {
@@ -3497,7 +3438,7 @@ var createAttachmentsCompositionMiddleware = (composer) => ({
3497
3438
  return discard();
3498
3439
  }
3499
3440
  const attachments = (state.message.attachments ?? []).concat(
3500
- attachmentManager.attachments.filter(isSendable).map(localAttachmentToAttachment)
3441
+ attachmentManager.attachments.filter(isSendableAttachment).map(localAttachmentToAttachment)
3501
3442
  );
3502
3443
  if (!attachments.length) return forward();
3503
3444
  return next({
@@ -3524,7 +3465,7 @@ var createDraftAttachmentsCompositionMiddleware = (composer) => ({
3524
3465
  }) => {
3525
3466
  const { attachmentManager } = composer;
3526
3467
  if (!attachmentManager) return forward();
3527
- const sendableAttachments = attachmentManager.attachments.filter(isSendable);
3468
+ const sendableAttachments = attachmentManager.attachments.filter(isSendableAttachment);
3528
3469
  const attachments = sendableAttachments.length ? (state.draft.attachments ?? []).concat(
3529
3470
  sendableAttachments.map(localAttachmentToAttachment)
3530
3471
  ) : void 0;
@@ -7602,11 +7543,7 @@ var ChannelPaginator = class extends BasePaginator {
7602
7543
  }
7603
7544
  return this.client.hydrateChannels(
7604
7545
  cachedQuery.channels,
7605
- {
7606
- offlineMode: true,
7607
- skipInitialization: []
7608
- // an empty array clears existing channel messages (no duplicates)
7609
- },
7546
+ { offlineMode: true },
7610
7547
  request
7611
7548
  );
7612
7549
  }
@@ -15184,7 +15121,7 @@ var settlePendingAttachmentUploads = async ({
15184
15121
  client
15185
15122
  }) => {
15186
15123
  const unsettledIndexes = attachments.reduce((indexes, attachment, index) => {
15187
- if (isPendingUpload(attachment) || isFailedUpload(attachment)) indexes.push(index);
15124
+ if (isResolvableUpload(attachment)) indexes.push(index);
15188
15125
  return indexes;
15189
15126
  }, []);
15190
15127
  if (!unsettledIndexes.length) return { attachments };
@@ -16115,18 +16052,7 @@ var Channel = class extends ChannelApi {
16115
16052
  */
16116
16053
  async updatePartial(update, requestOptions) {
16117
16054
  const data = await this.updateChannelPartial(update, requestOptions);
16118
- const channel = data.channel;
16119
- const currentCapabilities = this.data?.own_capabilities ?? [];
16120
- const newCapabilities = channel?.own_capabilities;
16121
- const capabilitiesChanged = newCapabilities && [...currentCapabilities].sort().join() !== [...newCapabilities].sort().join();
16122
- this.data = channel;
16123
- if (capabilitiesChanged) {
16124
- this.getClient().dispatchEvent({
16125
- type: "capabilities.changed",
16126
- cid: this.cid,
16127
- own_capabilities: newCapabilities
16128
- });
16129
- }
16055
+ this.data = data.channel;
16130
16056
  return data;
16131
16057
  }
16132
16058
  /**
@@ -16623,13 +16549,18 @@ var Channel = class extends ChannelApi {
16623
16549
  * Reads `state.data`. Assigning publishes `data`, `memberCount` and `ownCapabilities` in one update.
16624
16550
  * If the object omits `member_count` or `own_capabilities`, the last known values are carried onto
16625
16551
  * a copy (the assigned object is not changed). Editing `channel.data.x` in place does not reach
16626
- * the state.
16552
+ * the state. `ownCapabilities` keeps its array while the capabilities stay the same (in any
16553
+ * order), so a subscriber to it is notified only when they change.
16627
16554
  */
16628
16555
  get data() {
16629
16556
  return this.state.getLatestValue().data;
16630
16557
  }
16631
16558
  set data(next) {
16632
- const previous = this.state.getLatestValue().data;
16559
+ const {
16560
+ data: previous,
16561
+ memberCount: previousMemberCount,
16562
+ ownCapabilities: previousOwnCapabilities
16563
+ } = this.state.getLatestValue();
16633
16564
  const carriedMemberCount = typeof next?.member_count !== "number" && typeof previous?.member_count === "number" ? previous.member_count : void 0;
16634
16565
  const carriedCapabilities = !Array.isArray(next?.own_capabilities) && Array.isArray(previous?.own_capabilities) ? [...previous.own_capabilities] : void 0;
16635
16566
  const data = next && (carriedMemberCount !== void 0 || carriedCapabilities) ? {
@@ -16638,11 +16569,13 @@ var Channel = class extends ChannelApi {
16638
16569
  ...carriedCapabilities && { own_capabilities: carriedCapabilities }
16639
16570
  } : next;
16640
16571
  const memberCount = data?.member_count ?? carriedMemberCount;
16641
- const ownCapabilities = data?.own_capabilities ?? carriedCapabilities;
16572
+ const ownCapabilities = data?.own_capabilities ?? carriedCapabilities ?? [];
16573
+ const toKey = (capabilities) => [...capabilities].sort().join();
16574
+ const haveSameOwnCapabilities = toKey(previousOwnCapabilities) === toKey(ownCapabilities);
16642
16575
  this.state.partialNext({
16643
16576
  data,
16644
- memberCount: memberCount ?? this.state.getLatestValue().memberCount,
16645
- ownCapabilities: ownCapabilities ? [...ownCapabilities] : []
16577
+ memberCount: memberCount ?? previousMemberCount,
16578
+ ownCapabilities: haveSameOwnCapabilities ? previousOwnCapabilities : [...ownCapabilities]
16646
16579
  });
16647
16580
  }
16648
16581
  /**
@@ -17126,18 +17059,8 @@ var Channel = class extends ChannelApi {
17126
17059
  this.getClient().polls.hydratePollCache(state.messages, true);
17127
17060
  this.getClient().reminders.hydrateState(state.messages);
17128
17061
  this.messageComposer.initStateFromChannelResponse(state);
17129
- const areCapabilitiesChanged = [...channel.own_capabilities || []].sort().join() !== [
17130
- ...this.data && Array.isArray(this.data?.own_capabilities) ? this.data.own_capabilities : []
17131
- ].sort().join();
17132
17062
  this.data = channel;
17133
17063
  this.state.partialNext({ initialized: true, offlineMode: false });
17134
- if (areCapabilitiesChanged) {
17135
- this.getClient().dispatchEvent({
17136
- type: "capabilities.changed",
17137
- cid: this.cid,
17138
- own_capabilities: channel.own_capabilities ?? []
17139
- });
17140
- }
17141
17064
  this.getClient().dispatchEvent({
17142
17065
  type: "channels.queried",
17143
17066
  queriedChannels: {
@@ -18638,12 +18561,12 @@ var _MessageComposer = class _MessageComposer extends WithSubscriptions {
18638
18561
  get hasSendableData() {
18639
18562
  if (!this.isCommandSendable) return false;
18640
18563
  if (this.allowsPendingUploads) {
18641
- const hasSendableAttachment = this.attachmentManager.attachments.some(
18642
- (attachment) => isFinishedUpload(attachment) || isPendingUpload(attachment) || isFailedUpload(attachment)
18564
+ const hasAttachmentContent = this.attachmentManager.attachments.some(
18565
+ (attachment) => isSendableAttachment(attachment) || isResolvableUpload(attachment)
18643
18566
  );
18644
- 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);
18645
18568
  }
18646
- 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);
18647
18570
  }
18648
18571
  get compositionIsEmpty() {
18649
18572
  return !this.quotedMessage && this.contentIsEmpty;
@@ -21770,14 +21693,8 @@ var ConnectionRecoveryManager = class extends WithSubscriptions {
21770
21693
  wasHealthy = isHealthy;
21771
21694
  if (previous === void 0 || !isHealthy) return;
21772
21695
  if (!lastUnhealthyAt) return;
21773
- if (!this.config.enabled) return;
21774
21696
  const syncEdgeDrivesRecovery = this.ensureSyncStatusSubscription();
21775
- if (!syncEdgeDrivesRecovery) {
21776
- runDetached(this.recoverChannelLists(), { context: "recoverChannelLists" });
21777
- runDetached(this.recoverActiveChannels(), {
21778
- context: "recoverActiveChannels"
21779
- });
21780
- }
21697
+ if (!syncEdgeDrivesRecovery) this.handleReconnect();
21781
21698
  }
21782
21699
  )
21783
21700
  );
@@ -21799,9 +21716,7 @@ var ConnectionRecoveryManager = class extends WithSubscriptions {
21799
21716
  const { offlineDb } = this.client;
21800
21717
  if (!offlineDb?.state.getLatestValue().initialized) return false;
21801
21718
  const { unsubscribe } = offlineDb.syncManager.onSyncStatusChange((status) => {
21802
- if (!status || !this.config.enabled) return;
21803
- runDetached(this.recoverChannelLists(), { context: "recoverChannelLists" });
21804
- runDetached(this.recoverActiveChannels(), { context: "recoverActiveChannels" });
21719
+ if (status) this.handleReconnect();
21805
21720
  });
21806
21721
  this.unsubscribeSyncStatus = unsubscribe;
21807
21722
  return true;
@@ -21874,6 +21789,21 @@ var ConnectionRecoveryManager = class extends WithSubscriptions {
21874
21789
  initializeConfig(config) {
21875
21790
  this.configController.initialize(config);
21876
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
+ }
21877
21807
  /**
21878
21808
  * Channels a consumer is reading. Not filtered on `watchStatus`: a channel opened while offline never
21879
21809
  * reached `Watching`, and `Channel.reload()` has its own `initialized || offlineMode` guard.
@@ -25256,7 +25186,7 @@ var StreamChat = class _StreamChat extends ChatApi {
25256
25186
  return this.userAgent;
25257
25187
  }
25258
25188
  if (!this.cachedUserAgent) {
25259
- const version = "10.0.0-rc.31";
25189
+ const version = "10.0.0-rc.33";
25260
25190
  const { name: sdkName, version: sdkVersion } = this.sdkIdentifier ?? {};
25261
25191
  const { name: appName, version: appVersion } = this.appIdentifier ?? {};
25262
25192
  const { os, model: deviceModel } = this.deviceIdentifier ?? {};
@@ -25833,7 +25763,7 @@ var StreamChat = class _StreamChat extends ChatApi {
25833
25763
  return await this.queryReactions(...args);
25834
25764
  }
25835
25765
  hydrateChannels(channelsFromApi = [], stateOptions = {}, queryChannelsOptions, headIntervalItemIdsAtRequestByCid) {
25836
- const { skipInitialization, offlineMode = false } = stateOptions;
25766
+ const { offlineMode = false } = stateOptions;
25837
25767
  const channels = [];
25838
25768
  for (const channelState of channelsFromApi) {
25839
25769
  if (!channelState.channel) continue;
@@ -25851,9 +25781,8 @@ var StreamChat = class _StreamChat extends ChatApi {
25851
25781
  c.watchStatus = ChannelWatchStatus.Watching;
25852
25782
  }
25853
25783
  c.push_preferences = channelState.push_preferences;
25854
- const willInitialize = skipInitialization === void 0 || !skipInitialization.includes(channelState.channel.id);
25855
25784
  const requestedPageSize = queryChannelsOptions?.message_limit ?? DEFAULT_QUERY_CHANNELS_MESSAGE_LIST_PAGE_SIZE;
25856
- const placesNewestPage = willInitialize && !c.active;
25785
+ const placesNewestPage = !c.active;
25857
25786
  let placedFirstPage = false;
25858
25787
  if (placesNewestPage) {
25859
25788
  c.messagePaginator.setQueriedLatestMessageAt(
@@ -25867,19 +25796,13 @@ var StreamChat = class _StreamChat extends ChatApi {
25867
25796
  }
25868
25797
  );
25869
25798
  }
25870
- if (skipInitialization === void 0) {
25871
- c._initializeState(channelState);
25872
- } else if (!skipInitialization.includes(channelState.channel.id)) {
25873
- c._initializeState(channelState);
25874
- }
25799
+ c._initializeState(channelState);
25875
25800
  if (placedFirstPage) c.messagePaginator.seedUnreadSnapshot();
25876
- if (willInitialize && !c.active && !wasWatching && !(placesNewestPage && channelState.messages.length)) {
25801
+ if (placesNewestPage && !wasWatching && !channelState.messages.length) {
25877
25802
  c.messagePaginator.unmarkStaleHead();
25878
25803
  }
25879
- if (willInitialize) {
25880
- this.polls.hydratePollCache(channelState.messages, true);
25881
- this.reminders.hydrateState(channelState.messages);
25882
- }
25804
+ this.polls.hydratePollCache(channelState.messages, true);
25805
+ this.reminders.hydrateState(channelState.messages);
25883
25806
  c.messageComposer.initStateFromChannelResponse(channelState);
25884
25807
  c.cooldownTimer.refresh();
25885
25808
  channels.push(c);