stream-chat 9.5.1 → 9.6.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.
@@ -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: "Error uploading attachment",
4843
- origin: { emitter: "AttachmentManager", context: { attachment } }
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
- let finalError = {
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),
@@ -7798,10 +7840,11 @@ var initEditingAuditState = (composition) => {
7798
7840
  var initState5 = (composition) => {
7799
7841
  if (!composition) {
7800
7842
  return {
7843
+ draftId: null,
7801
7844
  id: MessageComposer.generateId(),
7802
- quotedMessage: null,
7803
7845
  pollId: null,
7804
- draftId: null
7846
+ quotedMessage: null,
7847
+ showReplyInChannel: false
7805
7848
  };
7806
7849
  }
7807
7850
  const quotedMessage = composition.quoted_message;
@@ -7818,8 +7861,9 @@ var initState5 = (composition) => {
7818
7861
  return {
7819
7862
  draftId,
7820
7863
  id,
7864
+ pollId: message.poll_id ?? null,
7821
7865
  quotedMessage: quotedMessage ? formatMessage(quotedMessage) : null,
7822
- pollId: message.poll_id ?? null
7866
+ showReplyInChannel: false
7823
7867
  };
7824
7868
  };
7825
7869
  var noop3 = () => void 0;
@@ -8014,6 +8058,9 @@ var _MessageComposer = class _MessageComposer extends WithSubscriptions {
8014
8058
  this.setQuotedMessage = (quotedMessage) => {
8015
8059
  this.state.partialNext({ quotedMessage });
8016
8060
  };
8061
+ this.toggleShowReplyInChannel = () => {
8062
+ this.state.partialNext({ showReplyInChannel: !this.showReplyInChannel });
8063
+ };
8017
8064
  this.clear = () => {
8018
8065
  this.initState();
8019
8066
  };
@@ -8087,15 +8134,21 @@ var _MessageComposer = class _MessageComposer extends WithSubscriptions {
8087
8134
  const composition = await this.pollComposer.compose();
8088
8135
  if (!composition || !composition.data.id) return;
8089
8136
  try {
8090
- const { poll } = await this.client.createPoll(composition.data);
8091
- this.state.partialNext({ pollId: poll.id });
8092
- this.pollComposer.initState();
8137
+ const poll = await this.client.polls.createPoll(composition.data);
8138
+ this.state.partialNext({ pollId: poll?.id });
8093
8139
  } catch (error) {
8094
- this.client.notifications.add({
8140
+ this.client.notifications.addError({
8095
8141
  message: "Failed to create the poll",
8096
8142
  origin: {
8097
8143
  emitter: "MessageComposer",
8098
8144
  context: { composer: this }
8145
+ },
8146
+ options: {
8147
+ type: "api:poll:create:failed",
8148
+ metadata: {
8149
+ reason: error.message
8150
+ },
8151
+ originalError: error instanceof Error ? error : void 0
8099
8152
  }
8100
8153
  });
8101
8154
  throw error;
@@ -8200,6 +8253,9 @@ var _MessageComposer = class _MessageComposer extends WithSubscriptions {
8200
8253
  get pollId() {
8201
8254
  return this.state.getLatestValue().pollId;
8202
8255
  }
8256
+ get showReplyInChannel() {
8257
+ return this.state.getLatestValue().showReplyInChannel;
8258
+ }
8203
8259
  get hasSendableData() {
8204
8260
  return !!(!this.attachmentManager.uploadsInProgressCount && (!this.textComposer.textIsEmpty || this.attachmentManager.successfulUploadsCount > 0) || this.pollId);
8205
8261
  }
@@ -11788,7 +11844,11 @@ var PollManager = class extends WithSubscriptions {
11788
11844
  };
11789
11845
  this.createPoll = async (poll) => {
11790
11846
  const { poll: createdPoll } = await this.client.createPoll(poll);
11791
- return new Poll({ client: this.client, poll: createdPoll });
11847
+ if (!createdPoll.vote_counts_by_option) {
11848
+ createdPoll.vote_counts_by_option = {};
11849
+ }
11850
+ this.setOrOverwriteInCache(createdPoll);
11851
+ return this.fromState(createdPoll.id);
11792
11852
  };
11793
11853
  this.getPoll = async (id) => {
11794
11854
  const cachedPoll = this.fromState(id);
@@ -12326,21 +12386,23 @@ var ChannelManager = class extends WithSubscriptions {
12326
12386
  }
12327
12387
  };
12328
12388
 
12329
- // src/notifications/NotificationManager.ts
12330
- var DURATIONS = {
12331
- error: 1e4,
12332
- warning: 5e3,
12333
- info: 3e3,
12334
- success: 3e3
12389
+ // src/notifications/configuration.ts
12390
+ var DURATION_MS = 3e3;
12391
+ var DEFAULT_NOTIFICATION_MANAGER_CONFIG = {
12392
+ durations: {
12393
+ error: DURATION_MS,
12394
+ info: DURATION_MS,
12395
+ success: DURATION_MS,
12396
+ warning: DURATION_MS
12397
+ }
12335
12398
  };
12399
+
12400
+ // src/notifications/NotificationManager.ts
12336
12401
  var NotificationManager = class {
12337
12402
  constructor(config = {}) {
12338
12403
  this.timeouts = /* @__PURE__ */ new Map();
12339
12404
  this.store = new StateStore({ notifications: [] });
12340
- this.config = {
12341
- ...config,
12342
- durations: config.durations || DURATIONS
12343
- };
12405
+ this.config = mergeWith(DEFAULT_NOTIFICATION_MANAGER_CONFIG, config);
12344
12406
  }
12345
12407
  get notifications() {
12346
12408
  return this.store.getLatestValue().notifications;
@@ -12360,21 +12422,24 @@ var NotificationManager = class {
12360
12422
  add({ message, origin, options = {} }) {
12361
12423
  const id = generateUUIDv4();
12362
12424
  const now = Date.now();
12425
+ const severity = options.severity || "info";
12426
+ const duration = options.duration ?? this.config.durations[severity];
12363
12427
  const notification = {
12364
12428
  id,
12365
12429
  message,
12366
12430
  origin,
12367
- severity: options.severity || "info",
12431
+ type: options?.type,
12432
+ severity,
12368
12433
  createdAt: now,
12369
- expiresAt: options.duration ? now + options.duration : void 0,
12370
- autoClose: options.autoClose ?? true,
12434
+ expiresAt: now + duration,
12371
12435
  actions: options.actions,
12372
- metadata: options.metadata
12436
+ metadata: options.metadata,
12437
+ originalError: options.originalError
12373
12438
  };
12374
12439
  this.store.partialNext({
12375
12440
  notifications: [...this.store.getLatestValue().notifications, notification]
12376
12441
  });
12377
- if (notification.autoClose && notification.expiresAt) {
12442
+ if (notification.expiresAt) {
12378
12443
  const timeout = setTimeout(() => {
12379
12444
  this.remove(id);
12380
12445
  }, options.duration || this.config.durations[notification.severity]);
@@ -15083,7 +15148,7 @@ var StreamChat = class _StreamChat {
15083
15148
  if (this.userAgent) {
15084
15149
  return this.userAgent;
15085
15150
  }
15086
- const version = "9.5.1";
15151
+ const version = "9.6.0";
15087
15152
  const clientBundle = "browser-cjs";
15088
15153
  let userAgentString = "";
15089
15154
  if (this.sdkIdentifier) {