stream-chat 9.54.1 → 9.54.3

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.
@@ -1048,7 +1048,11 @@ var messagePaginationLinear = ({
1048
1048
  newPagination.hasNext = hasNext;
1049
1049
  return newPagination;
1050
1050
  };
1051
+ var hasMessagePaginationCursor = (options) => !!(options?.id_lt || options?.id_lte || options?.id_gt || options?.id_gte || options?.id_around || options?.created_at_before || options?.created_at_before_or_equal || options?.created_at_after || options?.created_at_after_or_equal || options?.created_at_around || options?.offset);
1051
1052
  var messageSetPagination = (params) => {
1053
+ if (params.requestedPageSize === 0 && params.parentSet.messages.length > 0) {
1054
+ return params.parentSet.pagination;
1055
+ }
1052
1056
  if (params.parentSet.messages.length + (params.returnedPage.length - params.filteredReturnedPage.length) < params.returnedPage.length) {
1053
1057
  params.logger?.(
1054
1058
  "error",
@@ -1224,6 +1228,7 @@ var aOverlapsB = (a, b) => {
1224
1228
  return oldestMessageA < oldestMessageB && oldestMessageB < newestMessageA && newestMessageA < newestMessageB;
1225
1229
  };
1226
1230
  var messageSetsOverlapByTimestamp = (a, b) => aContainsOrEqualsB(a, b) || aContainsOrEqualsB(b, a) || aOverlapsB(a, b) || aOverlapsB(b, a);
1231
+ var isLocalOnlyMessage = (message) => message.status === "sending" || message.status === "failed" || message.type === "error" || message.type === "ephemeral";
1227
1232
  var ChannelState = class {
1228
1233
  constructor(channel) {
1229
1234
  /**
@@ -1883,6 +1888,22 @@ var ChannelState = class {
1883
1888
  currentMessages.isCurrent = false;
1884
1889
  this.messageSets[index].isCurrent = true;
1885
1890
  }
1891
+ /**
1892
+ * Empties the latest message set if the newest page is newer than it and shares no messages
1893
+ * with it. Merging them would hide the messages in between from pagination.
1894
+ * Skipped while the set holds local-only messages, so they are not lost.
1895
+ */
1896
+ _dropLatestMessagesDisjointFrom(newestPage) {
1897
+ const latestSet = this.messageSets.find((s) => s.isLatest);
1898
+ const newestLoaded = latestSet?.messages.slice(-1)[0];
1899
+ const oldestReturned = newestPage.find((m) => !m.parent_id || m.show_in_channel);
1900
+ if (!latestSet || !newestLoaded || !oldestReturned?.created_at) return;
1901
+ if (new Date(oldestReturned.created_at).getTime() <= newestLoaded.created_at.getTime() || this.areMessageSetsOverlap(latestSet.messages, newestPage) || latestSet.messages.some(isLocalOnlyMessage)) {
1902
+ return;
1903
+ }
1904
+ latestSet.messages = [];
1905
+ latestSet.pagination = { ...DEFAULT_MESSAGE_SET_PAGINATION };
1906
+ }
1886
1907
  areMessageSetsOverlap(messages1, messages2) {
1887
1908
  return messages1.some((m1) => messages2.find((m2) => m1.id === m2.id));
1888
1909
  }
@@ -3865,13 +3886,14 @@ var localAttachmentToAttachment = (localAttachment) => {
3865
3886
  const { localMetadata, ...attachment } = localAttachment;
3866
3887
  return attachment;
3867
3888
  };
3889
+ var isSendable = (attachment) => isFinishedUpload(attachment) || !isLocalUploadAttachment(attachment);
3868
3890
  var composeWithPendingUploads = ({
3869
3891
  composer,
3870
3892
  state
3871
3893
  }) => {
3872
3894
  const composerIsKeptAsDraft = !!composer.pollId;
3873
3895
  const relevantAttachments = composer.attachmentManager.attachments.filter(
3874
- (attachment) => isFinishedUpload(attachment) || !composerIsKeptAsDraft && isPendingUpload(attachment)
3896
+ (attachment) => isSendable(attachment) || !composerIsKeptAsDraft && isPendingUpload(attachment)
3875
3897
  );
3876
3898
  const localAttachments = (state.localMessage.attachments ?? []).concat(
3877
3899
  relevantAttachments.map(
@@ -3879,7 +3901,7 @@ var composeWithPendingUploads = ({
3879
3901
  )
3880
3902
  );
3881
3903
  const messageAttachments = (state.message.attachments ?? []).concat(
3882
- relevantAttachments.filter(isFinishedUpload).map(localAttachmentToAttachment)
3904
+ relevantAttachments.filter(isSendable).map(localAttachmentToAttachment)
3883
3905
  );
3884
3906
  if (!localAttachments.length && !messageAttachments.length) return state;
3885
3907
  return {
@@ -3934,7 +3956,7 @@ var createAttachmentsCompositionMiddleware = (composer) => ({
3934
3956
  return discard();
3935
3957
  }
3936
3958
  const attachments = (state.message.attachments ?? []).concat(
3937
- attachmentManager.successfulUploads.map(localAttachmentToAttachment)
3959
+ attachmentManager.attachments.filter(isSendable).map(localAttachmentToAttachment)
3938
3960
  );
3939
3961
  if (!attachments.length) return forward();
3940
3962
  return next({
@@ -3961,9 +3983,9 @@ var createDraftAttachmentsCompositionMiddleware = (composer) => ({
3961
3983
  }) => {
3962
3984
  const { attachmentManager } = composer;
3963
3985
  if (!attachmentManager) return forward();
3964
- const successfulUploads = attachmentManager.successfulUploads;
3965
- const attachments = successfulUploads.length ? (state.draft.attachments ?? []).concat(
3966
- successfulUploads.map(localAttachmentToAttachment)
3986
+ const sendableAttachments = attachmentManager.attachments.filter(isSendable);
3987
+ const attachments = sendableAttachments.length ? (state.draft.attachments ?? []).concat(
3988
+ sendableAttachments.map(localAttachmentToAttachment)
3967
3989
  ) : void 0;
3968
3990
  return next({
3969
3991
  ...state,
@@ -10601,7 +10623,8 @@ var Channel = class {
10601
10623
  }
10602
10624
  const { messageSet, filteredMessageIds } = this._initializeState(
10603
10625
  state,
10604
- messageSetToAddToIfDoesNotExist
10626
+ messageSetToAddToIfDoesNotExist,
10627
+ !hasMessagePaginationCursor(options?.messages)
10605
10628
  );
10606
10629
  messageSet.pagination = {
10607
10630
  ...messageSet.pagination,
@@ -11219,7 +11242,7 @@ var Channel = class {
11219
11242
  );
11220
11243
  }
11221
11244
  }
11222
- _initializeState(state, messageSetToAddToIfDoesNotExist = "latest") {
11245
+ _initializeState(state, messageSetToAddToIfDoesNotExist = "latest", isNewestPage = true) {
11223
11246
  const { state: clientState, user, userID } = this.getClient();
11224
11247
  if (state.members) {
11225
11248
  this._hydrateMembers({ members: state.members });
@@ -11234,6 +11257,9 @@ var Channel = class {
11234
11257
  if (!this.state.messages) {
11235
11258
  this.state.initMessages();
11236
11259
  }
11260
+ if (messageSetToAddToIfDoesNotExist === "latest" && isNewestPage) {
11261
+ this.state._dropLatestMessagesDisjointFrom(messages);
11262
+ }
11237
11263
  const { messageSet, filteredMessageIds } = this.state.addMessagesSorted(
11238
11264
  messages,
11239
11265
  false,
@@ -13163,9 +13189,14 @@ function applyOwnVoteDelta(state, { add = [], remove = [] }) {
13163
13189
  }
13164
13190
  voteCount = Math.max(voteCount - 1, 0);
13165
13191
  if (latestVotesByOption?.[optionId]) {
13166
- latestVotesByOption[optionId] = latestVotesByOption[optionId].filter(
13192
+ const latestVotes = latestVotesByOption[optionId].filter(
13167
13193
  (latestVote) => latestVote.id !== vote.id
13168
13194
  );
13195
+ if (latestVotes.length) {
13196
+ latestVotesByOption[optionId] = latestVotes;
13197
+ } else {
13198
+ delete latestVotesByOption[optionId];
13199
+ }
13169
13200
  }
13170
13201
  }
13171
13202
  for (const vote of add) {
@@ -13825,11 +13856,15 @@ var ChannelManager = class extends WithSubscriptions {
13825
13856
  sort
13826
13857
  });
13827
13858
  if (channelsFromDB) {
13828
- const offlineChannels = this.client.hydrateActiveChannels(channelsFromDB, {
13829
- offlineMode: true,
13830
- skipInitialization: []
13831
- // passing empty array will clear out the existing messages from channel state, this removes the possibility of duplicate messages
13832
- });
13859
+ const offlineChannels = this.client.hydrateActiveChannels(
13860
+ channelsFromDB,
13861
+ {
13862
+ offlineMode: true,
13863
+ skipInitialization: []
13864
+ // passing empty array will clear out the existing messages from channel state, this removes the possibility of duplicate messages
13865
+ },
13866
+ options
13867
+ );
13833
13868
  this.state.partialNext({ channels: offlineChannels });
13834
13869
  }
13835
13870
  }
@@ -15270,7 +15305,7 @@ var StreamChat = class _StreamChat {
15270
15305
  return this.userAgent;
15271
15306
  }
15272
15307
  if (!this.cachedUserAgent) {
15273
- const version = "9.54.1";
15308
+ const version = "9.54.3";
15274
15309
  const { name: sdkName, version: sdkVersion } = this.sdkIdentifier ?? {};
15275
15310
  const { name: appName, version: appVersion } = this.appIdentifier ?? {};
15276
15311
  const { os, model: deviceModel } = this.deviceIdentifier ?? {};
@@ -16200,7 +16235,7 @@ var StreamChat = class _StreamChat {
16200
16235
  ...updatedMessagesSet.pagination,
16201
16236
  ...messageSetPagination({
16202
16237
  parentSet: updatedMessagesSet,
16203
- requestedPageSize: queryChannelsOptions?.message_limit || DEFAULT_QUERY_CHANNELS_MESSAGE_LIST_PAGE_SIZE,
16238
+ requestedPageSize: queryChannelsOptions?.message_limit ?? DEFAULT_QUERY_CHANNELS_MESSAGE_LIST_PAGE_SIZE,
16204
16239
  returnedPage: channelState.messages,
16205
16240
  filteredReturnedPage: channelState.messages.filter(
16206
16241
  (m) => !filteredMessageIds.includes(m.id)