sceyt-chat-react-uikit 1.8.9-beta.17 → 1.8.9-beta.18

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.
package/index.js CHANGED
@@ -46854,6 +46854,10 @@ function useChatController(_ref5) {
46854
46854
  var highlightTimeoutRef = React.useRef(null);
46855
46855
  var unreadRestoreCompletedRef = React.useRef(false);
46856
46856
  var previousUnreadScrollToRef = React.useRef(unreadScrollTo);
46857
+ var unreadScrollToRef = React.useRef(unreadScrollTo);
46858
+ var tabIsActiveRef = React.useRef(tabIsActive);
46859
+ var hasNextMessagesRef = React.useRef(hasNextMessages);
46860
+ var needsVisibleUnreadCheckRef = React.useRef(false);
46857
46861
  var historyLoadArmedRef = React.useRef(true);
46858
46862
  var latestLoadArmedRef = React.useRef(true);
46859
46863
  var pendingNewestCountRef = React.useRef(0);
@@ -46965,6 +46969,9 @@ function useChatController(_ref5) {
46965
46969
  visibleMessagesMapRef.current = visibleMessagesMap;
46966
46970
  channelRef.current = channel;
46967
46971
  connectionStatusRef.current = connectionStatus;
46972
+ unreadScrollToRef.current = unreadScrollTo;
46973
+ tabIsActiveRef.current = tabIsActive;
46974
+ hasNextMessagesRef.current = hasNext;
46968
46975
  });
46969
46976
  var oldestConfirmedMessage = getFirstConfirmedMessage(messages);
46970
46977
  var newestConfirmedMessage = getLastConfirmedMessage(messages);
@@ -46998,6 +47005,7 @@ function useChatController(_ref5) {
46998
47005
  });
46999
47006
  }, [channel.id, messages]);
47000
47007
  var hasNext = hasNextMessages || (newestConfirmedMessage ? hasNextContiguousInMap(channel.id, newestConfirmedMessage) : false) || (newestConfirmedMessageId && (_channel$lastMessage = channel.lastMessage) !== null && _channel$lastMessage !== void 0 && _channel$lastMessage.id ? compareMessageIds(channel.lastMessage.id, newestConfirmedMessageId) > 0 : false) || hiddenPendingTailExists;
47008
+ hasNextMessagesRef.current = hasNext;
47001
47009
  var isScrollInteractionActive = React.useCallback(function () {
47002
47010
  return Date.now() - lastScrollActivityAtRef.current < SCROLL_IDLE_MS;
47003
47011
  }, []);
@@ -47102,21 +47110,32 @@ function useChatController(_ref5) {
47102
47110
  }, lockDuration);
47103
47111
  }, [clearJumpScrollingLock]);
47104
47112
  var queueVisibleUnreadCheck = React.useCallback(function () {
47105
- if (pendingVisibleUnreadFrameRef.current !== null || unreadScrollTo || !tabIsActive) {
47113
+ if (pendingVisibleUnreadFrameRef.current !== null) {
47114
+ return;
47115
+ }
47116
+ if (unreadScrollToRef.current || !tabIsActiveRef.current || connectionStatusRef.current !== CONNECTION_STATUS.CONNECTED) {
47117
+ needsVisibleUnreadCheckRef.current = true;
47106
47118
  return;
47107
47119
  }
47120
+ var scheduledChannelId = channel.id;
47108
47121
  pendingVisibleUnreadFrameRef.current = requestAnimationFrame(function () {
47109
47122
  pendingVisibleUnreadFrameRef.current = null;
47123
+ var currentChannel = channelRef.current;
47124
+ if (currentChannel.id !== scheduledChannelId || unreadScrollToRef.current || !tabIsActiveRef.current || connectionStatusRef.current !== CONNECTION_STATUS.CONNECTED) {
47125
+ needsVisibleUnreadCheckRef.current = true;
47126
+ return;
47127
+ }
47110
47128
  var container = scrollRef.current;
47111
47129
  if (!container) {
47112
47130
  return;
47113
47131
  }
47114
- var unreadStartIndex = getUnreadTrackingStartIndex(messages);
47132
+ var currentMessages = messagesRef.current;
47133
+ var unreadStartIndex = getUnreadTrackingStartIndex(currentMessages);
47115
47134
  if (unreadStartIndex < 0) {
47116
47135
  return;
47117
47136
  }
47118
- var candidateUnreadMessages = messages.slice(unreadStartIndex);
47119
- var pinnedToLatestWithoutMorePages = !hasNext && isPinnedToLatest(container);
47137
+ var candidateUnreadMessages = currentMessages.slice(unreadStartIndex);
47138
+ var pinnedToLatestWithoutMorePages = !hasNextMessagesRef.current && isPinnedToLatest(container);
47120
47139
  var containerRect = pinnedToLatestWithoutMorePages ? null : container.getBoundingClientRect();
47121
47140
  var visibleUnreadMessages = candidateUnreadMessages.map(function (message) {
47122
47141
  if (visibleUnreadReportedRef.current.has(message.id)) {
@@ -47137,16 +47156,17 @@ function useChatController(_ref5) {
47137
47156
  var ids = visibleUnreadMessages.filter(isUnreadIncomingMessage).map(function (message) {
47138
47157
  return message.id;
47139
47158
  });
47140
- if (!ids.length || !channel.id || !channel.newMessageCount) {
47159
+ if (!ids.length || !currentChannel.id || !currentChannel.newMessageCount) {
47141
47160
  return;
47142
47161
  }
47143
47162
  ids.forEach(function (id) {
47144
47163
  visibleUnreadReportedRef.current.add(id);
47145
47164
  });
47165
+ needsVisibleUnreadCheckRef.current = false;
47146
47166
  registerLocallyReadUnreadMessages(ids.length);
47147
- dispatch(markMessagesAsReadAC(channel.id, ids));
47167
+ dispatch(markMessagesAsReadAC(currentChannel.id, ids));
47148
47168
  });
47149
- }, [channel.id, channel.lastDisplayedMessageId, channel.newMessageCount, dispatch, hasNext, messages, registerLocallyReadUnreadMessages, unreadScrollTo, tabIsActive]);
47169
+ }, [channel.id, dispatch, registerLocallyReadUnreadMessages]);
47150
47170
  var timelineItems = React.useMemo(function () {
47151
47171
  var unreadStartIndex = getUnreadDividerIndex(messages, unreadMessageId);
47152
47172
  return messages.flatMap(function (message, index) {
@@ -48574,8 +48594,15 @@ function useChatController(_ref5) {
48574
48594
  if (!previousUnreadScrollTo || unreadScrollTo) {
48575
48595
  return;
48576
48596
  }
48597
+ needsVisibleUnreadCheckRef.current = true;
48577
48598
  queueVisibleUnreadCheck();
48578
48599
  }, [queueVisibleUnreadCheck, unreadScrollTo]);
48600
+ React.useEffect(function () {
48601
+ if (!needsVisibleUnreadCheckRef.current || unreadScrollTo || !tabIsActive || connectionStatus !== CONNECTION_STATUS.CONNECTED) {
48602
+ return;
48603
+ }
48604
+ queueVisibleUnreadCheck();
48605
+ }, [connectionStatus, queueVisibleUnreadCheck, tabIsActive, unreadScrollTo]);
48579
48606
  React.useEffect(function () {
48580
48607
  return function () {
48581
48608
  var _pendingWindowLoadRef3, _pendingEdgeLoadRefs$5, _pendingEdgeLoadRefs$6;
package/index.modern.js CHANGED
@@ -46834,6 +46834,10 @@ function useChatController(_ref5) {
46834
46834
  var highlightTimeoutRef = useRef(null);
46835
46835
  var unreadRestoreCompletedRef = useRef(false);
46836
46836
  var previousUnreadScrollToRef = useRef(unreadScrollTo);
46837
+ var unreadScrollToRef = useRef(unreadScrollTo);
46838
+ var tabIsActiveRef = useRef(tabIsActive);
46839
+ var hasNextMessagesRef = useRef(hasNextMessages);
46840
+ var needsVisibleUnreadCheckRef = useRef(false);
46837
46841
  var historyLoadArmedRef = useRef(true);
46838
46842
  var latestLoadArmedRef = useRef(true);
46839
46843
  var pendingNewestCountRef = useRef(0);
@@ -46945,6 +46949,9 @@ function useChatController(_ref5) {
46945
46949
  visibleMessagesMapRef.current = visibleMessagesMap;
46946
46950
  channelRef.current = channel;
46947
46951
  connectionStatusRef.current = connectionStatus;
46952
+ unreadScrollToRef.current = unreadScrollTo;
46953
+ tabIsActiveRef.current = tabIsActive;
46954
+ hasNextMessagesRef.current = hasNext;
46948
46955
  });
46949
46956
  var oldestConfirmedMessage = getFirstConfirmedMessage(messages);
46950
46957
  var newestConfirmedMessage = getLastConfirmedMessage(messages);
@@ -46978,6 +46985,7 @@ function useChatController(_ref5) {
46978
46985
  });
46979
46986
  }, [channel.id, messages]);
46980
46987
  var hasNext = hasNextMessages || (newestConfirmedMessage ? hasNextContiguousInMap(channel.id, newestConfirmedMessage) : false) || (newestConfirmedMessageId && (_channel$lastMessage = channel.lastMessage) !== null && _channel$lastMessage !== void 0 && _channel$lastMessage.id ? compareMessageIds(channel.lastMessage.id, newestConfirmedMessageId) > 0 : false) || hiddenPendingTailExists;
46988
+ hasNextMessagesRef.current = hasNext;
46981
46989
  var isScrollInteractionActive = useCallback(function () {
46982
46990
  return Date.now() - lastScrollActivityAtRef.current < SCROLL_IDLE_MS;
46983
46991
  }, []);
@@ -47082,21 +47090,32 @@ function useChatController(_ref5) {
47082
47090
  }, lockDuration);
47083
47091
  }, [clearJumpScrollingLock]);
47084
47092
  var queueVisibleUnreadCheck = useCallback(function () {
47085
- if (pendingVisibleUnreadFrameRef.current !== null || unreadScrollTo || !tabIsActive) {
47093
+ if (pendingVisibleUnreadFrameRef.current !== null) {
47094
+ return;
47095
+ }
47096
+ if (unreadScrollToRef.current || !tabIsActiveRef.current || connectionStatusRef.current !== CONNECTION_STATUS.CONNECTED) {
47097
+ needsVisibleUnreadCheckRef.current = true;
47086
47098
  return;
47087
47099
  }
47100
+ var scheduledChannelId = channel.id;
47088
47101
  pendingVisibleUnreadFrameRef.current = requestAnimationFrame(function () {
47089
47102
  pendingVisibleUnreadFrameRef.current = null;
47103
+ var currentChannel = channelRef.current;
47104
+ if (currentChannel.id !== scheduledChannelId || unreadScrollToRef.current || !tabIsActiveRef.current || connectionStatusRef.current !== CONNECTION_STATUS.CONNECTED) {
47105
+ needsVisibleUnreadCheckRef.current = true;
47106
+ return;
47107
+ }
47090
47108
  var container = scrollRef.current;
47091
47109
  if (!container) {
47092
47110
  return;
47093
47111
  }
47094
- var unreadStartIndex = getUnreadTrackingStartIndex(messages);
47112
+ var currentMessages = messagesRef.current;
47113
+ var unreadStartIndex = getUnreadTrackingStartIndex(currentMessages);
47095
47114
  if (unreadStartIndex < 0) {
47096
47115
  return;
47097
47116
  }
47098
- var candidateUnreadMessages = messages.slice(unreadStartIndex);
47099
- var pinnedToLatestWithoutMorePages = !hasNext && isPinnedToLatest(container);
47117
+ var candidateUnreadMessages = currentMessages.slice(unreadStartIndex);
47118
+ var pinnedToLatestWithoutMorePages = !hasNextMessagesRef.current && isPinnedToLatest(container);
47100
47119
  var containerRect = pinnedToLatestWithoutMorePages ? null : container.getBoundingClientRect();
47101
47120
  var visibleUnreadMessages = candidateUnreadMessages.map(function (message) {
47102
47121
  if (visibleUnreadReportedRef.current.has(message.id)) {
@@ -47117,16 +47136,17 @@ function useChatController(_ref5) {
47117
47136
  var ids = visibleUnreadMessages.filter(isUnreadIncomingMessage).map(function (message) {
47118
47137
  return message.id;
47119
47138
  });
47120
- if (!ids.length || !channel.id || !channel.newMessageCount) {
47139
+ if (!ids.length || !currentChannel.id || !currentChannel.newMessageCount) {
47121
47140
  return;
47122
47141
  }
47123
47142
  ids.forEach(function (id) {
47124
47143
  visibleUnreadReportedRef.current.add(id);
47125
47144
  });
47145
+ needsVisibleUnreadCheckRef.current = false;
47126
47146
  registerLocallyReadUnreadMessages(ids.length);
47127
- dispatch(markMessagesAsReadAC(channel.id, ids));
47147
+ dispatch(markMessagesAsReadAC(currentChannel.id, ids));
47128
47148
  });
47129
- }, [channel.id, channel.lastDisplayedMessageId, channel.newMessageCount, dispatch, hasNext, messages, registerLocallyReadUnreadMessages, unreadScrollTo, tabIsActive]);
47149
+ }, [channel.id, dispatch, registerLocallyReadUnreadMessages]);
47130
47150
  var timelineItems = useMemo(function () {
47131
47151
  var unreadStartIndex = getUnreadDividerIndex(messages, unreadMessageId);
47132
47152
  return messages.flatMap(function (message, index) {
@@ -48554,8 +48574,15 @@ function useChatController(_ref5) {
48554
48574
  if (!previousUnreadScrollTo || unreadScrollTo) {
48555
48575
  return;
48556
48576
  }
48577
+ needsVisibleUnreadCheckRef.current = true;
48557
48578
  queueVisibleUnreadCheck();
48558
48579
  }, [queueVisibleUnreadCheck, unreadScrollTo]);
48580
+ useEffect(function () {
48581
+ if (!needsVisibleUnreadCheckRef.current || unreadScrollTo || !tabIsActive || connectionStatus !== CONNECTION_STATUS.CONNECTED) {
48582
+ return;
48583
+ }
48584
+ queueVisibleUnreadCheck();
48585
+ }, [connectionStatus, queueVisibleUnreadCheck, tabIsActive, unreadScrollTo]);
48559
48586
  useEffect(function () {
48560
48587
  return function () {
48561
48588
  var _pendingWindowLoadRef3, _pendingEdgeLoadRefs$5, _pendingEdgeLoadRefs$6;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sceyt-chat-react-uikit",
3
- "version": "1.8.9-beta.17",
3
+ "version": "1.8.9-beta.18",
4
4
  "description": "Interactive React UI Components for Sceyt Chat.",
5
5
  "author": "Sceyt",
6
6
  "license": "MIT",