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.
- package/dist/cjs/index.browser.js +65 -44
- package/dist/cjs/index.browser.js.map +2 -2
- package/dist/cjs/index.node.js +68 -44
- package/dist/cjs/index.node.js.map +2 -2
- package/dist/esm/index.mjs +65 -44
- package/dist/esm/index.mjs.map +2 -2
- package/dist/types/connection/ConnectionRecoveryManager.d.ts +13 -1
- package/dist/types/custom_types.d.ts +0 -2
- package/dist/types/gen/models/index.d.ts +93 -11
- package/dist/types/index.d.ts +1 -1
- package/dist/types/messageComposer/attachmentIdentity.d.ts +18 -0
- package/dist/types/messageComposer/attachmentManager.d.ts +16 -2
- package/dist/types/messageComposer/types.d.ts +19 -1
- package/package.json +1 -1
- package/src/connection/ConnectionRecoveryManager.ts +29 -14
- package/src/custom_types.ts +0 -1
- package/src/gen/models/index.ts +94 -11
- package/src/index.ts +0 -1
- package/src/messageComposer/attachmentIdentity.ts +26 -0
- package/src/messageComposer/attachmentManager.ts +36 -23
- package/src/messageComposer/messageComposer.ts +8 -9
- package/src/messageComposer/middleware/messageComposer/attachments.ts +12 -21
- package/src/messageComposer/types.ts +27 -1
- package/src/messageOperations/settlePendingAttachmentUploads.ts +2 -3
|
@@ -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
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2930
|
-
|
|
2939
|
+
const updatedAttachments = [...attachments];
|
|
2940
|
+
updatedAttachments.splice(attachmentIndex, 1, localAttachment);
|
|
2941
|
+
return updatedAttachments;
|
|
2931
2942
|
}
|
|
2932
2943
|
}
|
|
2933
|
-
return
|
|
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 =
|
|
2944
|
-
let hasUpdates = false;
|
|
2960
|
+
let attachments = this.attachments;
|
|
2945
2961
|
attachmentsToUpsert.forEach((attachment) => {
|
|
2946
|
-
const
|
|
2947
|
-
if (
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
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 (
|
|
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) =>
|
|
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) =>
|
|
3394
|
+
(attachment) => isSendableAttachment(attachment) ? localAttachmentToAttachment(attachment) : attachment
|
|
3381
3395
|
)
|
|
3382
3396
|
);
|
|
3383
3397
|
const messageAttachments = (state.message.attachments ?? []).concat(
|
|
3384
|
-
relevantAttachments.filter(
|
|
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(
|
|
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(
|
|
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 (
|
|
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
|
|
18551
|
-
(attachment) =>
|
|
18564
|
+
const hasAttachmentContent = this.attachmentManager.attachments.some(
|
|
18565
|
+
(attachment) => isSendableAttachment(attachment) || isResolvableUpload(attachment)
|
|
18552
18566
|
);
|
|
18553
|
-
return !!(!this.textComposer.textIsEmpty || this.textComposer.activeCommandIsContent ||
|
|
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.
|
|
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 (
|
|
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.
|
|
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 ?? {};
|