stream-chat-react 10.7.1 → 10.7.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.
@@ -261,7 +261,7 @@ var ChannelInner = function (props) {
261
261
  client.off('user.deleted', handleEvent);
262
262
  notificationTimeouts.forEach(clearTimeout);
263
263
  };
264
- }, [channel.cid, doMarkReadRequest]);
264
+ }, [channel.cid, doMarkReadRequest, channelConfig === null || channelConfig === void 0 ? void 0 : channelConfig.read_events]);
265
265
  useEffect(function () {
266
266
  var _a;
267
267
  if (!state.thread)
@@ -1 +1 @@
1
- {"version":3,"file":"usePrependMessagesCount.d.ts","sourceRoot":"","sources":["../../../../src/components/MessageList/hooks/usePrependMessagesCount.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAE1E,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAEtE,wBAAgB,yBAAyB,CACvC,kBAAkB,SAAS,yBAAyB,GAAG,yBAAyB,EAChF,QAAQ,EAAE,aAAa,CAAC,kBAAkB,CAAC,EAAE,EAAE,gBAAgB,EAAE,OAAO,UAwCzE"}
1
+ {"version":3,"file":"usePrependMessagesCount.d.ts","sourceRoot":"","sources":["../../../../src/components/MessageList/hooks/usePrependMessagesCount.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAE1E,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAItE,wBAAgB,yBAAyB,CACvC,kBAAkB,SAAS,yBAAyB,GAAG,yBAAyB,EAChF,QAAQ,EAAE,aAAa,CAAC,kBAAkB,CAAC,EAAE,EAAE,gBAAgB,EAAE,OAAO,UA2DzE"}
@@ -1,11 +1,12 @@
1
1
  import { useMemo, useRef } from 'react';
2
+ var STATUSES_EXCLUDED_FROM_PREPEND = ['sending', 'failed'];
2
3
  export function usePrependedMessagesCount(messages, hasDateSeparator) {
3
4
  var firstRealMessageIndex = hasDateSeparator ? 1 : 0;
4
5
  var firstMessageId = useRef();
5
6
  var earliestMessageId = useRef();
6
7
  var previousNumItemsPrepended = useRef(0);
7
8
  var numItemsPrepended = useMemo(function () {
8
- var _a;
9
+ var _a, _b;
9
10
  if (!messages || !messages.length) {
10
11
  previousNumItemsPrepended.current = 0;
11
12
  return 0;
@@ -21,13 +22,30 @@ export function usePrependedMessagesCount(messages, hasDateSeparator) {
21
22
  earliestMessageId.current = currentFirstMessageId;
22
23
  // if new messages were prepended, find out how many
23
24
  // start with this number because there cannot be fewer prepended items than before
25
+ var adjustPrependedMessageCount = 0;
24
26
  for (var i = previousNumItemsPrepended.current; i < messages.length; i += 1) {
27
+ // Optimistic UI update, when sending messages, can lead to a situation, when
28
+ // the order of the messages changes for a moment. This can happen, when a user
29
+ // sends multiple messages withing few milliseconds. E.g. we send a message A
30
+ // then message B. At first we have message array with both messages of status "sending"
31
+ // then response for message A is received with a new - later - created_at timestamp
32
+ // this leads to rearrangement of 1.B ("sending"), 2.A ("received"). Still firstMessageId.current
33
+ // points to message A, but now this message has index 1 => previousNumItemsPrepended.current === 1
34
+ // That in turn leads to incorrect index calculation in VirtualizedMessageList trying to access a message
35
+ // at non-existent index. Therefore, we ignore messages of status "sending" / "failed" in order they are
36
+ // not considered as prepended messages.
37
+ if (((_b = messages[i]) === null || _b === void 0 ? void 0 : _b.status) &&
38
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
39
+ STATUSES_EXCLUDED_FROM_PREPEND.includes(messages[i].status) &&
40
+ messages[i].id !== firstMessageId.current) {
41
+ adjustPrependedMessageCount++;
42
+ }
25
43
  if (messages[i].id === firstMessageId.current) {
26
- previousNumItemsPrepended.current = i;
27
- return i;
44
+ previousNumItemsPrepended.current = i - adjustPrependedMessageCount;
45
+ return previousNumItemsPrepended.current;
28
46
  }
29
47
  }
30
- // if no match has found, we have jumped - reset the prepend item count.
48
+ // if no match has found, we have jumped - reset the prepended item count.
31
49
  firstMessageId.current = currentFirstMessageId;
32
50
  previousNumItemsPrepended.current = 0;
33
51
  return 0;