stream-chat-react 10.22.0 → 10.22.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.
@@ -47781,7 +47781,7 @@ var StreamChatReact = (function (exports, React$2, streamChat, ReactDOM) {
47781
47781
 
47782
47782
  window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};
47783
47783
 
47784
- window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var version$1 = '10.22.0';
47784
+ window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var version$1 = '10.22.1';
47785
47785
 
47786
47786
  window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var useChat = function (_a) {
47787
47787
  var _b, _c;
@@ -50586,11 +50586,14 @@ var StreamChatReact = (function (exports, React$2, streamChat, ReactDOM) {
50586
50586
  };
50587
50587
  }
50588
50588
 
50589
- window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var STATUSES_EXCLUDED_FROM_PREPEND = ['sending', 'failed'];
50589
+ window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var STATUSES_EXCLUDED_FROM_PREPEND = {
50590
+ failed: true,
50591
+ sending: true,
50592
+ };
50590
50593
  function usePrependedMessagesCount(messages, hasDateSeparator) {
50591
50594
  var firstRealMessageIndex = hasDateSeparator ? 1 : 0;
50592
- var firstMessageId = React$2.useRef();
50593
- var earliestMessageId = React$2.useRef();
50595
+ var firstMessageOnFirstLoadedPage = React$2.useRef();
50596
+ var previousFirstMessageOnFirstLoadedPage = React$2.useRef();
50594
50597
  var previousNumItemsPrepended = React$2.useRef(0);
50595
50598
  var numItemsPrepended = React$2.useMemo(function () {
50596
50599
  var _a, _b;
@@ -50598,47 +50601,43 @@ var StreamChatReact = (function (exports, React$2, streamChat, ReactDOM) {
50598
50601
  previousNumItemsPrepended.current = 0;
50599
50602
  return 0;
50600
50603
  }
50601
- var currentFirstMessageId = (_a = messages === null || messages === void 0 ? void 0 : messages[firstRealMessageIndex]) === null || _a === void 0 ? void 0 : _a.id;
50602
- // if no new messages were prepended, return early (same amount as before)
50603
- if (currentFirstMessageId === earliestMessageId.current) {
50604
+ var currentFirstMessage = messages === null || messages === void 0 ? void 0 : messages[firstRealMessageIndex];
50605
+ var noNewMessages = (currentFirstMessage === null || currentFirstMessage === void 0 ? void 0 : currentFirstMessage.id) === ((_a = previousFirstMessageOnFirstLoadedPage.current) === null || _a === void 0 ? void 0 : _a.id);
50606
+ // This is possible only, when sending messages very quickly (basically single char messages submitted like a crazy) in empty channel (first page)
50607
+ // Optimistic UI update, when sending messages, can lead to a situation, when
50608
+ // the order of the messages changes for a moment. This can happen, when a user
50609
+ // sends multiple messages withing few milliseconds. E.g. we send a message A
50610
+ // then message B. At first we have message array with both messages of status "sending"
50611
+ // then response for message A is received with a new - later - created_at timestamp
50612
+ // this leads to rearrangement of 1.B ("sending"), 2.A ("received"). Still firstMessageOnFirstLoadedPage.current
50613
+ // points to message A, but now this message has index 1 => previousNumItemsPrepended.current === 1
50614
+ // That in turn leads to incorrect index calculation in VirtualizedMessageList trying to access a message
50615
+ // at non-existent index. Therefore, we ignore messages of status "sending" / "failed" in order they are
50616
+ // not considered as prepended messages.
50617
+ var firstMsgMovedAfterMessagesInExcludedStatus = (currentFirstMessage === null || currentFirstMessage === void 0 ? void 0 : currentFirstMessage.status) && STATUSES_EXCLUDED_FROM_PREPEND[currentFirstMessage.status];
50618
+ if (noNewMessages || firstMsgMovedAfterMessagesInExcludedStatus) {
50604
50619
  return previousNumItemsPrepended.current;
50605
50620
  }
50606
- if (!firstMessageId.current) {
50607
- firstMessageId.current = currentFirstMessageId;
50621
+ if (!firstMessageOnFirstLoadedPage.current) {
50622
+ firstMessageOnFirstLoadedPage.current = currentFirstMessage;
50608
50623
  }
50609
- earliestMessageId.current = currentFirstMessageId;
50624
+ previousFirstMessageOnFirstLoadedPage.current = currentFirstMessage;
50610
50625
  // if new messages were prepended, find out how many
50611
50626
  // start with this number because there cannot be fewer prepended items than before
50612
- var adjustPrependedMessageCount = 0;
50613
- for (var i = previousNumItemsPrepended.current; i < messages.length; i += 1) {
50614
- // Optimistic UI update, when sending messages, can lead to a situation, when
50615
- // the order of the messages changes for a moment. This can happen, when a user
50616
- // sends multiple messages withing few milliseconds. E.g. we send a message A
50617
- // then message B. At first we have message array with both messages of status "sending"
50618
- // then response for message A is received with a new - later - created_at timestamp
50619
- // this leads to rearrangement of 1.B ("sending"), 2.A ("received"). Still firstMessageId.current
50620
- // points to message A, but now this message has index 1 => previousNumItemsPrepended.current === 1
50621
- // That in turn leads to incorrect index calculation in VirtualizedMessageList trying to access a message
50622
- // at non-existent index. Therefore, we ignore messages of status "sending" / "failed" in order they are
50623
- // not considered as prepended messages.
50624
- if (((_b = messages[i]) === null || _b === void 0 ? void 0 : _b.status) &&
50625
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
50626
- STATUSES_EXCLUDED_FROM_PREPEND.includes(messages[i].status) &&
50627
- messages[i].id !== firstMessageId.current) {
50628
- adjustPrependedMessageCount++;
50629
- }
50630
- if (messages[i].id === firstMessageId.current) {
50631
- previousNumItemsPrepended.current = i - adjustPrependedMessageCount;
50632
- return previousNumItemsPrepended.current;
50627
+ for (var prependedMessageCount = previousNumItemsPrepended.current; prependedMessageCount < messages.length; prependedMessageCount += 1) {
50628
+ var messageIsFirstOnFirstLoadedPage = messages[prependedMessageCount].id === ((_b = firstMessageOnFirstLoadedPage.current) === null || _b === void 0 ? void 0 : _b.id);
50629
+ if (messageIsFirstOnFirstLoadedPage) {
50630
+ previousNumItemsPrepended.current = prependedMessageCount;
50631
+ return prependedMessageCount;
50633
50632
  }
50634
50633
  }
50635
50634
  // if no match has found, we have jumped - reset the prepended item count.
50636
- firstMessageId.current = currentFirstMessageId;
50635
+ firstMessageOnFirstLoadedPage.current = currentFirstMessage;
50637
50636
  previousNumItemsPrepended.current = 0;
50638
50637
  return 0;
50639
50638
  // TODO: there's a bug here, the messages prop is the same array instance (something mutates it)
50640
50639
  // that's why the second dependency is necessary
50641
- }, [messages, messages === null || messages === void 0 ? void 0 : messages.length]);
50640
+ }, [firstRealMessageIndex, messages, messages === null || messages === void 0 ? void 0 : messages.length]);
50642
50641
  return numItemsPrepended;
50643
50642
  }
50644
50643