stream-chat-react 11.1.0 → 11.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.
@@ -52387,7 +52387,7 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
52387
52387
 
52388
52388
  window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};
52389
52389
 
52390
- window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var version$1 = '11.1.0';
52390
+ window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var version$1 = '11.1.1';
52391
52391
 
52392
52392
  window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var useChat = function (_a) {
52393
52393
  var _b, _c;
@@ -55183,11 +55183,14 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
55183
55183
  };
55184
55184
  }
55185
55185
 
55186
- window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var STATUSES_EXCLUDED_FROM_PREPEND = ['sending', 'failed'];
55186
+ window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var STATUSES_EXCLUDED_FROM_PREPEND = {
55187
+ failed: true,
55188
+ sending: true,
55189
+ };
55187
55190
  function usePrependedMessagesCount(messages, hasDateSeparator) {
55188
55191
  var firstRealMessageIndex = hasDateSeparator ? 1 : 0;
55189
- var firstMessageId = React$2.useRef();
55190
- var earliestMessageId = React$2.useRef();
55192
+ var firstMessageOnFirstLoadedPage = React$2.useRef();
55193
+ var previousFirstMessageOnFirstLoadedPage = React$2.useRef();
55191
55194
  var previousNumItemsPrepended = React$2.useRef(0);
55192
55195
  var numItemsPrepended = React$2.useMemo(function () {
55193
55196
  var _a, _b;
@@ -55195,47 +55198,43 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
55195
55198
  previousNumItemsPrepended.current = 0;
55196
55199
  return 0;
55197
55200
  }
55198
- var currentFirstMessageId = (_a = messages === null || messages === void 0 ? void 0 : messages[firstRealMessageIndex]) === null || _a === void 0 ? void 0 : _a.id;
55199
- // if no new messages were prepended, return early (same amount as before)
55200
- if (currentFirstMessageId === earliestMessageId.current) {
55201
+ var currentFirstMessage = messages === null || messages === void 0 ? void 0 : messages[firstRealMessageIndex];
55202
+ var noNewMessages = (currentFirstMessage === null || currentFirstMessage === void 0 ? void 0 : currentFirstMessage.id) === ((_a = previousFirstMessageOnFirstLoadedPage.current) === null || _a === void 0 ? void 0 : _a.id);
55203
+ // This is possible only, when sending messages very quickly (basically single char messages submitted like a crazy) in empty channel (first page)
55204
+ // Optimistic UI update, when sending messages, can lead to a situation, when
55205
+ // the order of the messages changes for a moment. This can happen, when a user
55206
+ // sends multiple messages withing few milliseconds. E.g. we send a message A
55207
+ // then message B. At first we have message array with both messages of status "sending"
55208
+ // then response for message A is received with a new - later - created_at timestamp
55209
+ // this leads to rearrangement of 1.B ("sending"), 2.A ("received"). Still firstMessageOnFirstLoadedPage.current
55210
+ // points to message A, but now this message has index 1 => previousNumItemsPrepended.current === 1
55211
+ // That in turn leads to incorrect index calculation in VirtualizedMessageList trying to access a message
55212
+ // at non-existent index. Therefore, we ignore messages of status "sending" / "failed" in order they are
55213
+ // not considered as prepended messages.
55214
+ var firstMsgMovedAfterMessagesInExcludedStatus = (currentFirstMessage === null || currentFirstMessage === void 0 ? void 0 : currentFirstMessage.status) && STATUSES_EXCLUDED_FROM_PREPEND[currentFirstMessage.status];
55215
+ if (noNewMessages || firstMsgMovedAfterMessagesInExcludedStatus) {
55201
55216
  return previousNumItemsPrepended.current;
55202
55217
  }
55203
- if (!firstMessageId.current) {
55204
- firstMessageId.current = currentFirstMessageId;
55218
+ if (!firstMessageOnFirstLoadedPage.current) {
55219
+ firstMessageOnFirstLoadedPage.current = currentFirstMessage;
55205
55220
  }
55206
- earliestMessageId.current = currentFirstMessageId;
55221
+ previousFirstMessageOnFirstLoadedPage.current = currentFirstMessage;
55207
55222
  // if new messages were prepended, find out how many
55208
55223
  // start with this number because there cannot be fewer prepended items than before
55209
- var adjustPrependedMessageCount = 0;
55210
- for (var i = previousNumItemsPrepended.current; i < messages.length; i += 1) {
55211
- // Optimistic UI update, when sending messages, can lead to a situation, when
55212
- // the order of the messages changes for a moment. This can happen, when a user
55213
- // sends multiple messages withing few milliseconds. E.g. we send a message A
55214
- // then message B. At first we have message array with both messages of status "sending"
55215
- // then response for message A is received with a new - later - created_at timestamp
55216
- // this leads to rearrangement of 1.B ("sending"), 2.A ("received"). Still firstMessageId.current
55217
- // points to message A, but now this message has index 1 => previousNumItemsPrepended.current === 1
55218
- // That in turn leads to incorrect index calculation in VirtualizedMessageList trying to access a message
55219
- // at non-existent index. Therefore, we ignore messages of status "sending" / "failed" in order they are
55220
- // not considered as prepended messages.
55221
- if (((_b = messages[i]) === null || _b === void 0 ? void 0 : _b.status) &&
55222
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
55223
- STATUSES_EXCLUDED_FROM_PREPEND.includes(messages[i].status) &&
55224
- messages[i].id !== firstMessageId.current) {
55225
- adjustPrependedMessageCount++;
55226
- }
55227
- if (messages[i].id === firstMessageId.current) {
55228
- previousNumItemsPrepended.current = i - adjustPrependedMessageCount;
55229
- return previousNumItemsPrepended.current;
55224
+ for (var prependedMessageCount = previousNumItemsPrepended.current; prependedMessageCount < messages.length; prependedMessageCount += 1) {
55225
+ var messageIsFirstOnFirstLoadedPage = messages[prependedMessageCount].id === ((_b = firstMessageOnFirstLoadedPage.current) === null || _b === void 0 ? void 0 : _b.id);
55226
+ if (messageIsFirstOnFirstLoadedPage) {
55227
+ previousNumItemsPrepended.current = prependedMessageCount;
55228
+ return prependedMessageCount;
55230
55229
  }
55231
55230
  }
55232
55231
  // if no match has found, we have jumped - reset the prepended item count.
55233
- firstMessageId.current = currentFirstMessageId;
55232
+ firstMessageOnFirstLoadedPage.current = currentFirstMessage;
55234
55233
  previousNumItemsPrepended.current = 0;
55235
55234
  return 0;
55236
55235
  // TODO: there's a bug here, the messages prop is the same array instance (something mutates it)
55237
55236
  // that's why the second dependency is necessary
55238
- }, [messages, messages === null || messages === void 0 ? void 0 : messages.length]);
55237
+ }, [firstRealMessageIndex, messages, messages === null || messages === void 0 ? void 0 : messages.length]);
55239
55238
  return numItemsPrepended;
55240
55239
  }
55241
55240