sceyt-chat-react-uikit 1.8.5-beta.1 → 1.8.5-beta.2

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.
Files changed (3) hide show
  1. package/index.js +396 -187
  2. package/index.modern.js +396 -187
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -11609,40 +11609,62 @@ var compareMessageIds = function compareMessageIds(leftId, rightId) {
11609
11609
  }
11610
11610
  return leftValue < rightValue ? -1 : 1;
11611
11611
  };
11612
- function getContiguousPrevMessages(channelId, fromMessageId, limit) {
11612
+ function getContiguousPrevMessages(channelId, fromMessage, limit) {
11613
11613
  var segments = loadedSegmentsMap[channelId] || [];
11614
- var bigFrom = BigInt(fromMessageId);
11614
+ var fromKey = getMessageSortKey(fromMessage);
11615
11615
  var seg = segments.find(function (s) {
11616
- return BigInt(s.startId) <= bigFrom && BigInt(s.endId) >= bigFrom;
11616
+ return BigInt(s.startId) <= fromKey && BigInt(s.endId) >= fromKey;
11617
11617
  });
11618
- if (!seg || BigInt(seg.startId) >= bigFrom) return [];
11618
+ if (!seg || BigInt(seg.startId) >= fromKey) return [];
11619
11619
  return Object.values(messagesMap[channelId] || {}).filter(function (msg) {
11620
- return msg.id && BigInt(msg.id) >= BigInt(seg.startId) && BigInt(msg.id) < bigFrom;
11620
+ return msg.id && BigInt(msg.id) >= BigInt(seg.startId) && BigInt(msg.id) < fromKey;
11621
11621
  }).sort(compareMessagesForList).slice(-limit);
11622
11622
  }
11623
- function getContiguousNextMessages(channelId, fromMessageId, limit) {
11623
+ function getContiguousNextMessages(channelId, fromMessage, limit, includePending) {
11624
+ if (includePending === void 0) {
11625
+ includePending = false;
11626
+ }
11624
11627
  var segments = loadedSegmentsMap[channelId] || [];
11625
- var bigFrom = BigInt(fromMessageId);
11628
+ var fromKey = getMessageSortKey(fromMessage);
11626
11629
  var seg = segments.find(function (s) {
11627
- return BigInt(s.startId) <= bigFrom && BigInt(s.endId) >= bigFrom;
11630
+ return BigInt(s.startId) <= fromKey && BigInt(s.endId) >= fromKey;
11628
11631
  });
11629
- if (!seg || BigInt(seg.endId) <= bigFrom) return [];
11630
- return Object.values(messagesMap[channelId] || {}).filter(function (msg) {
11631
- return msg.id && BigInt(msg.id) > bigFrom && BigInt(msg.id) <= BigInt(seg.endId);
11632
- }).sort(compareMessagesForList).slice(0, limit);
11632
+ var pendingMessages = Object.values(messagesMap[channelId] || {}).filter(function (msg) {
11633
+ return !msg.id && !!msg.tid;
11634
+ }).sort(compareMessagesForList);
11635
+ if (!seg) {
11636
+ if (!includePending || fromMessage.id) {
11637
+ return [];
11638
+ }
11639
+ return pendingMessages.filter(function (msg) {
11640
+ return getMessageSortKey(msg) > fromKey;
11641
+ }).slice(0, limit);
11642
+ }
11643
+ var segEnd = BigInt(seg.endId);
11644
+ var confirmedMessages = Object.values(messagesMap[channelId] || {}).filter(function (msg) {
11645
+ return msg.id && BigInt(msg.id) > fromKey && BigInt(msg.id) <= segEnd;
11646
+ });
11647
+ if (!includePending) {
11648
+ if (segEnd <= fromKey) return [];
11649
+ return confirmedMessages.sort(compareMessagesForList).slice(0, limit);
11650
+ }
11651
+ var latestSeg = segments[segments.length - 1];
11652
+ var pendingTailMessages = seg.endId === (latestSeg === null || latestSeg === void 0 ? void 0 : latestSeg.endId) ? pendingMessages : [];
11653
+ if (!confirmedMessages.length && !pendingTailMessages.length) return [];
11654
+ return [].concat(confirmedMessages, pendingTailMessages).sort(compareMessagesForList).slice(0, limit);
11633
11655
  }
11634
- function hasPrevContiguousInMap(channelId, fromMessageId) {
11656
+ function hasPrevContiguousInMap(channelId, fromMessage) {
11635
11657
  var segments = loadedSegmentsMap[channelId] || [];
11636
- var bigFrom = BigInt(fromMessageId);
11658
+ var fromKey = getMessageSortKey(fromMessage);
11637
11659
  return segments.some(function (s) {
11638
- return BigInt(s.startId) < bigFrom && BigInt(s.endId) >= bigFrom;
11660
+ return BigInt(s.startId) < fromKey && BigInt(s.endId) >= fromKey;
11639
11661
  });
11640
11662
  }
11641
- function hasNextContiguousInMap(channelId, fromMessageId) {
11663
+ function hasNextContiguousInMap(channelId, fromMessage) {
11642
11664
  var segments = loadedSegmentsMap[channelId] || [];
11643
- var bigFrom = BigInt(fromMessageId);
11665
+ var fromKey = getMessageSortKey(fromMessage);
11644
11666
  return segments.some(function (s) {
11645
- return BigInt(s.startId) <= bigFrom && BigInt(s.endId) > bigFrom;
11667
+ return BigInt(s.startId) <= fromKey && BigInt(s.endId) > fromKey;
11646
11668
  });
11647
11669
  }
11648
11670
  function getCachedNearMessages(channelId, boundaryMessageId, limit) {
@@ -11790,7 +11812,7 @@ var getFirstConfirmedMessageId = function getFirstConfirmedMessageId(messages) {
11790
11812
  var _messages$find;
11791
11813
  return ((_messages$find = messages.find(function (message) {
11792
11814
  return !!message.id;
11793
- })) === null || _messages$find === void 0 ? void 0 : _messages$find.id) || '';
11815
+ })) === null || _messages$find === void 0 ? void 0 : _messages$find.id) || undefined;
11794
11816
  };
11795
11817
  var getLastConfirmedMessageId = function getLastConfirmedMessageId(messages) {
11796
11818
  for (var index = messages.length - 1; index >= 0; index--) {
@@ -11801,6 +11823,18 @@ var getLastConfirmedMessageId = function getLastConfirmedMessageId(messages) {
11801
11823
  }
11802
11824
  return '';
11803
11825
  };
11826
+ var getFirstConfirmedMessage = function getFirstConfirmedMessage(messages) {
11827
+ return messages.find(function (m) {
11828
+ return !!m.id;
11829
+ });
11830
+ };
11831
+ var getLastConfirmedMessage = function getLastConfirmedMessage(messages) {
11832
+ for (var i = messages.length - 1; i >= 0; i--) {
11833
+ var _messages$i, _messages$i2;
11834
+ if ((_messages$i = messages[i]) !== null && _messages$i !== void 0 && _messages$i.id || (_messages$i2 = messages[i]) !== null && _messages$i2 !== void 0 && _messages$i2.tid) return messages[i];
11835
+ }
11836
+ return undefined;
11837
+ };
11804
11838
  var getClosestConfirmedMessageId = function getClosestConfirmedMessageId(messages, index, preferredDirection) {
11805
11839
  if (preferredDirection === void 0) {
11806
11840
  preferredDirection = 'nearest';
@@ -11829,6 +11863,17 @@ function getLatestMessagesFromMap(channelId, limit) {
11829
11863
  return !!m.id || m.tid;
11830
11864
  }).sort(compareMessagesForList).slice(-limit);
11831
11865
  }
11866
+ function getLatestCachedConfirmedMessageId(channelId) {
11867
+ var _loadedSegmentsMap$ch;
11868
+ var latestSegment = (_loadedSegmentsMap$ch = loadedSegmentsMap[channelId]) === null || _loadedSegmentsMap$ch === void 0 ? void 0 : _loadedSegmentsMap$ch.at(-1);
11869
+ if (latestSegment !== null && latestSegment !== void 0 && latestSegment.endId) {
11870
+ return latestSegment.endId;
11871
+ }
11872
+ var latestConfirmedMessage = Object.values(messagesMap[channelId] || {}).filter(function (message) {
11873
+ return !!message.id;
11874
+ }).sort(compareMessagesForList).at(-1);
11875
+ return (latestConfirmedMessage === null || latestConfirmedMessage === void 0 ? void 0 : latestConfirmedMessage.id) || '';
11876
+ }
11832
11877
  function setMessagesToMap(channelId, messages, firstMessageId, lastMessageId) {
11833
11878
  if (firstMessageId === void 0) {
11834
11879
  firstMessageId = '0';
@@ -15699,11 +15744,7 @@ function handleChannelMessageEvent(args, SceytChatClient) {
15699
15744
  }, shouldUpdateLastMessage && resolvedLastMessage ? {
15700
15745
  lastMessage: resolvedLastMessage
15701
15746
  } : {});
15702
- if (channel.id === activeChannelId) {
15703
- if (!store.getState().MessageReducer.messagesHasNext) {
15704
- appendMessageToLatestSegment(channel.id, message.id);
15705
- }
15706
- } else if (storedChannel !== null && storedChannel !== void 0 && (_storedChannel$lastMe7 = storedChannel.lastMessage) !== null && _storedChannel$lastMe7 !== void 0 && _storedChannel$lastMe7.id) {
15747
+ if (storedChannel !== null && storedChannel !== void 0 && (_storedChannel$lastMe7 = storedChannel.lastMessage) !== null && _storedChannel$lastMe7 !== void 0 && _storedChannel$lastMe7.id) {
15707
15748
  appendMessageToLatestSegment(channel.id, message.id, storedChannel.lastMessage.id);
15708
15749
  }
15709
15750
  _context.n = 8;
@@ -18520,6 +18561,7 @@ function markMessagesRead(action) {
18520
18561
  case 0:
18521
18562
  payload = action.payload;
18522
18563
  channelId = payload.channelId, messageIds = payload.messageIds;
18564
+ console.log(messageIds, 'messageIds');
18523
18565
  connectionStatus = store.getState().UserReducer.connectionStatus;
18524
18566
  if (!(connectionStatus !== CONNECTION_STATUS.CONNECTED)) {
18525
18567
  _context9.n = 1;
@@ -21418,6 +21460,16 @@ var addPendingMessage = function addPendingMessage(message, messageCopy, channel
21418
21460
  parentMessage: message.parentMessage
21419
21461
  });
21420
21462
  addMessageToMap(channelId, messageToAdd);
21463
+ if (getActiveChannelId() === channelId) {
21464
+ store.dispatch(updateChannelLastMessageAC(messageToAdd, {
21465
+ id: channelId
21466
+ }));
21467
+ }
21468
+ store.dispatch(updateChannelLastMessageAC(messageToAdd, {
21469
+ id: channelId
21470
+ }));
21471
+ updateChannelLastMessageOnAllChannels(channelId, messageToAdd);
21472
+ store.dispatch(addMessagesAC([messageToAdd], 'next'));
21421
21473
  };
21422
21474
  var addConfirmedMessageToCache = function addConfirmedMessageToCache(channelId, message) {
21423
21475
  addMessageToMap(channelId, message);
@@ -24175,11 +24227,15 @@ function prefetchMessages(channelId, fromMessageId, direction, pages) {
24175
24227
  _context23.n = 11;
24176
24228
  break;
24177
24229
  }
24178
- if (!hasPrevContiguousInMap(channelId, currentFromId)) {
24230
+ if (!hasPrevContiguousInMap(channelId, {
24231
+ id: currentFromId
24232
+ })) {
24179
24233
  _context23.n = 5;
24180
24234
  break;
24181
24235
  }
24182
- cached = getContiguousPrevMessages(channelId, currentFromId, LOAD_MAX_MESSAGE_COUNT_PREFETCH);
24236
+ cached = getContiguousPrevMessages(channelId, {
24237
+ id: currentFromId
24238
+ }, LOAD_MAX_MESSAGE_COUNT_PREFETCH);
24183
24239
  if (!(cached.length > 0)) {
24184
24240
  _context23.n = 5;
24185
24241
  break;
@@ -24219,11 +24275,15 @@ function prefetchMessages(channelId, fromMessageId, direction, pages) {
24219
24275
  _context23.n = 17;
24220
24276
  break;
24221
24277
  case 11:
24222
- if (!hasNextContiguousInMap(channelId, currentFromId)) {
24278
+ if (!hasNextContiguousInMap(channelId, {
24279
+ id: currentFromId
24280
+ })) {
24223
24281
  _context23.n = 12;
24224
24282
  break;
24225
24283
  }
24226
- _cached = getContiguousNextMessages(channelId, currentFromId, LOAD_MAX_MESSAGE_COUNT_PREFETCH);
24284
+ _cached = getContiguousNextMessages(channelId, {
24285
+ id: currentFromId
24286
+ }, LOAD_MAX_MESSAGE_COUNT_PREFETCH);
24227
24287
  if (!(_cached.length > 0)) {
24228
24288
  _context23.n = 12;
24229
24289
  break;
@@ -24289,7 +24349,7 @@ function prefetchMessages(channelId, fromMessageId, direction, pages) {
24289
24349
  }, _marked17$1, null, [[2, 20, 21, 22]]);
24290
24350
  }
24291
24351
  function loadMoreMessages(action) {
24292
- var acquiredLock, loadingScope, payload, limit, direction, channelId, messageId, hasNext, requestId, inFlightKey, SceytChatClient, messageQueryBuilder, messageQuery, connectionState, result, reachedLatestConfirmedEdge, nextHasPrevState, nextHasNextState, currentConfirmedMessages, prefetchKey, mapCached, aheadCached, pagesToFetch, fromId, _result$messages$, _result$messages2, nextWindowConfirmedCount, _mapCached, _reverse$find, lastConfirmedId, _aheadCached, confirmedAheadCount, hasCachedNext, canLoadServerNext, _pagesToFetch, _reverse$find2, lastAheadConfirmedId, _fromId, _result$messages$2, _result$messages3, shouldApplyVisibleResult, filteredPendingMessages, _t29;
24352
+ var acquiredLock, loadingScope, payload, limit, direction, channelId, messageId, hasNext, requestId, inFlightKey, SceytChatClient, messageQueryBuilder, messageQuery, connectionState, result, reachedLatestConfirmedEdge, nextHasPrevState, nextHasNextState, currentConfirmedMessages, prefetchKey, mapCached, aheadCached, pagesToFetch, fromId, _result$messages$, _result$messages2, nextWindowConfirmedCount, _mapCached, lastConfirmedMsg, lastConfirmedId, _aheadCached, confirmedAheadCount, hasCachedNext, canLoadServerNext, _pagesToFetch, _reverse$find, lastAheadConfirmedId, _fromId, _result$messages$2, _result$messages3, shouldApplyVisibleResult, filteredPendingMessages, _t29;
24293
24353
  return _regenerator().w(function (_context24) {
24294
24354
  while (1) switch (_context24.p = _context24.n) {
24295
24355
  case 0:
@@ -24333,7 +24393,9 @@ function loadMoreMessages(action) {
24333
24393
  _context24.n = 14;
24334
24394
  break;
24335
24395
  }
24336
- mapCached = getContiguousPrevMessages(channelId, messageId, limit || 30);
24396
+ mapCached = getContiguousPrevMessages(channelId, {
24397
+ id: messageId
24398
+ }, limit || 30);
24337
24399
  if (!(!mapCached.length && hasNext && prefetchInFlight.has(prefetchKey))) {
24338
24400
  _context24.n = 6;
24339
24401
  break;
@@ -24341,14 +24403,16 @@ function loadMoreMessages(action) {
24341
24403
  _context24.n = 5;
24342
24404
  return effects.call(waitForPrefetchCompletion, prefetchKey);
24343
24405
  case 5:
24344
- mapCached = getContiguousPrevMessages(channelId, messageId, limit || 30);
24406
+ mapCached = getContiguousPrevMessages(channelId, {
24407
+ id: messageId
24408
+ }, limit || 30);
24345
24409
  case 6:
24346
24410
  if (!(mapCached.length > 0)) {
24347
24411
  _context24.n = 8;
24348
24412
  break;
24349
24413
  }
24350
24414
  result.messages = mapCached;
24351
- aheadCached = getContiguousPrevMessages(channelId, mapCached[0].id, LOAD_MAX_MESSAGE_COUNT_PREFETCH * 2);
24415
+ aheadCached = getContiguousPrevMessages(channelId, mapCached[0], LOAD_MAX_MESSAGE_COUNT_PREFETCH * 2);
24352
24416
  nextHasPrevState = aheadCached.length > 0 || hasNext;
24353
24417
  pagesToFetch = 2 - Math.floor(aheadCached.length / LOAD_MAX_MESSAGE_COUNT_PREFETCH);
24354
24418
  if (!(pagesToFetch > 0 && hasNext)) {
@@ -24387,7 +24451,9 @@ function loadMoreMessages(action) {
24387
24451
  _context24.n = 11;
24388
24452
  return effects.spawn(prefetchMessages, channelId, result.messages[0].id, MESSAGE_LOAD_DIRECTION.PREV, 2);
24389
24453
  case 11:
24390
- result.messages = getContiguousPrevMessages(channelId, messageId, limit || 30);
24454
+ result.messages = getContiguousPrevMessages(channelId, {
24455
+ id: messageId
24456
+ }, limit || 30);
24391
24457
  case 12:
24392
24458
  nextHasPrevState = result.hasNext;
24393
24459
  case 13:
@@ -24400,7 +24466,9 @@ function loadMoreMessages(action) {
24400
24466
  _context24.n = 25;
24401
24467
  break;
24402
24468
  case 14:
24403
- _mapCached = getContiguousNextMessages(channelId, messageId, limit || 30);
24469
+ _mapCached = getContiguousNextMessages(channelId, {
24470
+ id: messageId
24471
+ }, limit || 30);
24404
24472
  if (!(!_mapCached.length && hasNext && prefetchInFlight.has(prefetchKey))) {
24405
24473
  _context24.n = 16;
24406
24474
  break;
@@ -24408,17 +24476,20 @@ function loadMoreMessages(action) {
24408
24476
  _context24.n = 15;
24409
24477
  return effects.call(waitForPrefetchCompletion, prefetchKey);
24410
24478
  case 15:
24411
- _mapCached = getContiguousNextMessages(channelId, messageId, limit || 30);
24479
+ _mapCached = getContiguousNextMessages(channelId, {
24480
+ id: messageId
24481
+ }, limit || 30);
24412
24482
  case 16:
24413
24483
  if (!(_mapCached.length > 0)) {
24414
24484
  _context24.n = 18;
24415
24485
  break;
24416
24486
  }
24417
24487
  result.messages = _mapCached;
24418
- lastConfirmedId = (_reverse$find = [].concat(_mapCached).reverse().find(function (m) {
24488
+ lastConfirmedMsg = [].concat(_mapCached).reverse().find(function (m) {
24419
24489
  return !!m.id;
24420
- })) === null || _reverse$find === void 0 ? void 0 : _reverse$find.id;
24421
- _aheadCached = lastConfirmedId ? getContiguousNextMessages(channelId, lastConfirmedId, LOAD_MAX_MESSAGE_COUNT_PREFETCH * 2) : [];
24490
+ });
24491
+ lastConfirmedId = lastConfirmedMsg === null || lastConfirmedMsg === void 0 ? void 0 : lastConfirmedMsg.id;
24492
+ _aheadCached = lastConfirmedMsg ? getContiguousNextMessages(channelId, lastConfirmedMsg, LOAD_MAX_MESSAGE_COUNT_PREFETCH * 2) : [];
24422
24493
  confirmedAheadCount = _aheadCached.filter(function (m) {
24423
24494
  return !!m.id;
24424
24495
  }).length;
@@ -24431,9 +24502,9 @@ function loadMoreMessages(action) {
24431
24502
  _context24.n = 17;
24432
24503
  break;
24433
24504
  }
24434
- lastAheadConfirmedId = (_reverse$find2 = [].concat(_aheadCached).reverse().find(function (m) {
24505
+ lastAheadConfirmedId = (_reverse$find = [].concat(_aheadCached).reverse().find(function (m) {
24435
24506
  return !!m.id;
24436
- })) === null || _reverse$find2 === void 0 ? void 0 : _reverse$find2.id;
24507
+ })) === null || _reverse$find === void 0 ? void 0 : _reverse$find.id;
24437
24508
  _fromId = lastAheadConfirmedId || lastConfirmedId;
24438
24509
  if (!_fromId) {
24439
24510
  _context24.n = 17;
@@ -24471,7 +24542,9 @@ function loadMoreMessages(action) {
24471
24542
  _context24.n = 21;
24472
24543
  return effects.spawn(prefetchMessages, channelId, result.messages[result.messages.length - 1].id, MESSAGE_LOAD_DIRECTION.NEXT, 2);
24473
24544
  case 21:
24474
- result.messages = getContiguousNextMessages(channelId, messageId, limit || 30);
24545
+ result.messages = getContiguousNextMessages(channelId, {
24546
+ id: messageId
24547
+ }, limit || 30);
24475
24548
  case 22:
24476
24549
  reachedLatestConfirmedEdge = !result.hasNext;
24477
24550
  nextHasNextState = result.hasNext;
@@ -41857,7 +41930,6 @@ var Message$1 = function Message(_ref) {
41857
41930
  setReactionsAnchorBottom = stateSetters.setReactionsAnchorBottom,
41858
41931
  setReportPopupOpen = stateSetters.setReportPopupOpen;
41859
41932
  var scrollToNewMessage = useSelector(scrollToNewMessageSelector, reactRedux.shallowEqual);
41860
- var unreadScrollTo = useSelector(unreadScrollToSelector, reactRedux.shallowEqual);
41861
41933
  var messageItemRef = React.useRef(null);
41862
41934
  var isVisible = useOnScreen(messageItemRef);
41863
41935
  var reactionsCount = React.useMemo(function () {
@@ -41879,7 +41951,7 @@ var Message$1 = function Message(_ref) {
41879
41951
  var nextMessageFirstInInterval = !nextMessage || nextDay !== null && nextDay.diff(current, 'days') !== 0 || nextMessage.type === exports.MESSAGE_TYPE.SYSTEM || nextMessageStartsUnreadSection;
41880
41952
  var messageTimeVisible = showMessageTime && (showMessageTimeForEachMessage || !nextMessage);
41881
41953
  var messageStatusVisible = !message.incoming && showMessageStatus && message.state !== MESSAGE_STATUS.DELETE && (showMessageStatusForEachMessage || !nextMessage);
41882
- var renderAvatar = prevMessageUserID && (prevMessageUserID !== messageUserID || firstMessageInInterval) && !(channel.type === DEFAULT_CHANNEL_TYPE.DIRECT && !showSenderNameOnDirectChannel) && !(!message.incoming && !showOwnAvatar);
41954
+ var renderAvatar = !!prevMessageUserID && (prevMessageUserID !== messageUserID || firstMessageInInterval) && !(channel.type === DEFAULT_CHANNEL_TYPE.DIRECT && !showSenderNameOnDirectChannel) && !(!message.incoming && !showOwnAvatar);
41883
41955
  var selectionIsActive = selectedMessagesMap && selectedMessagesMap.size > 0;
41884
41956
  var isSelectedMessage = selectedMessagesMap && selectedMessagesMap.get(message.id || message.tid);
41885
41957
  var tooManySelected = selectedMessagesMap && selectedMessagesMap.size >= MAX_SELECTED_MESSAGES;
@@ -42048,7 +42120,7 @@ var Message$1 = function Message(_ref) {
42048
42120
  })) {
42049
42121
  if (message.userMarkers && message.userMarkers.length && message.userMarkers.find(function (marker) {
42050
42122
  return marker.name === MESSAGE_DELIVERY_STATUS.READ;
42051
- }) && !unreadScrollTo) {
42123
+ })) {
42052
42124
  if (queueDeliveredMarker) {
42053
42125
  queueDeliveredMarker(channel.id, message.id);
42054
42126
  } else {
@@ -42058,14 +42130,14 @@ var Message$1 = function Message(_ref) {
42058
42130
  }
42059
42131
  if (isVisible && message.incoming && !(message.userMarkers && message.userMarkers.length && message.userMarkers.find(function (marker) {
42060
42132
  return marker.name === MESSAGE_DELIVERY_STATUS.READ;
42061
- })) && channel.newMessageCount && channel.newMessageCount > 0 && connectionStatus === CONNECTION_STATUS.CONNECTED && !unreadScrollTo) {
42133
+ })) && channel.newMessageCount && channel.newMessageCount > 0 && connectionStatus === CONNECTION_STATUS.CONNECTED) {
42062
42134
  if (queueReadMarker) {
42063
42135
  queueReadMarker(channel.id, message.id);
42064
42136
  } else {
42065
42137
  dispatch(markMessagesAsReadAC(channel.id, [message.id]));
42066
42138
  }
42067
42139
  }
42068
- }, [dispatch, message.incoming, message.userMarkers, message.id, isVisible, channel.id, channel.newMessageCount, connectionStatus, unreadScrollTo, queueReadMarker, queueDeliveredMarker]);
42140
+ }, [dispatch, message.incoming, message.userMarkers, message.id, isVisible, channel.id, channel.newMessageCount, connectionStatus, queueReadMarker, queueDeliveredMarker]);
42069
42141
  var handleForwardMessage = React.useCallback(function (channelIds) {
42070
42142
  if (channelIds && channelIds.length) {
42071
42143
  channelIds.forEach(function (channelId) {
@@ -42103,7 +42175,7 @@ var Message$1 = function Message(_ref) {
42103
42175
  }
42104
42176
  }, [dispatch, selectionIsActive]);
42105
42177
  React.useEffect(function () {
42106
- if (isVisible && !unreadScrollTo) {
42178
+ if (isVisible) {
42107
42179
  if (setLastVisibleMessageId) {
42108
42180
  setLastVisibleMessageId(message);
42109
42181
  }
@@ -42121,7 +42193,7 @@ var Message$1 = function Message(_ref) {
42121
42193
  removeMessageFromVisibleMessagesMap(message);
42122
42194
  }
42123
42195
  }
42124
- }, [isVisible, unreadScrollTo, setLastVisibleMessageId, message.id, handleSendReadMarker, disableAutoReadTracking, channel.isLinkedChannel, channel.lastMessage, scrollToNewMessage.scrollToBottom, dispatch, message]);
42196
+ }, [isVisible, setLastVisibleMessageId, message.id, handleSendReadMarker, disableAutoReadTracking, channel.isLinkedChannel, channel.lastMessage, scrollToNewMessage.scrollToBottom, dispatch, message]);
42125
42197
  React.useEffect(function () {
42126
42198
  if (!isVisible && infoPopupOpen) {
42127
42199
  setInfoPopupOpen(false);
@@ -42717,6 +42789,7 @@ var getUnreadTrackingStartIndex = function getUnreadTrackingStartIndex(messages)
42717
42789
  return messages.findIndex(isUnreadIncomingMessage);
42718
42790
  };
42719
42791
  function useChatController(_ref3) {
42792
+ var _channel$lastMessage;
42720
42793
  var messages = _ref3.messages,
42721
42794
  channel = _ref3.channel,
42722
42795
  hasPrevMessages = _ref3.hasPrevMessages,
@@ -42785,6 +42858,7 @@ function useChatController(_ref3) {
42785
42858
  var jumpToLatestFrameRef = React.useRef(null);
42786
42859
  var loadPrevFrameRef = React.useRef(null);
42787
42860
  var loadNextFrameRef = React.useRef(null);
42861
+ var pendingLatestJumpRef = React.useRef(null);
42788
42862
  var _useState = React.useState(false),
42789
42863
  isLoadingPrevious = _useState[0],
42790
42864
  setIsLoadingPrevious = _useState[1];
@@ -42866,10 +42940,23 @@ function useChatController(_ref3) {
42866
42940
  channelRef.current = channel;
42867
42941
  connectionStatusRef.current = connectionStatus;
42868
42942
  });
42869
- var oldestConfirmedMessageId = getFirstConfirmedMessageId(messages);
42943
+ var oldestConfirmedMessage = getFirstConfirmedMessage(messages);
42944
+ var newestConfirmedMessage = getLastConfirmedMessage(messages);
42870
42945
  var newestConfirmedMessageId = getLastConfirmedMessageId(messages);
42871
- var hasPrevious = hasPrevMessages || (oldestConfirmedMessageId ? hasPrevContiguousInMap(channel.id, oldestConfirmedMessageId) : false);
42872
- var hasNext = hasNextMessages || (newestConfirmedMessageId ? hasNextContiguousInMap(channel.id, newestConfirmedMessageId) : false);
42946
+ var hasPrevious = hasPrevMessages || (oldestConfirmedMessage ? hasPrevContiguousInMap(channel.id, oldestConfirmedMessage) : false);
42947
+ var hiddenPendingTailExists = React.useMemo(function () {
42948
+ var pendingMessages = getPendingMessagesFromMap(channel.id);
42949
+ if (!pendingMessages.length) {
42950
+ return false;
42951
+ }
42952
+ var visibleMessageRefs = new Set(messages.map(function (message) {
42953
+ return getMessageLocalRef(message);
42954
+ }).filter(Boolean));
42955
+ return pendingMessages.some(function (message) {
42956
+ return !visibleMessageRefs.has(getMessageLocalRef(message));
42957
+ });
42958
+ }, [channel.id, messages]);
42959
+ 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;
42873
42960
  var isScrollInteractionActive = React.useCallback(function () {
42874
42961
  return Date.now() - lastScrollActivityAtRef.current < SCROLL_IDLE_MS;
42875
42962
  }, []);
@@ -42919,6 +43006,9 @@ function useChatController(_ref3) {
42919
43006
  isJumping.current = false;
42920
43007
  setIsJumpingToItem(false);
42921
43008
  }, []);
43009
+ var clearPendingLatestJump = React.useCallback(function () {
43010
+ pendingLatestJumpRef.current = null;
43011
+ }, []);
42922
43012
  var clearJumpScrollingLock = React.useCallback(function () {
42923
43013
  jumpLockUntilRef.current = 0;
42924
43014
  jumpLockModeRef.current = null;
@@ -43085,7 +43175,10 @@ function useChatController(_ref3) {
43085
43175
  request.hasSeenLoading = true;
43086
43176
  return;
43087
43177
  }
43088
- if (!request.hasSeenLoading || !isViewportLoadSettled(windowLoadScopeRef.current)) {
43178
+ var hasMessageSetChanged = request.previousIds.size !== messages.length || messages.some(function (message) {
43179
+ return !request.previousIds.has(getMessageLocalRef(message));
43180
+ });
43181
+ if (!request.hasSeenLoading && !(request.allowNoLoading && hasMessageSetChanged) || !isViewportLoadSettled(windowLoadScopeRef.current)) {
43089
43182
  return;
43090
43183
  }
43091
43184
  pendingWindowLoadRef.current = null;
@@ -43122,14 +43215,15 @@ function useChatController(_ref3) {
43122
43215
  resolvePendingEdgeLoad('previous');
43123
43216
  resolvePendingEdgeLoad('next');
43124
43217
  }, [resolvePendingEdgeLoad, resolvePendingWindowLoad]);
43125
- var beginWindowPagedRequest = React.useCallback(function (dispatchAction) {
43218
+ var beginWindowPagedRequest = React.useCallback(function (dispatchAction, options) {
43126
43219
  return new Promise(function (resolve) {
43127
43220
  pendingWindowLoadRef.current = {
43128
43221
  previousIds: new Set(messagesRef.current.map(function (message) {
43129
43222
  return getMessageLocalRef(message);
43130
43223
  })),
43131
43224
  resolve: resolve,
43132
- hasSeenLoading: false
43225
+ hasSeenLoading: false,
43226
+ allowNoLoading: !!(options !== null && options !== void 0 && options.allowNoLoading)
43133
43227
  };
43134
43228
  suppressNextMessageChange();
43135
43229
  dispatchAction();
@@ -43142,7 +43236,8 @@ function useChatController(_ref3) {
43142
43236
  return getMessageLocalRef(message);
43143
43237
  })),
43144
43238
  resolve: resolve,
43145
- hasSeenLoading: false
43239
+ hasSeenLoading: false,
43240
+ allowNoLoading: false
43146
43241
  };
43147
43242
  suppressNextMessageChange();
43148
43243
  dispatchAction();
@@ -43153,16 +43248,7 @@ function useChatController(_ref3) {
43153
43248
  smooth = true;
43154
43249
  }
43155
43250
  try {
43156
- var _temp2 = function _temp2(_result) {
43157
- if (_exit) return _result;
43158
- if (!container) {
43159
- return;
43160
- }
43161
- syncLatestState();
43162
- scrollToLatestEdge(container, smooth ? 'smooth' : 'auto');
43163
- dispatch(showScrollToNewMessageButtonAC(false));
43164
- };
43165
- var _exit = false;
43251
+ var _channelRef$current, _pendingLatestJumpRef, _pendingLatestJumpRef2, _channelRef$current2, _channelRef$current2$;
43166
43252
  isJumping.current = true;
43167
43253
  lockJumpScrolling(smooth, 'latest');
43168
43254
  invalidateEdgeDirection('previous');
@@ -43171,50 +43257,76 @@ function useChatController(_ref3) {
43171
43257
  pendingNewestCountRef.current = 0;
43172
43258
  setPendingNewestCount(0);
43173
43259
  var container = scrollRef.current;
43174
- if (container) {
43260
+ var currentChannelId = (_channelRef$current = channelRef.current) === null || _channelRef$current === void 0 ? void 0 : _channelRef$current.id;
43261
+ var pendingLatestServerSync = ((_pendingLatestJumpRef = pendingLatestJumpRef.current) === null || _pendingLatestJumpRef === void 0 ? void 0 : _pendingLatestJumpRef.channelId) === currentChannelId && ((_pendingLatestJumpRef2 = pendingLatestJumpRef.current) === null || _pendingLatestJumpRef2 === void 0 ? void 0 : _pendingLatestJumpRef2.needsServerSync);
43262
+ if (!currentChannelId) {
43263
+ clearPendingLatestJump();
43264
+ if (!container) {
43265
+ return Promise.resolve();
43266
+ }
43175
43267
  viewIsAtLatestRef.current = true;
43176
43268
  setIsViewingLatest(true);
43177
43269
  scrollToLatestEdge(container, smooth ? 'smooth' : 'auto');
43270
+ dispatch(showScrollToNewMessageButtonAC(false));
43271
+ return Promise.resolve();
43178
43272
  }
43179
- var _temp = function (_channelRef$current) {
43180
- if ((_channelRef$current = channelRef.current) !== null && _channelRef$current !== void 0 && _channelRef$current.id) {
43181
- suppressNextMessageChange();
43182
- return Promise.resolve(beginWindowPagedRequest(function () {
43183
- if (connectionStatus === CONNECTION_STATUS.CONNECTED) {
43184
- dispatch(loadLatestMessagesAC(channelRef.current));
43185
- } else {
43186
- dispatch(loadDefaultMessagesAC(channelRef.current));
43187
- }
43188
- })).then(function () {
43189
- dispatch(showScrollToNewMessageButtonAC(false));
43190
- var latestContainer = scrollRef.current;
43191
- if (!latestContainer) {
43192
- _exit = true;
43193
- return;
43194
- }
43195
- viewIsAtLatestRef.current = true;
43196
- setIsViewingLatest(true);
43197
- if (jumpToLatestFrameRef.current !== null) {
43198
- cancelAnimationFrame(jumpToLatestFrameRef.current);
43199
- }
43200
- jumpToLatestFrameRef.current = requestAnimationFrame(function () {
43201
- jumpToLatestFrameRef.current = null;
43202
- var renderedContainer = scrollRef.current;
43203
- if (!renderedContainer) {
43204
- return;
43205
- }
43206
- scrollToLatestEdge(renderedContainer, smooth ? 'smooth' : 'auto');
43207
- });
43208
- dispatch(showScrollToNewMessageButtonAC(false));
43209
- _exit = true;
43210
- });
43273
+ var cachedLatestConfirmedMessageId = getLatestCachedConfirmedMessageId(currentChannelId);
43274
+ var currentLatestMessageId = ((_channelRef$current2 = channelRef.current) === null || _channelRef$current2 === void 0 ? void 0 : (_channelRef$current2$ = _channelRef$current2.lastMessage) === null || _channelRef$current2$ === void 0 ? void 0 : _channelRef$current2$.id) || '';
43275
+ var needsServerSync = !!currentLatestMessageId && (!cachedLatestConfirmedMessageId || compareMessageIds(cachedLatestConfirmedMessageId, currentLatestMessageId) < 0);
43276
+ if (!hasNext && container && !pendingLatestServerSync) {
43277
+ clearPendingLatestJump();
43278
+ viewIsAtLatestRef.current = true;
43279
+ setIsViewingLatest(true);
43280
+ scrollToLatestEdge(container, smooth ? 'smooth' : 'auto');
43281
+ dispatch(showScrollToNewMessageButtonAC(false));
43282
+ return Promise.resolve();
43283
+ }
43284
+ if (connectionStatus === CONNECTION_STATUS.CONNECTED) {
43285
+ clearPendingLatestJump();
43286
+ } else {
43287
+ pendingLatestJumpRef.current = {
43288
+ channelId: currentChannelId,
43289
+ smooth: smooth,
43290
+ needsServerSync: needsServerSync
43291
+ };
43292
+ }
43293
+ restoreRef.current = smooth ? {
43294
+ mode: 'to-bottom-smooth'
43295
+ } : {
43296
+ mode: 'to-bottom'
43297
+ };
43298
+ return Promise.resolve(beginWindowPagedRequest(function () {
43299
+ if (connectionStatus === CONNECTION_STATUS.CONNECTED) {
43300
+ dispatch(loadLatestMessagesAC(channelRef.current));
43301
+ return;
43211
43302
  }
43212
- }();
43213
- return Promise.resolve(_temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp));
43303
+ dispatch(loadDefaultMessagesAC(channelRef.current));
43304
+ }, {
43305
+ allowNoLoading: connectionStatus !== CONNECTION_STATUS.CONNECTED
43306
+ })).then(function () {
43307
+ dispatch(showScrollToNewMessageButtonAC(false));
43308
+ var latestContainer = scrollRef.current;
43309
+ if (!latestContainer) {
43310
+ return;
43311
+ }
43312
+ viewIsAtLatestRef.current = true;
43313
+ setIsViewingLatest(true);
43314
+ if (jumpToLatestFrameRef.current !== null) {
43315
+ cancelAnimationFrame(jumpToLatestFrameRef.current);
43316
+ }
43317
+ jumpToLatestFrameRef.current = requestAnimationFrame(function () {
43318
+ jumpToLatestFrameRef.current = null;
43319
+ var renderedContainer = scrollRef.current;
43320
+ if (!renderedContainer) {
43321
+ return;
43322
+ }
43323
+ scrollToLatestEdge(renderedContainer, smooth ? 'smooth' : 'auto');
43324
+ });
43325
+ });
43214
43326
  } catch (e) {
43215
43327
  return Promise.reject(e);
43216
43328
  }
43217
- }, [beginWindowPagedRequest, connectionStatus, dispatch, hasNext, invalidateEdgeDirection, lockJumpScrolling, suppressNextMessageChange, syncLatestState]);
43329
+ }, [beginWindowPagedRequest, clearPendingLatestJump, connectionStatus, dispatch, hasNext, invalidateEdgeDirection, lockJumpScrolling, suppressNextMessageChange]);
43218
43330
  var jumpToItem = React.useCallback(function (itemId, smooth) {
43219
43331
  if (smooth === void 0) {
43220
43332
  smooth = true;
@@ -43229,66 +43341,74 @@ function useChatController(_ref3) {
43229
43341
  pendingWindowLoadRef.current = null;
43230
43342
  clearJumpBlur();
43231
43343
  }
43232
- var jumpId = ++currentJumpIdRef.current;
43233
- isJumping.current = true;
43234
- invalidateEdgeDirection('previous');
43235
- invalidateEdgeDirection('next');
43236
43344
  var length = (_messagesRef$current = messagesRef.current) === null || _messagesRef$current === void 0 ? void 0 : _messagesRef$current.length;
43237
43345
  var isLoaded = messagesRef.current.some(function (message, index) {
43238
43346
  return index < length - 10 && index > 10 && getMessageLocalRef(message) === itemId;
43239
43347
  });
43240
- restoreRef.current = {
43241
- mode: 'reveal-message',
43242
- messageId: itemId,
43243
- smooth: smooth
43244
- };
43245
- if (isLoaded) {
43246
- var container = scrollRef.current;
43247
- var target = container ? getItemElement(container, itemId) : null;
43248
- if (container && target) {
43249
- lockJumpScrolling(smooth, 'item');
43250
- restoreRef.current = null;
43251
- viewIsAtLatestRef.current = false;
43252
- setIsViewingLatest(false);
43253
- scrollItemIntoView(container, target, smooth, true);
43254
- clearJumpBlur();
43255
- }
43256
- setHighlight(itemId);
43257
- return Promise.resolve();
43258
- }
43259
- if (!channelRef.current.id) {
43260
- return Promise.resolve();
43261
- }
43262
- windowLoadScopeRef.current = 'around';
43263
- setIsLoadingPrevious(true);
43264
- setIsLoadingNext(true);
43265
- jumpTargetIdRef.current = itemId;
43266
- setIsJumpingToItem(true);
43267
- return Promise.resolve(_finallyRethrows(function () {
43268
- return Promise.resolve(beginWindowPagedRequest(function () {
43269
- dispatch(loadAroundMessageAC(channelRef.current, itemId));
43270
- })).then(function () {
43271
- if (jumpId !== currentJumpIdRef.current) {
43272
- clearJumpBlur();
43273
- return;
43348
+ setTimeout(function () {
43349
+ try {
43350
+ clearPendingLatestJump();
43351
+ var jumpId = ++currentJumpIdRef.current;
43352
+ isJumping.current = true;
43353
+ invalidateEdgeDirection('previous');
43354
+ invalidateEdgeDirection('next');
43355
+ restoreRef.current = {
43356
+ mode: 'reveal-message',
43357
+ messageId: itemId,
43358
+ smooth: smooth
43359
+ };
43360
+ if (isLoaded) {
43361
+ var container = scrollRef.current;
43362
+ var target = container ? getItemElement(container, itemId) : null;
43363
+ if (container && target) {
43364
+ lockJumpScrolling(smooth, 'item');
43365
+ restoreRef.current = null;
43366
+ viewIsAtLatestRef.current = false;
43367
+ setIsViewingLatest(false);
43368
+ scrollItemIntoView(container, target, smooth, true);
43369
+ clearJumpBlur();
43370
+ }
43371
+ setHighlight(itemId);
43372
+ return Promise.resolve();
43274
43373
  }
43275
- windowLoadScopeRef.current = null;
43276
- setHighlight(itemId);
43277
- });
43278
- }, function (_wasThrown, _result2) {
43279
- if (jumpId === currentJumpIdRef.current) {
43280
- lockJumpScrolling(smooth, 'item');
43281
- windowLoadScopeRef.current = null;
43282
- setIsLoadingPrevious(false);
43283
- setIsLoadingNext(false);
43284
- }
43285
- if (_wasThrown) throw _result2;
43286
- return _result2;
43287
- }));
43374
+ if (!channelRef.current.id) {
43375
+ return Promise.resolve();
43376
+ }
43377
+ windowLoadScopeRef.current = 'around';
43378
+ setIsLoadingPrevious(true);
43379
+ setIsLoadingNext(true);
43380
+ jumpTargetIdRef.current = itemId;
43381
+ setIsJumpingToItem(true);
43382
+ return Promise.resolve(_finallyRethrows(function () {
43383
+ return Promise.resolve(beginWindowPagedRequest(function () {
43384
+ dispatch(loadAroundMessageAC(channelRef.current, itemId));
43385
+ })).then(function () {
43386
+ if (jumpId !== currentJumpIdRef.current) {
43387
+ clearJumpBlur();
43388
+ return;
43389
+ }
43390
+ windowLoadScopeRef.current = null;
43391
+ setHighlight(itemId);
43392
+ });
43393
+ }, function (_wasThrown, _result) {
43394
+ if (jumpId === currentJumpIdRef.current) {
43395
+ lockJumpScrolling(smooth, 'item');
43396
+ windowLoadScopeRef.current = null;
43397
+ setIsLoadingPrevious(false);
43398
+ setIsLoadingNext(false);
43399
+ }
43400
+ if (_wasThrown) throw _result;
43401
+ return _result;
43402
+ }));
43403
+ } catch (e) {
43404
+ return Promise.reject(e);
43405
+ }
43406
+ }, isLoaded ? 0 : 50);
43407
+ return Promise.resolve();
43288
43408
  } catch (e) {
43289
43409
  return Promise.reject(e);
43290
43410
  }
43291
- }, [beginWindowPagedRequest, clearJumpBlur, dispatch, invalidateEdgeDirection, lockJumpScrolling, setHighlight]);
43411
+ }, [beginWindowPagedRequest, clearJumpBlur, clearPendingLatestJump, dispatch, invalidateEdgeDirection, lockJumpScrolling, setHighlight]);
43292
43412
  var notifyIncomingItems = React.useCallback(function (incomingItems) {
43293
43413
  var nextIsViewingLatest = !hasNext && isPinnedToLatest(scrollRef.current);
43294
43414
  viewIsAtLatestRef.current = nextIsViewingLatest;
@@ -43315,7 +43435,7 @@ function useChatController(_ref3) {
43315
43435
  }, [hasNext]);
43316
43436
  var loadPrevious = React.useCallback(function (beforeId, requestId) {
43317
43437
  try {
43318
- if (!channel.id || scrollToMentionedMessage || scrollToNewMessage.scrollToBottom || isPreviousLoading) {
43438
+ if (!channel.id || scrollToMentionedMessage || scrollToNewMessage.scrollToBottom || isPreviousLoading || connectionStatus !== CONNECTION_STATUS.CONNECTED) {
43319
43439
  return Promise.resolve({
43320
43440
  items: []
43321
43441
  });
@@ -43327,33 +43447,72 @@ function useChatController(_ref3) {
43327
43447
  } catch (e) {
43328
43448
  return Promise.reject(e);
43329
43449
  }
43330
- }, [beginEdgePagedRequest, channel.id, dispatch, hasPrevMessages, isPreviousLoading, scrollToMentionedMessage, scrollToNewMessage.scrollToBottom]);
43450
+ }, [beginEdgePagedRequest, channel.id, connectionStatus, dispatch, hasPrevMessages, isPreviousLoading, scrollToMentionedMessage, scrollToNewMessage.scrollToBottom]);
43331
43451
  var loadNext = React.useCallback(function (afterId, requestId) {
43332
43452
  try {
43333
- if (!channel.id || scrollToMentionedMessage || scrollToNewMessage.scrollToBottom || isNextLoading) {
43453
+ if (!channel.id || scrollToMentionedMessage || scrollToNewMessage.scrollToBottom || isNextLoading || connectionStatus !== CONNECTION_STATUS.CONNECTED) {
43334
43454
  return Promise.resolve({
43335
43455
  items: []
43336
43456
  });
43337
43457
  }
43338
43458
  dispatch(setActivePaginationIntentAC(channel.id, 'next', requestId, afterId));
43339
43459
  return Promise.resolve(beginEdgePagedRequest('next', function () {
43340
- dispatch(loadMoreMessagesAC(channel.id, LOAD_MAX_MESSAGE_COUNT, MESSAGE_LOAD_DIRECTION.NEXT, afterId, hasNextMessages, requestId));
43460
+ var _channelRef$current3, _channelRef$current3$;
43461
+ var channelLastMsgId = (_channelRef$current3 = channelRef.current) === null || _channelRef$current3 === void 0 ? void 0 : (_channelRef$current3$ = _channelRef$current3.lastMessage) === null || _channelRef$current3$ === void 0 ? void 0 : _channelRef$current3$.id;
43462
+ var effectiveHasNext = hasNextMessages || !!channelLastMsgId && compareMessageIds(channelLastMsgId, afterId) > 0;
43463
+ dispatch(loadMoreMessagesAC(channel.id, LOAD_MAX_MESSAGE_COUNT, MESSAGE_LOAD_DIRECTION.NEXT, afterId, effectiveHasNext, requestId));
43341
43464
  }));
43342
43465
  } catch (e) {
43343
43466
  return Promise.reject(e);
43344
43467
  }
43345
- }, [beginEdgePagedRequest, channel.id, dispatch, hasNextMessages, isNextLoading, scrollToMentionedMessage, scrollToNewMessage.scrollToBottom]);
43468
+ }, [beginEdgePagedRequest, channel.id, connectionStatus, dispatch, hasNextMessages, isNextLoading, scrollToMentionedMessage, scrollToNewMessage.scrollToBottom]);
43346
43469
  var loadPreviousItems = React.useCallback(function () {
43347
43470
  try {
43348
43471
  if (isJumping.current) {
43349
43472
  return Promise.resolve();
43350
43473
  }
43474
+ clearPendingLatestJump();
43351
43475
  var oldestVisibleId = getFirstConfirmedMessageId(messages);
43352
43476
  if (!oldestVisibleId || !hasPrevious || windowLoadScopeRef.current) {
43353
43477
  return Promise.resolve();
43354
43478
  }
43355
43479
  var requestId = createEdgeRequestId('previous');
43356
43480
  activeEdgeIntentRef.current = 'previous';
43481
+ var cachedPreviousMessages = getContiguousPrevMessages(channel.id, {
43482
+ id: oldestVisibleId
43483
+ }, LOAD_MAX_MESSAGE_COUNT);
43484
+ if (cachedPreviousMessages.length > 0) {
43485
+ var _container = scrollRef.current;
43486
+ var anchor = _container ? getTopViewportAnchor(_container, itemElementsRef.current) : null;
43487
+ if (anchor && _container) {
43488
+ cachedEdgeRequestRef.current = {
43489
+ requestId: requestId,
43490
+ direction: 'previous',
43491
+ anchorId: oldestVisibleId
43492
+ };
43493
+ restoreRef.current = {
43494
+ mode: 'preserve-anchor',
43495
+ itemId: anchor.itemId,
43496
+ offsetFromTop: anchor.offsetFromTop,
43497
+ sourceScrollTop: _container.scrollTop,
43498
+ loadDirection: 'previous',
43499
+ requestId: requestId
43500
+ };
43501
+ } else {
43502
+ cachedEdgeRequestRef.current = null;
43503
+ }
43504
+ suppressNextMessageChange();
43505
+ dispatch(addMessagesAC(cachedPreviousMessages, MESSAGE_LOAD_DIRECTION.PREV));
43506
+ historyLoadArmedRef.current = true;
43507
+ if (loadPrevFrameRef.current !== null) {
43508
+ cancelAnimationFrame(loadPrevFrameRef.current);
43509
+ }
43510
+ loadPrevFrameRef.current = requestAnimationFrame(function () {
43511
+ loadPrevFrameRef.current = null;
43512
+ handleScrollRef.current();
43513
+ });
43514
+ return Promise.resolve();
43515
+ }
43357
43516
  activeEdgeRequestRef.current = {
43358
43517
  requestId: requestId,
43359
43518
  direction: 'previous',
@@ -43361,12 +43520,12 @@ function useChatController(_ref3) {
43361
43520
  };
43362
43521
  var container = scrollRef.current;
43363
43522
  if (container) {
43364
- var anchor = getTopViewportAnchor(container, itemElementsRef.current);
43365
- if (anchor) {
43523
+ var _anchor = getTopViewportAnchor(container, itemElementsRef.current);
43524
+ if (_anchor) {
43366
43525
  restoreRef.current = {
43367
43526
  mode: 'preserve-anchor',
43368
- itemId: anchor.itemId,
43369
- offsetFromTop: anchor.offsetFromTop,
43527
+ itemId: _anchor.itemId,
43528
+ offsetFromTop: _anchor.offsetFromTop,
43370
43529
  sourceScrollTop: container.scrollTop,
43371
43530
  loadDirection: 'previous',
43372
43531
  requestId: requestId
@@ -43374,13 +43533,13 @@ function useChatController(_ref3) {
43374
43533
  }
43375
43534
  }
43376
43535
  setIsLoadingPrevious(true);
43377
- var _temp3 = _finallyRethrows(function () {
43536
+ var _temp = _finallyRethrows(function () {
43378
43537
  return Promise.resolve(loadPrevious(oldestVisibleId, requestId)).then(function (result) {
43379
43538
  if (!result.items.length && isActiveEdgeRequestCurrent(requestId, 'previous')) {
43380
43539
  clearPreserveAnchorForRequest(requestId);
43381
43540
  }
43382
43541
  });
43383
- }, function (_wasThrown2, _result3) {
43542
+ }, function (_wasThrown2, _result2) {
43384
43543
  var isCurrentRequest = isActiveEdgeRequestCurrent(requestId, 'previous');
43385
43544
  if (isCurrentRequest) {
43386
43545
  dispatch(clearActivePaginationIntentAC(requestId));
@@ -43397,38 +43556,79 @@ function useChatController(_ref3) {
43397
43556
  handleScrollRef.current();
43398
43557
  });
43399
43558
  setIsLoadingPrevious(false);
43400
- if (_wasThrown2) throw _result3;
43401
- return _result3;
43559
+ if (_wasThrown2) throw _result2;
43560
+ return _result2;
43402
43561
  });
43403
- return Promise.resolve(_temp3 && _temp3.then ? _temp3.then(function () {}) : void 0);
43562
+ return Promise.resolve(_temp && _temp.then ? _temp.then(function () {}) : void 0);
43404
43563
  } catch (e) {
43405
43564
  return Promise.reject(e);
43406
43565
  }
43407
- }, [channel.id, clearPreserveAnchorForRequest, consumeSuppressedMessageChange, createEdgeRequestId, dispatch, hasNext, hasPrevious, isActiveEdgeRequestCurrent, isLoadingPrevious, loadPrevious, messages]);
43566
+ }, [channel.id, clearPreserveAnchorForRequest, consumeSuppressedMessageChange, createEdgeRequestId, clearPendingLatestJump, dispatch, suppressNextMessageChange, hasNext, hasPrevious, isActiveEdgeRequestCurrent, isLoadingPrevious, loadPrevious, messages]);
43408
43567
  var loadNextItems = React.useCallback(function () {
43409
43568
  try {
43410
43569
  if (isJumping.current) {
43411
43570
  return Promise.resolve();
43412
43571
  }
43413
- var newestVisibleId = getLastConfirmedMessageId(messages);
43414
- if (!newestVisibleId || !hasNext || windowLoadScopeRef.current) {
43572
+ clearPendingLatestJump();
43573
+ var newestVisibleMessage = messages[messages.length - 1];
43574
+ var newestVisibleMessageRef = getMessageLocalRef(newestVisibleMessage);
43575
+ var newestVisibleConfirmedId = getLastConfirmedMessageId(messages);
43576
+ if (!newestVisibleMessage || !hasNext || windowLoadScopeRef.current) {
43415
43577
  return Promise.resolve();
43416
43578
  }
43417
43579
  var requestId = createEdgeRequestId('next');
43418
43580
  activeEdgeIntentRef.current = 'next';
43581
+ var cachedNextMessages = getContiguousNextMessages(channel.id, newestVisibleMessage, LOAD_MAX_MESSAGE_COUNT, true);
43582
+ if (cachedNextMessages.length > 0) {
43583
+ var _container2 = scrollRef.current;
43584
+ var anchor = _container2 ? getTopViewportAnchor(_container2, itemElementsRef.current) : null;
43585
+ if (anchor && _container2) {
43586
+ cachedEdgeRequestRef.current = {
43587
+ requestId: requestId,
43588
+ direction: 'next',
43589
+ anchorId: newestVisibleMessageRef
43590
+ };
43591
+ restoreRef.current = {
43592
+ mode: 'preserve-anchor',
43593
+ itemId: anchor.itemId,
43594
+ offsetFromTop: anchor.offsetFromTop,
43595
+ sourceScrollTop: _container2.scrollTop,
43596
+ loadDirection: 'next',
43597
+ requestId: requestId
43598
+ };
43599
+ } else {
43600
+ cachedEdgeRequestRef.current = null;
43601
+ }
43602
+ suppressNextMessageChange();
43603
+ dispatch(addMessagesAC(cachedNextMessages, MESSAGE_LOAD_DIRECTION.NEXT));
43604
+ latestLoadArmedRef.current = true;
43605
+ if (loadNextFrameRef.current !== null) {
43606
+ cancelAnimationFrame(loadNextFrameRef.current);
43607
+ }
43608
+ loadNextFrameRef.current = requestAnimationFrame(function () {
43609
+ loadNextFrameRef.current = null;
43610
+ handleScrollRef.current();
43611
+ });
43612
+ return Promise.resolve();
43613
+ }
43614
+ if (!newestVisibleConfirmedId) {
43615
+ activeEdgeIntentRef.current = null;
43616
+ latestLoadArmedRef.current = true;
43617
+ return Promise.resolve();
43618
+ }
43419
43619
  activeEdgeRequestRef.current = {
43420
43620
  requestId: requestId,
43421
43621
  direction: 'next',
43422
- anchorId: newestVisibleId
43622
+ anchorId: newestVisibleMessageRef || newestVisibleConfirmedId
43423
43623
  };
43424
43624
  var container = scrollRef.current;
43425
43625
  if (container) {
43426
- var anchor = getTopViewportAnchor(container, itemElementsRef.current);
43427
- if (anchor) {
43626
+ var _anchor2 = getTopViewportAnchor(container, itemElementsRef.current);
43627
+ if (_anchor2) {
43428
43628
  restoreRef.current = {
43429
43629
  mode: 'preserve-anchor',
43430
- itemId: anchor.itemId,
43431
- offsetFromTop: anchor.offsetFromTop,
43630
+ itemId: _anchor2.itemId,
43631
+ offsetFromTop: _anchor2.offsetFromTop,
43432
43632
  sourceScrollTop: container.scrollTop,
43433
43633
  loadDirection: 'next',
43434
43634
  requestId: requestId
@@ -43436,13 +43636,13 @@ function useChatController(_ref3) {
43436
43636
  }
43437
43637
  }
43438
43638
  setIsLoadingNext(true);
43439
- var _temp4 = _finallyRethrows(function () {
43440
- return Promise.resolve(loadNext(newestVisibleId, requestId)).then(function (result) {
43639
+ var _temp2 = _finallyRethrows(function () {
43640
+ return Promise.resolve(loadNext(newestVisibleConfirmedId, requestId)).then(function (result) {
43441
43641
  if (!result.items.length && isActiveEdgeRequestCurrent(requestId, 'next')) {
43442
43642
  clearPreserveAnchorForRequest(requestId);
43443
43643
  }
43444
43644
  });
43445
- }, function (_wasThrown3, _result4) {
43645
+ }, function (_wasThrown3, _result3) {
43446
43646
  var isCurrentRequest = isActiveEdgeRequestCurrent(requestId, 'next');
43447
43647
  if (isCurrentRequest) {
43448
43648
  dispatch(clearActivePaginationIntentAC(requestId));
@@ -43459,14 +43659,14 @@ function useChatController(_ref3) {
43459
43659
  handleScrollRef.current();
43460
43660
  });
43461
43661
  setIsLoadingNext(false);
43462
- if (_wasThrown3) throw _result4;
43463
- return _result4;
43662
+ if (_wasThrown3) throw _result3;
43663
+ return _result3;
43464
43664
  });
43465
- return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(function () {}) : void 0);
43665
+ return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function () {}) : void 0);
43466
43666
  } catch (e) {
43467
43667
  return Promise.reject(e);
43468
43668
  }
43469
- }, [channel.id, clearPreserveAnchorForRequest, consumeSuppressedMessageChange, createEdgeRequestId, dispatch, hasNext, hasPrevious, isActiveEdgeRequestCurrent, isLoadingNext, loadNext, messages]);
43669
+ }, [channel.id, clearPreserveAnchorForRequest, consumeSuppressedMessageChange, createEdgeRequestId, clearPendingLatestJump, dispatch, suppressNextMessageChange, hasNext, hasPrevious, isActiveEdgeRequestCurrent, isLoadingNext, loadNext, messages]);
43470
43670
  var handleTimelineScroll = React.useCallback(function () {
43471
43671
  var _restoreRef$current2, _restoreRef$current3;
43472
43672
  var container = scrollRef.current;
@@ -43632,6 +43832,7 @@ function useChatController(_ref3) {
43632
43832
  itemElementsRef.current.clear();
43633
43833
  previousMessagesRef.current = [];
43634
43834
  suppressedMessageChangesRef.current = 0;
43835
+ pendingLatestJumpRef.current = null;
43635
43836
  (_pendingWindowLoadRef = pendingWindowLoadRef.current) === null || _pendingWindowLoadRef === void 0 ? void 0 : _pendingWindowLoadRef.resolve({
43636
43837
  items: []
43637
43838
  });
@@ -43746,7 +43947,7 @@ function useChatController(_ref3) {
43746
43947
  var offsetDelta = anchorRect.top - containerRect.top - restoreState.offsetFromTop;
43747
43948
  restoreRef.current = null;
43748
43949
  if (offsetDelta !== 0) {
43749
- setScrollTop(container, Math.max(LATEST_EDGE_GAP_PX, container.scrollTop + offsetDelta), 'auto');
43950
+ setScrollTop(container, Math.max(LATEST_EDGE_GAP_PX, container.scrollTop - offsetDelta), 'auto');
43750
43951
  }
43751
43952
  return;
43752
43953
  }
@@ -43778,7 +43979,7 @@ function useChatController(_ref3) {
43778
43979
  cachedEdgeRequestRef.current = null;
43779
43980
  }
43780
43981
  if (_offsetDelta !== 0) {
43781
- var nextScrollTop = Math.max(LATEST_EDGE_GAP_PX, container.scrollTop + _offsetDelta);
43982
+ var nextScrollTop = Math.max(LATEST_EDGE_GAP_PX, container.scrollTop - _offsetDelta);
43782
43983
  setScrollTop(container, nextScrollTop, 'auto');
43783
43984
  }
43784
43985
  }
@@ -43943,6 +44144,13 @@ function useChatController(_ref3) {
43943
44144
  if (connectionStatus !== CONNECTION_STATUS.CONNECTED || previousConnectionStatus === CONNECTION_STATUS.CONNECTED || !(channel !== null && channel !== void 0 && channel.id)) {
43944
44145
  return;
43945
44146
  }
44147
+ var pendingLatestJump = pendingLatestJumpRef.current;
44148
+ if ((pendingLatestJump === null || pendingLatestJump === void 0 ? void 0 : pendingLatestJump.channelId) === channel.id && pendingLatestJump.needsServerSync) {
44149
+ jumpToLatest(pendingLatestJump.smooth)["catch"](function () {
44150
+ return undefined;
44151
+ });
44152
+ return;
44153
+ }
43946
44154
  var applyVisibleWindow = !isScrollInteractionActive();
43947
44155
  if (applyVisibleWindow && !isViewingLatest && lastVisibleAnchorIdRef.current) {
43948
44156
  captureWindowPreserveAnchor();
@@ -43956,7 +44164,7 @@ function useChatController(_ref3) {
43956
44164
  return visibleMessage.id === ((_messagesRef$current$ = messagesRef.current[0]) === null || _messagesRef$current$ === void 0 ? void 0 : _messagesRef$current$.id);
43957
44165
  }) : false;
43958
44166
  dispatch(reloadActiveChannelAfterReconnectAC(channel, lastVisibleAnchorIdRef.current || '', isViewingLatest, applyVisibleWindow, isHistoryTopVisible));
43959
- }, [captureWindowPreserveAnchor, channel === null || channel === void 0 ? void 0 : channel.id, connectionStatus, dispatch, hasPrevious, isScrollInteractionActive, isViewingLatest, suppressNextMessageChange]);
44167
+ }, [captureWindowPreserveAnchor, channel === null || channel === void 0 ? void 0 : channel.id, connectionStatus, dispatch, hasPrevious, isScrollInteractionActive, isViewingLatest, jumpToLatest, suppressNextMessageChange]);
43960
44168
  React.useEffect(function () {
43961
44169
  if (!scrollToNewMessage.scrollToBottom) {
43962
44170
  return;
@@ -44567,7 +44775,8 @@ var MessageList = function MessageList(_ref) {
44567
44775
  return;
44568
44776
  }
44569
44777
  if (channel.lastMessage.id && String(channel.lastMessage.user.id) !== currentUserId) {
44570
- dispatch(markMessagesAsReadAC(channel.id, [channel.lastMessage.id]));
44778
+ var _markerBatcherRef$cur5;
44779
+ (_markerBatcherRef$cur5 = markerBatcherRef.current) === null || _markerBatcherRef$cur5 === void 0 ? void 0 : _markerBatcherRef$cur5.enqueueRead(channel.id, channel.lastMessage.id);
44571
44780
  }
44572
44781
  jumpToLatest(true);
44573
44782
  };
@@ -55277,7 +55486,7 @@ var StatusText$1 = styled__default.p(_templateObject11$c || (_templateObject11$c
55277
55486
  return props.full ? 'height: 100%;' : '';
55278
55487
  });
55279
55488
  var GroupSection = styled__default.div(_templateObject12$8 || (_templateObject12$8 = _taggedTemplateLiteralLoose(["\n position: relative;\n"])));
55280
- var GroupLabel = styled__default.div(_templateObject13$7 || (_templateObject13$7 = _taggedTemplateLiteralLoose(["\n position: sticky;\n top: 0;\n z-index: 1;\n background-color: ", ";\n text-transform: capitalize;\n letter-spacing: 0.5px;\n color: ", ";\n padding: 12px 16px 4px;\n font-weight: 500;\n font-size: 13px;\n line-height: 16px;\n letter-spacing: 0px;\n"])), function (p) {
55489
+ var GroupLabel = styled__default.div(_templateObject13$7 || (_templateObject13$7 = _taggedTemplateLiteralLoose(["\n position: sticky;\n top: 0;\n z-index: 1;\n background-color: ", ";\n text-transform: capitalize;\n letter-spacing: 0.5px;\n color: ", ";\n padding: 12px 16px 4px;\n font-weight: 500;\n font-size: 13px;\n line-height: 16px;\n user-select: none;\n"])), function (p) {
55281
55490
  return p.backgroundColor;
55282
55491
  }, function (p) {
55283
55492
  return p.color;