stream-chat 9.0.1 → 9.1.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.
@@ -16431,6 +16431,10 @@ var pollStateChangeValidators = {
16431
16431
  max_votes_allowed: ({ data, value }) => {
16432
16432
  if (data.enforce_unique_vote && value)
16433
16433
  return { max_votes_allowed: "Enforce unique vote is enabled" };
16434
+ const numericMatch = value.match(/^[0-9]+$/);
16435
+ if (!numericMatch && value) {
16436
+ return { max_votes_allowed: "Only numbers are allowed" };
16437
+ }
16434
16438
  if (value?.length > 1 && !value.match(VALID_MAX_VOTES_VALUE_REGEX))
16435
16439
  return { max_votes_allowed: "Type a number from 2 to 10" };
16436
16440
  return { max_votes_allowed: void 0 };
@@ -16545,7 +16549,7 @@ var createPollComposerStateMiddleware = ({
16545
16549
  forward
16546
16550
  }) => {
16547
16551
  if (!state.targetFields) return forward();
16548
- const { previousState } = state;
16552
+ const { previousState, injectedFieldErrors } = state;
16549
16553
  const finalValidators = {
16550
16554
  ...pollStateChangeValidators,
16551
16555
  ...defaultPollFieldChangeEventValidators,
@@ -16565,7 +16569,7 @@ var createPollComposerStateMiddleware = ({
16565
16569
  nextState: {
16566
16570
  ...previousState,
16567
16571
  data: { ...previousState.data, ...newData },
16568
- errors: { ...previousState.errors, ...newErrors }
16572
+ errors: { ...previousState.errors, ...newErrors, ...injectedFieldErrors }
16569
16573
  }
16570
16574
  });
16571
16575
  },
@@ -16591,7 +16595,11 @@ var createPollComposerStateMiddleware = ({
16591
16595
  nextState: {
16592
16596
  ...previousState,
16593
16597
  data: { ...previousState.data, ...newData },
16594
- errors: { ...previousState.errors, ...newErrors }
16598
+ errors: {
16599
+ ...previousState.errors,
16600
+ ...newErrors,
16601
+ ...state.injectedFieldErrors
16602
+ }
16595
16603
  }
16596
16604
  });
16597
16605
  }
@@ -16652,13 +16660,20 @@ var PollComposer = class {
16652
16660
  this.initState = () => {
16653
16661
  this.state.next(this.initialState);
16654
16662
  };
16655
- this.updateFields = async (data) => {
16663
+ /**
16664
+ * Updates specified fields and generates relevant errors
16665
+ * @param data
16666
+ * @param injectedFieldErrors - errors produced externally that will take precedence over the errors generated in the middleware chaing
16667
+ */
16668
+ // FIXME: change method params to a single object with the next major release
16669
+ this.updateFields = async (data, injectedFieldErrors) => {
16656
16670
  const { state, status } = await this.stateMiddlewareExecutor.execute({
16657
16671
  eventName: "handleFieldChange",
16658
16672
  initialValue: {
16659
16673
  nextState: { ...this.state.getLatestValue() },
16660
16674
  previousState: { ...this.state.getLatestValue() },
16661
- targetFields: data
16675
+ targetFields: data,
16676
+ injectedFieldErrors
16662
16677
  }
16663
16678
  });
16664
16679
  if (status === "discard") return;
@@ -17130,11 +17145,48 @@ var createDraftMessageComposerStateCompositionMiddleware = (composer) => ({
17130
17145
  }
17131
17146
  });
17132
17147
 
17148
+ // src/messageComposer/middleware/messageComposer/pollOnly.ts
17149
+ var pollLocalMessageNullifiedFields = {
17150
+ attachments: [],
17151
+ mentioned_users: [],
17152
+ parent_id: void 0,
17153
+ quoted_message: void 0,
17154
+ text: ""
17155
+ };
17156
+ var createPollOnlyCompositionMiddleware = (composer) => ({
17157
+ id: "stream-io/message-composer-middleware/poll-only",
17158
+ handlers: {
17159
+ compose: ({
17160
+ state,
17161
+ complete,
17162
+ forward
17163
+ }) => {
17164
+ const pollId = composer.pollId;
17165
+ const isEditingMessage = !!composer.editedMessage;
17166
+ const isComposingThreadReply = !!composer.threadId;
17167
+ if (!pollId || isComposingThreadReply || isEditingMessage) return forward();
17168
+ return complete({
17169
+ ...state,
17170
+ localMessage: {
17171
+ ...state.localMessage,
17172
+ ...pollLocalMessageNullifiedFields,
17173
+ poll_id: pollId
17174
+ },
17175
+ message: {
17176
+ id: state.localMessage.id,
17177
+ poll_id: pollId
17178
+ }
17179
+ });
17180
+ }
17181
+ }
17182
+ });
17183
+
17133
17184
  // src/messageComposer/middleware/messageComposer/MessageComposerMiddlewareExecutor.ts
17134
17185
  var MessageComposerMiddlewareExecutor = class extends MiddlewareExecutor {
17135
17186
  constructor({ composer }) {
17136
17187
  super();
17137
17188
  this.use([
17189
+ createPollOnlyCompositionMiddleware(composer),
17138
17190
  createTextComposerCompositionMiddleware(composer),
17139
17191
  createAttachmentsCompositionMiddleware(composer),
17140
17192
  createLinkPreviewsCompositionMiddleware(composer),
@@ -17986,27 +18038,8 @@ var TextComposerMiddlewareExecutor = class extends MiddlewareExecutor {
17986
18038
  eventName,
17987
18039
  initialValue: initialState
17988
18040
  });
17989
- if (result && result.state.suggestions) {
17990
- try {
17991
- const searchResult = await withCancellation(
17992
- "textComposer-suggestions-search",
17993
- async () => {
17994
- await result.state.suggestions?.searchSource.search(
17995
- result.state.suggestions?.query
17996
- );
17997
- }
17998
- );
17999
- if (searchResult === "canceled") return { ...result, status: "discard" };
18000
- } catch (error) {
18001
- return {
18002
- ...result,
18003
- state: {
18004
- ...result.state,
18005
- suggestions: void 0
18006
- }
18007
- };
18008
- }
18009
- }
18041
+ const { query, searchSource } = result.state.suggestions ?? {};
18042
+ searchSource?.search(query)?.catch(console.error);
18010
18043
  return result;
18011
18044
  }
18012
18045
  };
@@ -18684,15 +18717,17 @@ var initState5 = (composition) => {
18684
18717
  const quotedMessage = composition.quoted_message;
18685
18718
  let message;
18686
18719
  let draftId = null;
18720
+ let id = MessageComposer.generateId();
18687
18721
  if (compositionIsDraftResponse(composition)) {
18688
18722
  message = composition.message;
18689
18723
  draftId = composition.message.id;
18690
18724
  } else {
18691
18725
  message = composition;
18726
+ id = composition.id;
18692
18727
  }
18693
18728
  return {
18694
18729
  draftId,
18695
- id: message.id,
18730
+ id,
18696
18731
  quotedMessage: quotedMessage ? formatMessage(quotedMessage) : null,
18697
18732
  pollId: message.poll_id ?? null
18698
18733
  };
@@ -18715,6 +18750,7 @@ var _MessageComposer = class _MessageComposer {
18715
18750
  this.attachmentManager.initState({ message });
18716
18751
  this.linkPreviewsManager.initState({ message });
18717
18752
  this.textComposer.initState({ message });
18753
+ this.pollComposer.initState();
18718
18754
  this.customDataManager.initState({ message });
18719
18755
  this.state.next(initState5(composition));
18720
18756
  if (composition && !compositionIsDraftResponse(composition) && message && isLocalMessage(message)) {
@@ -18875,11 +18911,6 @@ var _MessageComposer = class _MessageComposer {
18875
18911
  this.state.partialNext({ quotedMessage });
18876
18912
  };
18877
18913
  this.clear = () => {
18878
- this.attachmentManager.initState();
18879
- this.linkPreviewsManager.initState();
18880
- this.textComposer.initState();
18881
- this.pollComposer.initState();
18882
- this.customDataManager.initState();
18883
18914
  this.initState();
18884
18915
  };
18885
18916
  this.restore = () => {
@@ -18954,6 +18985,7 @@ var _MessageComposer = class _MessageComposer {
18954
18985
  try {
18955
18986
  const { poll } = await this.client.createPoll(composition.data);
18956
18987
  this.state.partialNext({ pollId: poll.id });
18988
+ this.pollComposer.initState();
18957
18989
  } catch (error) {
18958
18990
  this.client.notifications.add({
18959
18991
  message: "Failed to create the poll",
@@ -24175,18 +24207,16 @@ var StreamChat = class _StreamChat {
24175
24207
  );
24176
24208
  }
24177
24209
  /**
24178
- * queryChannels - Query channels
24210
+ * queryChannelsRequest - Queries channels and returns the raw response
24179
24211
  *
24180
24212
  * @param {ChannelFilters} filterConditions object MongoDB style filters
24181
24213
  * @param {ChannelSort} [sort] Sort options, for instance {created_at: -1}.
24182
24214
  * When using multiple fields, make sure you use array of objects to guarantee field order, for instance [{last_updated: -1}, {created_at: 1}]
24183
24215
  * @param {ChannelOptions} [options] Options object
24184
- * @param {ChannelStateOptions} [stateOptions] State options object. These options will only be used for state management and won't be sent in the request.
24185
- * - stateOptions.skipInitialization - Skips the initialization of the state for the channels matching the ids in the list.
24186
24216
  *
24187
- * @return {Promise<{ channels: Array<ChannelAPIResponse>}> } search channels response
24217
+ * @return {Promise<Array<ChannelAPIResponse>>} search channels response
24188
24218
  */
24189
- async queryChannels(filterConditions, sort = [], options = {}, stateOptions = {}) {
24219
+ async queryChannelsRequest(filterConditions, sort = [], options = {}) {
24190
24220
  const defaultOptions = {
24191
24221
  state: true,
24192
24222
  watch: true,
@@ -24206,14 +24236,31 @@ var StreamChat = class _StreamChat {
24206
24236
  this.baseURL + "/channels",
24207
24237
  payload
24208
24238
  );
24239
+ return data.channels;
24240
+ }
24241
+ /**
24242
+ * queryChannels - Query channels
24243
+ *
24244
+ * @param {ChannelFilters} filterConditions object MongoDB style filters
24245
+ * @param {ChannelSort} [sort] Sort options, for instance {created_at: -1}.
24246
+ * When using multiple fields, make sure you use array of objects to guarantee field order, for instance [{last_updated: -1}, {created_at: 1}]
24247
+ * @param {ChannelOptions} [options] Options object
24248
+ * @param {ChannelStateOptions} [stateOptions] State options object. These options will only be used for state management and won't be sent in the request.
24249
+ * - stateOptions.skipInitialization - Skips the initialization of the state for the channels matching the ids in the list.
24250
+ * - stateOptions.skipHydration - Skips returning the channels as instances of the Channel class and rather returns the raw query response.
24251
+ *
24252
+ * @return {Promise<Array<Channel>>} search channels response
24253
+ */
24254
+ async queryChannels(filterConditions, sort = [], options = {}, stateOptions = {}) {
24255
+ const channels = await this.queryChannelsRequest(filterConditions, sort, options);
24209
24256
  this.dispatchEvent({
24210
24257
  type: "channels.queried",
24211
24258
  queriedChannels: {
24212
- channels: data.channels,
24259
+ channels,
24213
24260
  isLatestMessageSet: true
24214
24261
  }
24215
24262
  });
24216
- return this.hydrateActiveChannels(data.channels, stateOptions, options);
24263
+ return this.hydrateActiveChannels(channels, stateOptions, options);
24217
24264
  }
24218
24265
  /**
24219
24266
  * queryReactions - Query reactions
@@ -25160,7 +25207,7 @@ var StreamChat = class _StreamChat {
25160
25207
  if (this.userAgent) {
25161
25208
  return this.userAgent;
25162
25209
  }
25163
- const version = "9.0.1";
25210
+ const version = "9.1.1";
25164
25211
  const clientBundle = "node-cjs";
25165
25212
  let userAgentString = "";
25166
25213
  if (this.sdkIdentifier) {