stream-chat 9.5.1 → 9.6.1
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.cjs +133 -57
- package/dist/cjs/index.browser.cjs.map +4 -4
- package/dist/cjs/index.node.cjs +137 -60
- package/dist/cjs/index.node.cjs.map +4 -4
- package/dist/esm/index.js +133 -57
- package/dist/esm/index.js.map +4 -4
- package/dist/types/index.d.ts +1 -0
- package/dist/types/messageComposer/messageComposer.d.ts +8 -5
- package/dist/types/messageComposer/middleware/messageComposer/userDataInjection.d.ts +3 -0
- package/dist/types/notifications/configuration.d.ts +2 -0
- package/dist/types/notifications/types.d.ts +57 -18
- package/dist/types/poll_manager.d.ts +1 -1
- package/dist/types/utils/WithSubscriptions.d.ts +7 -2
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/messageComposer/attachmentManager.ts +26 -19
- package/src/messageComposer/messageComposer.ts +42 -27
- package/src/messageComposer/middleware/messageComposer/MessageComposerMiddlewareExecutor.ts +2 -0
- package/src/messageComposer/middleware/messageComposer/cleanData.ts +0 -1
- package/src/messageComposer/middleware/messageComposer/messageComposerState.ts +16 -2
- package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +43 -0
- package/src/notifications/NotificationManager.ts +10 -15
- package/src/notifications/configuration.ts +12 -0
- package/src/notifications/types.ts +60 -18
- package/src/poll_manager.ts +7 -1
- package/src/utils/WithSubscriptions.ts +16 -2
|
@@ -204,6 +204,7 @@ __export(index_exports, {
|
|
|
204
204
|
MiddlewareExecutor: () => MiddlewareExecutor,
|
|
205
205
|
MinPriority: () => MinPriority,
|
|
206
206
|
Moderation: () => Moderation,
|
|
207
|
+
NotificationManager: () => NotificationManager,
|
|
207
208
|
OfflineDBSyncManager: () => OfflineDBSyncManager,
|
|
208
209
|
OfflineError: () => OfflineError,
|
|
209
210
|
Permission: () => Permission,
|
|
@@ -4789,7 +4790,8 @@ var AttachmentManager = class {
|
|
|
4789
4790
|
if (!attachment.localMetadata?.file || !attachment.localMetadata.id) {
|
|
4790
4791
|
this.client.notifications.addError({
|
|
4791
4792
|
message: "File is required for upload attachment",
|
|
4792
|
-
origin: { emitter: "AttachmentManager", context: { attachment } }
|
|
4793
|
+
origin: { emitter: "AttachmentManager", context: { attachment } },
|
|
4794
|
+
options: { type: "validation:attachment:file:missing" }
|
|
4793
4795
|
});
|
|
4794
4796
|
return;
|
|
4795
4797
|
}
|
|
@@ -4839,8 +4841,17 @@ var AttachmentManager = class {
|
|
|
4839
4841
|
if (localAttachment.localMetadata.uploadState === "blocked") {
|
|
4840
4842
|
this.upsertAttachments([localAttachment]);
|
|
4841
4843
|
this.client.notifications.addError({
|
|
4842
|
-
message:
|
|
4843
|
-
origin: {
|
|
4844
|
+
message: `The attachment upload was blocked`,
|
|
4845
|
+
origin: {
|
|
4846
|
+
emitter: "AttachmentManager",
|
|
4847
|
+
context: { attachment, blockedAttachment: localAttachment }
|
|
4848
|
+
},
|
|
4849
|
+
options: {
|
|
4850
|
+
type: "validation:attachment:upload:blocked",
|
|
4851
|
+
metadata: {
|
|
4852
|
+
reason: localAttachment.localMetadata.uploadPermissionCheck?.reason
|
|
4853
|
+
}
|
|
4854
|
+
}
|
|
4844
4855
|
});
|
|
4845
4856
|
return localAttachment;
|
|
4846
4857
|
}
|
|
@@ -4857,19 +4868,7 @@ var AttachmentManager = class {
|
|
|
4857
4868
|
try {
|
|
4858
4869
|
response = await this.doUploadRequest(localAttachment.localMetadata.file);
|
|
4859
4870
|
} catch (error) {
|
|
4860
|
-
|
|
4861
|
-
message: "Error uploading attachment",
|
|
4862
|
-
name: "Error"
|
|
4863
|
-
};
|
|
4864
|
-
if (typeof error.message === "string") {
|
|
4865
|
-
finalError = error;
|
|
4866
|
-
} else if (typeof error === "object") {
|
|
4867
|
-
finalError = Object.assign(finalError, error);
|
|
4868
|
-
}
|
|
4869
|
-
this.client.notifications.addError({
|
|
4870
|
-
message: finalError.message,
|
|
4871
|
-
origin: { emitter: "AttachmentManager", context: { attachment } }
|
|
4872
|
-
});
|
|
4871
|
+
const reason = error instanceof Error ? error.message : "unknown error";
|
|
4873
4872
|
const failedAttachment = {
|
|
4874
4873
|
...attachment,
|
|
4875
4874
|
localMetadata: {
|
|
@@ -4877,6 +4876,18 @@ var AttachmentManager = class {
|
|
|
4877
4876
|
uploadState: "failed"
|
|
4878
4877
|
}
|
|
4879
4878
|
};
|
|
4879
|
+
this.client.notifications.addError({
|
|
4880
|
+
message: "Error uploading attachment",
|
|
4881
|
+
origin: {
|
|
4882
|
+
emitter: "AttachmentManager",
|
|
4883
|
+
context: { attachment, failedAttachment }
|
|
4884
|
+
},
|
|
4885
|
+
options: {
|
|
4886
|
+
type: "api:attachment:upload:failed",
|
|
4887
|
+
metadata: { reason },
|
|
4888
|
+
originalError: error instanceof Error ? error : void 0
|
|
4889
|
+
}
|
|
4890
|
+
});
|
|
4880
4891
|
this.updateAttachment(failedAttachment);
|
|
4881
4892
|
return failedAttachment;
|
|
4882
4893
|
}
|
|
@@ -5896,8 +5907,7 @@ var createCompositionDataCleanupMiddleware = (composer) => ({
|
|
|
5896
5907
|
localMessage: formatMessage({
|
|
5897
5908
|
...composer.editedMessage,
|
|
5898
5909
|
...state.localMessage,
|
|
5899
|
-
...common
|
|
5900
|
-
user: composer.client.user
|
|
5910
|
+
...common
|
|
5901
5911
|
}),
|
|
5902
5912
|
message: {
|
|
5903
5913
|
...editedMessagePayloadToBeSent,
|
|
@@ -6143,6 +6153,9 @@ var createMessageComposerStateCompositionMiddleware = (composer) => ({
|
|
|
6143
6153
|
if (composer.pollId) {
|
|
6144
6154
|
payload.poll_id = composer.pollId;
|
|
6145
6155
|
}
|
|
6156
|
+
if (composer.showReplyInChannel) {
|
|
6157
|
+
payload.show_in_channel = true;
|
|
6158
|
+
}
|
|
6146
6159
|
return next({
|
|
6147
6160
|
...state,
|
|
6148
6161
|
localMessage: {
|
|
@@ -6172,6 +6185,9 @@ var createDraftMessageComposerStateCompositionMiddleware = (composer) => ({
|
|
|
6172
6185
|
if (composer.pollId) {
|
|
6173
6186
|
payload.poll_id = composer.pollId;
|
|
6174
6187
|
}
|
|
6188
|
+
if (composer.showReplyInChannel) {
|
|
6189
|
+
payload.show_in_channel = true;
|
|
6190
|
+
}
|
|
6175
6191
|
return next({
|
|
6176
6192
|
...state,
|
|
6177
6193
|
draft: {
|
|
@@ -6183,6 +6199,31 @@ var createDraftMessageComposerStateCompositionMiddleware = (composer) => ({
|
|
|
6183
6199
|
}
|
|
6184
6200
|
});
|
|
6185
6201
|
|
|
6202
|
+
// src/messageComposer/middleware/messageComposer/userDataInjection.ts
|
|
6203
|
+
var createUserDataInjectionMiddleware = (composer) => ({
|
|
6204
|
+
id: "stream-io/message-composer-middleware/user-data-injection",
|
|
6205
|
+
handlers: {
|
|
6206
|
+
compose: ({
|
|
6207
|
+
state,
|
|
6208
|
+
next,
|
|
6209
|
+
forward
|
|
6210
|
+
}) => {
|
|
6211
|
+
if (!composer.client.user) {
|
|
6212
|
+
return forward();
|
|
6213
|
+
}
|
|
6214
|
+
const { channel_mutes, devices, mutes, ...messageUser } = composer.client.user;
|
|
6215
|
+
return next({
|
|
6216
|
+
...state,
|
|
6217
|
+
localMessage: {
|
|
6218
|
+
...state.localMessage,
|
|
6219
|
+
user: messageUser,
|
|
6220
|
+
user_id: messageUser.id
|
|
6221
|
+
}
|
|
6222
|
+
});
|
|
6223
|
+
}
|
|
6224
|
+
}
|
|
6225
|
+
});
|
|
6226
|
+
|
|
6186
6227
|
// src/messageComposer/middleware/messageComposer/pollOnly.ts
|
|
6187
6228
|
var pollLocalMessageNullifiedFields = {
|
|
6188
6229
|
attachments: [],
|
|
@@ -6224,6 +6265,7 @@ var MessageComposerMiddlewareExecutor = class extends MiddlewareExecutor {
|
|
|
6224
6265
|
constructor({ composer }) {
|
|
6225
6266
|
super();
|
|
6226
6267
|
this.use([
|
|
6268
|
+
createUserDataInjectionMiddleware(composer),
|
|
6227
6269
|
createPollOnlyCompositionMiddleware(composer),
|
|
6228
6270
|
createTextComposerCompositionMiddleware(composer),
|
|
6229
6271
|
createAttachmentsCompositionMiddleware(composer),
|
|
@@ -7310,6 +7352,7 @@ var TextComposer = class {
|
|
|
7310
7352
|
var _WithSubscriptions = class _WithSubscriptions {
|
|
7311
7353
|
constructor() {
|
|
7312
7354
|
this.unsubscribeFunctions = /* @__PURE__ */ new Set();
|
|
7355
|
+
this.refCount = 0;
|
|
7313
7356
|
}
|
|
7314
7357
|
/**
|
|
7315
7358
|
* Returns a boolean, provides information of whether `registerSubscriptions`
|
|
@@ -7321,6 +7364,12 @@ var _WithSubscriptions = class _WithSubscriptions {
|
|
|
7321
7364
|
addUnsubscribeFunction(unsubscribeFunction) {
|
|
7322
7365
|
this.unsubscribeFunctions.add(unsubscribeFunction);
|
|
7323
7366
|
}
|
|
7367
|
+
/**
|
|
7368
|
+
* Increments `refCount` by one and returns new value.
|
|
7369
|
+
*/
|
|
7370
|
+
incrementRefCount() {
|
|
7371
|
+
return ++this.refCount;
|
|
7372
|
+
}
|
|
7324
7373
|
/**
|
|
7325
7374
|
* If you re-declare `unregisterSubscriptions` method within your class
|
|
7326
7375
|
* make sure to run the original too.
|
|
@@ -7337,8 +7386,13 @@ var _WithSubscriptions = class _WithSubscriptions {
|
|
|
7337
7386
|
* ```
|
|
7338
7387
|
*/
|
|
7339
7388
|
unregisterSubscriptions() {
|
|
7389
|
+
if (this.refCount > 1) {
|
|
7390
|
+
this.refCount--;
|
|
7391
|
+
return _WithSubscriptions.symbol;
|
|
7392
|
+
}
|
|
7340
7393
|
this.unsubscribeFunctions.forEach((unsubscribe) => unsubscribe());
|
|
7341
7394
|
this.unsubscribeFunctions.clear();
|
|
7395
|
+
this.refCount = 0;
|
|
7342
7396
|
return _WithSubscriptions.symbol;
|
|
7343
7397
|
}
|
|
7344
7398
|
};
|
|
@@ -7798,10 +7852,11 @@ var initEditingAuditState = (composition) => {
|
|
|
7798
7852
|
var initState5 = (composition) => {
|
|
7799
7853
|
if (!composition) {
|
|
7800
7854
|
return {
|
|
7855
|
+
draftId: null,
|
|
7801
7856
|
id: MessageComposer.generateId(),
|
|
7802
|
-
quotedMessage: null,
|
|
7803
7857
|
pollId: null,
|
|
7804
|
-
|
|
7858
|
+
quotedMessage: null,
|
|
7859
|
+
showReplyInChannel: false
|
|
7805
7860
|
};
|
|
7806
7861
|
}
|
|
7807
7862
|
const quotedMessage = composition.quoted_message;
|
|
@@ -7818,11 +7873,11 @@ var initState5 = (composition) => {
|
|
|
7818
7873
|
return {
|
|
7819
7874
|
draftId,
|
|
7820
7875
|
id,
|
|
7876
|
+
pollId: message.poll_id ?? null,
|
|
7821
7877
|
quotedMessage: quotedMessage ? formatMessage(quotedMessage) : null,
|
|
7822
|
-
|
|
7878
|
+
showReplyInChannel: false
|
|
7823
7879
|
};
|
|
7824
7880
|
};
|
|
7825
|
-
var noop3 = () => void 0;
|
|
7826
7881
|
var _MessageComposer = class _MessageComposer extends WithSubscriptions {
|
|
7827
7882
|
// todo: mediaRecorder: MediaRecorderController;
|
|
7828
7883
|
constructor({
|
|
@@ -7849,20 +7904,20 @@ var _MessageComposer = class _MessageComposer extends WithSubscriptions {
|
|
|
7849
7904
|
};
|
|
7850
7905
|
this.initEditingAuditState = (composition) => initEditingAuditState(composition);
|
|
7851
7906
|
this.registerSubscriptions = () => {
|
|
7852
|
-
if (this.hasSubscriptions) {
|
|
7853
|
-
|
|
7854
|
-
|
|
7855
|
-
|
|
7856
|
-
|
|
7857
|
-
|
|
7858
|
-
|
|
7859
|
-
|
|
7860
|
-
|
|
7861
|
-
|
|
7862
|
-
|
|
7863
|
-
|
|
7864
|
-
this.
|
|
7865
|
-
return this.unregisterSubscriptions
|
|
7907
|
+
if (!this.hasSubscriptions) {
|
|
7908
|
+
this.addUnsubscribeFunction(this.subscribeMessageComposerSetupStateChange());
|
|
7909
|
+
this.addUnsubscribeFunction(this.subscribeMessageUpdated());
|
|
7910
|
+
this.addUnsubscribeFunction(this.subscribeMessageDeleted());
|
|
7911
|
+
this.addUnsubscribeFunction(this.subscribeTextComposerStateChanged());
|
|
7912
|
+
this.addUnsubscribeFunction(this.subscribeAttachmentManagerStateChanged());
|
|
7913
|
+
this.addUnsubscribeFunction(this.subscribeLinkPreviewsManagerStateChanged());
|
|
7914
|
+
this.addUnsubscribeFunction(this.subscribePollComposerStateChanged());
|
|
7915
|
+
this.addUnsubscribeFunction(this.subscribeCustomDataManagerStateChanged());
|
|
7916
|
+
this.addUnsubscribeFunction(this.subscribeMessageComposerStateChanged());
|
|
7917
|
+
this.addUnsubscribeFunction(this.subscribeMessageComposerConfigStateChanged());
|
|
7918
|
+
}
|
|
7919
|
+
this.incrementRefCount();
|
|
7920
|
+
return () => this.unregisterSubscriptions();
|
|
7866
7921
|
};
|
|
7867
7922
|
this.subscribeMessageUpdated = () => {
|
|
7868
7923
|
const eventTypes = [
|
|
@@ -8014,6 +8069,9 @@ var _MessageComposer = class _MessageComposer extends WithSubscriptions {
|
|
|
8014
8069
|
this.setQuotedMessage = (quotedMessage) => {
|
|
8015
8070
|
this.state.partialNext({ quotedMessage });
|
|
8016
8071
|
};
|
|
8072
|
+
this.toggleShowReplyInChannel = () => {
|
|
8073
|
+
this.state.partialNext({ showReplyInChannel: !this.showReplyInChannel });
|
|
8074
|
+
};
|
|
8017
8075
|
this.clear = () => {
|
|
8018
8076
|
this.initState();
|
|
8019
8077
|
};
|
|
@@ -8087,15 +8145,21 @@ var _MessageComposer = class _MessageComposer extends WithSubscriptions {
|
|
|
8087
8145
|
const composition = await this.pollComposer.compose();
|
|
8088
8146
|
if (!composition || !composition.data.id) return;
|
|
8089
8147
|
try {
|
|
8090
|
-
const
|
|
8091
|
-
this.state.partialNext({ pollId: poll
|
|
8092
|
-
this.pollComposer.initState();
|
|
8148
|
+
const poll = await this.client.polls.createPoll(composition.data);
|
|
8149
|
+
this.state.partialNext({ pollId: poll?.id });
|
|
8093
8150
|
} catch (error) {
|
|
8094
|
-
this.client.notifications.
|
|
8151
|
+
this.client.notifications.addError({
|
|
8095
8152
|
message: "Failed to create the poll",
|
|
8096
8153
|
origin: {
|
|
8097
8154
|
emitter: "MessageComposer",
|
|
8098
8155
|
context: { composer: this }
|
|
8156
|
+
},
|
|
8157
|
+
options: {
|
|
8158
|
+
type: "api:poll:create:failed",
|
|
8159
|
+
metadata: {
|
|
8160
|
+
reason: error.message
|
|
8161
|
+
},
|
|
8162
|
+
originalError: error instanceof Error ? error : void 0
|
|
8099
8163
|
}
|
|
8100
8164
|
});
|
|
8101
8165
|
throw error;
|
|
@@ -8200,6 +8264,9 @@ var _MessageComposer = class _MessageComposer extends WithSubscriptions {
|
|
|
8200
8264
|
get pollId() {
|
|
8201
8265
|
return this.state.getLatestValue().pollId;
|
|
8202
8266
|
}
|
|
8267
|
+
get showReplyInChannel() {
|
|
8268
|
+
return this.state.getLatestValue().showReplyInChannel;
|
|
8269
|
+
}
|
|
8203
8270
|
get hasSendableData() {
|
|
8204
8271
|
return !!(!this.attachmentManager.uploadsInProgressCount && (!this.textComposer.textIsEmpty || this.attachmentManager.successfulUploadsCount > 0) || this.pollId);
|
|
8205
8272
|
}
|
|
@@ -11788,7 +11855,11 @@ var PollManager = class extends WithSubscriptions {
|
|
|
11788
11855
|
};
|
|
11789
11856
|
this.createPoll = async (poll) => {
|
|
11790
11857
|
const { poll: createdPoll } = await this.client.createPoll(poll);
|
|
11791
|
-
|
|
11858
|
+
if (!createdPoll.vote_counts_by_option) {
|
|
11859
|
+
createdPoll.vote_counts_by_option = {};
|
|
11860
|
+
}
|
|
11861
|
+
this.setOrOverwriteInCache(createdPoll);
|
|
11862
|
+
return this.fromState(createdPoll.id);
|
|
11792
11863
|
};
|
|
11793
11864
|
this.getPoll = async (id) => {
|
|
11794
11865
|
const cachedPoll = this.fromState(id);
|
|
@@ -12326,21 +12397,23 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12326
12397
|
}
|
|
12327
12398
|
};
|
|
12328
12399
|
|
|
12329
|
-
// src/notifications/
|
|
12330
|
-
var
|
|
12331
|
-
|
|
12332
|
-
|
|
12333
|
-
|
|
12334
|
-
|
|
12400
|
+
// src/notifications/configuration.ts
|
|
12401
|
+
var DURATION_MS = 3e3;
|
|
12402
|
+
var DEFAULT_NOTIFICATION_MANAGER_CONFIG = {
|
|
12403
|
+
durations: {
|
|
12404
|
+
error: DURATION_MS,
|
|
12405
|
+
info: DURATION_MS,
|
|
12406
|
+
success: DURATION_MS,
|
|
12407
|
+
warning: DURATION_MS
|
|
12408
|
+
}
|
|
12335
12409
|
};
|
|
12410
|
+
|
|
12411
|
+
// src/notifications/NotificationManager.ts
|
|
12336
12412
|
var NotificationManager = class {
|
|
12337
12413
|
constructor(config = {}) {
|
|
12338
12414
|
this.timeouts = /* @__PURE__ */ new Map();
|
|
12339
12415
|
this.store = new StateStore({ notifications: [] });
|
|
12340
|
-
this.config =
|
|
12341
|
-
...config,
|
|
12342
|
-
durations: config.durations || DURATIONS
|
|
12343
|
-
};
|
|
12416
|
+
this.config = mergeWith(DEFAULT_NOTIFICATION_MANAGER_CONFIG, config);
|
|
12344
12417
|
}
|
|
12345
12418
|
get notifications() {
|
|
12346
12419
|
return this.store.getLatestValue().notifications;
|
|
@@ -12360,21 +12433,24 @@ var NotificationManager = class {
|
|
|
12360
12433
|
add({ message, origin, options = {} }) {
|
|
12361
12434
|
const id = generateUUIDv4();
|
|
12362
12435
|
const now = Date.now();
|
|
12436
|
+
const severity = options.severity || "info";
|
|
12437
|
+
const duration = options.duration ?? this.config.durations[severity];
|
|
12363
12438
|
const notification = {
|
|
12364
12439
|
id,
|
|
12365
12440
|
message,
|
|
12366
12441
|
origin,
|
|
12367
|
-
|
|
12442
|
+
type: options?.type,
|
|
12443
|
+
severity,
|
|
12368
12444
|
createdAt: now,
|
|
12369
|
-
expiresAt:
|
|
12370
|
-
autoClose: options.autoClose ?? true,
|
|
12445
|
+
expiresAt: now + duration,
|
|
12371
12446
|
actions: options.actions,
|
|
12372
|
-
metadata: options.metadata
|
|
12447
|
+
metadata: options.metadata,
|
|
12448
|
+
originalError: options.originalError
|
|
12373
12449
|
};
|
|
12374
12450
|
this.store.partialNext({
|
|
12375
12451
|
notifications: [...this.store.getLatestValue().notifications, notification]
|
|
12376
12452
|
});
|
|
12377
|
-
if (notification.
|
|
12453
|
+
if (notification.expiresAt) {
|
|
12378
12454
|
const timeout = setTimeout(() => {
|
|
12379
12455
|
this.remove(id);
|
|
12380
12456
|
}, options.duration || this.config.durations[notification.severity]);
|
|
@@ -15083,7 +15159,7 @@ var StreamChat = class _StreamChat {
|
|
|
15083
15159
|
if (this.userAgent) {
|
|
15084
15160
|
return this.userAgent;
|
|
15085
15161
|
}
|
|
15086
|
-
const version = "9.
|
|
15162
|
+
const version = "9.6.1";
|
|
15087
15163
|
const clientBundle = "browser-cjs";
|
|
15088
15164
|
let userAgentString = "";
|
|
15089
15165
|
if (this.sdkIdentifier) {
|