stream-chat 9.0.1 → 9.1.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.
@@ -5088,6 +5088,10 @@ var pollStateChangeValidators = {
5088
5088
  max_votes_allowed: ({ data, value }) => {
5089
5089
  if (data.enforce_unique_vote && value)
5090
5090
  return { max_votes_allowed: "Enforce unique vote is enabled" };
5091
+ const numericMatch = value.match(/^[0-9]+$/);
5092
+ if (!numericMatch && value) {
5093
+ return { max_votes_allowed: "Only numbers are allowed" };
5094
+ }
5091
5095
  if (value?.length > 1 && !value.match(VALID_MAX_VOTES_VALUE_REGEX))
5092
5096
  return { max_votes_allowed: "Type a number from 2 to 10" };
5093
5097
  return { max_votes_allowed: void 0 };
@@ -5202,7 +5206,7 @@ var createPollComposerStateMiddleware = ({
5202
5206
  forward
5203
5207
  }) => {
5204
5208
  if (!state.targetFields) return forward();
5205
- const { previousState } = state;
5209
+ const { previousState, injectedFieldErrors } = state;
5206
5210
  const finalValidators = {
5207
5211
  ...pollStateChangeValidators,
5208
5212
  ...defaultPollFieldChangeEventValidators,
@@ -5222,7 +5226,7 @@ var createPollComposerStateMiddleware = ({
5222
5226
  nextState: {
5223
5227
  ...previousState,
5224
5228
  data: { ...previousState.data, ...newData },
5225
- errors: { ...previousState.errors, ...newErrors }
5229
+ errors: { ...previousState.errors, ...newErrors, ...injectedFieldErrors }
5226
5230
  }
5227
5231
  });
5228
5232
  },
@@ -5248,7 +5252,11 @@ var createPollComposerStateMiddleware = ({
5248
5252
  nextState: {
5249
5253
  ...previousState,
5250
5254
  data: { ...previousState.data, ...newData },
5251
- errors: { ...previousState.errors, ...newErrors }
5255
+ errors: {
5256
+ ...previousState.errors,
5257
+ ...newErrors,
5258
+ ...state.injectedFieldErrors
5259
+ }
5252
5260
  }
5253
5261
  });
5254
5262
  }
@@ -5309,13 +5317,20 @@ var PollComposer = class {
5309
5317
  this.initState = () => {
5310
5318
  this.state.next(this.initialState);
5311
5319
  };
5312
- this.updateFields = async (data) => {
5320
+ /**
5321
+ * Updates specified fields and generates relevant errors
5322
+ * @param data
5323
+ * @param injectedFieldErrors - errors produced externally that will take precedence over the errors generated in the middleware chaing
5324
+ */
5325
+ // FIXME: change method params to a single object with the next major release
5326
+ this.updateFields = async (data, injectedFieldErrors) => {
5313
5327
  const { state, status } = await this.stateMiddlewareExecutor.execute({
5314
5328
  eventName: "handleFieldChange",
5315
5329
  initialValue: {
5316
5330
  nextState: { ...this.state.getLatestValue() },
5317
5331
  previousState: { ...this.state.getLatestValue() },
5318
- targetFields: data
5332
+ targetFields: data,
5333
+ injectedFieldErrors
5319
5334
  }
5320
5335
  });
5321
5336
  if (status === "discard") return;
@@ -5787,11 +5802,48 @@ var createDraftMessageComposerStateCompositionMiddleware = (composer) => ({
5787
5802
  }
5788
5803
  });
5789
5804
 
5805
+ // src/messageComposer/middleware/messageComposer/pollOnly.ts
5806
+ var pollLocalMessageNullifiedFields = {
5807
+ attachments: [],
5808
+ mentioned_users: [],
5809
+ parent_id: void 0,
5810
+ quoted_message: void 0,
5811
+ text: ""
5812
+ };
5813
+ var createPollOnlyCompositionMiddleware = (composer) => ({
5814
+ id: "stream-io/message-composer-middleware/poll-only",
5815
+ handlers: {
5816
+ compose: ({
5817
+ state,
5818
+ complete,
5819
+ forward
5820
+ }) => {
5821
+ const pollId = composer.pollId;
5822
+ const isEditingMessage = !!composer.editedMessage;
5823
+ const isComposingThreadReply = !!composer.threadId;
5824
+ if (!pollId || isComposingThreadReply || isEditingMessage) return forward();
5825
+ return complete({
5826
+ ...state,
5827
+ localMessage: {
5828
+ ...state.localMessage,
5829
+ ...pollLocalMessageNullifiedFields,
5830
+ poll_id: pollId
5831
+ },
5832
+ message: {
5833
+ id: state.localMessage.id,
5834
+ poll_id: pollId
5835
+ }
5836
+ });
5837
+ }
5838
+ }
5839
+ });
5840
+
5790
5841
  // src/messageComposer/middleware/messageComposer/MessageComposerMiddlewareExecutor.ts
5791
5842
  var MessageComposerMiddlewareExecutor = class extends MiddlewareExecutor {
5792
5843
  constructor({ composer }) {
5793
5844
  super();
5794
5845
  this.use([
5846
+ createPollOnlyCompositionMiddleware(composer),
5795
5847
  createTextComposerCompositionMiddleware(composer),
5796
5848
  createAttachmentsCompositionMiddleware(composer),
5797
5849
  createLinkPreviewsCompositionMiddleware(composer),
@@ -6643,27 +6695,8 @@ var TextComposerMiddlewareExecutor = class extends MiddlewareExecutor {
6643
6695
  eventName,
6644
6696
  initialValue: initialState
6645
6697
  });
6646
- if (result && result.state.suggestions) {
6647
- try {
6648
- const searchResult = await withCancellation(
6649
- "textComposer-suggestions-search",
6650
- async () => {
6651
- await result.state.suggestions?.searchSource.search(
6652
- result.state.suggestions?.query
6653
- );
6654
- }
6655
- );
6656
- if (searchResult === "canceled") return { ...result, status: "discard" };
6657
- } catch (error) {
6658
- return {
6659
- ...result,
6660
- state: {
6661
- ...result.state,
6662
- suggestions: void 0
6663
- }
6664
- };
6665
- }
6666
- }
6698
+ const { query, searchSource } = result.state.suggestions ?? {};
6699
+ searchSource?.search(query)?.catch(console.error);
6667
6700
  return result;
6668
6701
  }
6669
6702
  };
@@ -7341,15 +7374,17 @@ var initState5 = (composition) => {
7341
7374
  const quotedMessage = composition.quoted_message;
7342
7375
  let message;
7343
7376
  let draftId = null;
7377
+ let id = MessageComposer.generateId();
7344
7378
  if (compositionIsDraftResponse(composition)) {
7345
7379
  message = composition.message;
7346
7380
  draftId = composition.message.id;
7347
7381
  } else {
7348
7382
  message = composition;
7383
+ id = composition.id;
7349
7384
  }
7350
7385
  return {
7351
7386
  draftId,
7352
- id: message.id,
7387
+ id,
7353
7388
  quotedMessage: quotedMessage ? formatMessage(quotedMessage) : null,
7354
7389
  pollId: message.poll_id ?? null
7355
7390
  };
@@ -7372,6 +7407,7 @@ var _MessageComposer = class _MessageComposer {
7372
7407
  this.attachmentManager.initState({ message });
7373
7408
  this.linkPreviewsManager.initState({ message });
7374
7409
  this.textComposer.initState({ message });
7410
+ this.pollComposer.initState();
7375
7411
  this.customDataManager.initState({ message });
7376
7412
  this.state.next(initState5(composition));
7377
7413
  if (composition && !compositionIsDraftResponse(composition) && message && isLocalMessage(message)) {
@@ -7532,11 +7568,6 @@ var _MessageComposer = class _MessageComposer {
7532
7568
  this.state.partialNext({ quotedMessage });
7533
7569
  };
7534
7570
  this.clear = () => {
7535
- this.attachmentManager.initState();
7536
- this.linkPreviewsManager.initState();
7537
- this.textComposer.initState();
7538
- this.pollComposer.initState();
7539
- this.customDataManager.initState();
7540
7571
  this.initState();
7541
7572
  };
7542
7573
  this.restore = () => {
@@ -7611,6 +7642,7 @@ var _MessageComposer = class _MessageComposer {
7611
7642
  try {
7612
7643
  const { poll } = await this.client.createPoll(composition.data);
7613
7644
  this.state.partialNext({ pollId: poll.id });
7645
+ this.pollComposer.initState();
7614
7646
  } catch (error) {
7615
7647
  this.client.notifications.add({
7616
7648
  message: "Failed to create the poll",
@@ -13829,7 +13861,7 @@ var StreamChat = class _StreamChat {
13829
13861
  if (this.userAgent) {
13830
13862
  return this.userAgent;
13831
13863
  }
13832
- const version = "9.0.1";
13864
+ const version = "9.1.0";
13833
13865
  const clientBundle = "browser-cjs";
13834
13866
  let userAgentString = "";
13835
13867
  if (this.sdkIdentifier) {