stream-chat-react 10.22.0 → 10.22.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.
@@ -1 +1 @@
1
- {"version":3,"file":"ModalGallery.d.ts","sourceRoot":"","sources":["../../../src/components/Gallery/ModalGallery.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAEnE,oBAAY,iBAAiB,CAC3B,kBAAkB,SAAS,yBAAyB,GAAG,yBAAyB,IAC9E;IACF,4CAA4C;IAC5C,MAAM,EAAE,UAAU,CAAC,kBAAkB,CAAC,EAAE,CAAC;IACzC,kCAAkC;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,eAAO,MAAM,YAAY,iJA8BxB,CAAC"}
1
+ {"version":3,"file":"ModalGallery.d.ts","sourceRoot":"","sources":["../../../src/components/Gallery/ModalGallery.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAEnE,oBAAY,iBAAiB,CAC3B,kBAAkB,SAAS,yBAAyB,GAAG,yBAAyB,IAC9E;IACF,4CAA4C;IAC5C,MAAM,EAAE,UAAU,CAAC,kBAAkB,CAAC,EAAE,CAAC;IACzC,kCAAkC;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAYF,eAAO,MAAM,YAAY,iJA+BxB,CAAC"}
@@ -1,6 +1,16 @@
1
1
  import React, { useMemo } from 'react';
2
2
  import ImageGallery from 'react-image-gallery';
3
+ import { BaseImage } from './BaseImage';
3
4
  import { useTranslationContext } from '../../context';
5
+ var onError = function (e) {
6
+ // Prevent having alt attribute on img as the img takes the height of the alt text
7
+ // instead of the CSS / element width & height when the CSS mask (fallback) is applied.
8
+ e.target.alt = '';
9
+ };
10
+ var renderItem = function (_a) {
11
+ var original = _a.original, originalAlt = _a.originalAlt;
12
+ return (React.createElement(BaseImage, { alt: originalAlt, className: 'image-gallery-image', onError: onError, src: original }));
13
+ };
4
14
  export var ModalGallery = function (props) {
5
15
  var images = props.images, index = props.index;
6
16
  var t = useTranslationContext('ModalGallery').t;
@@ -14,5 +24,5 @@ export var ModalGallery = function (props) {
14
24
  };
15
25
  });
16
26
  }, [images]);
17
- return (React.createElement(ImageGallery, { items: formattedArray, showIndex: true, showPlayButton: false, showThumbnails: false, startIndex: index }));
27
+ return (React.createElement(ImageGallery, { items: formattedArray, renderItem: renderItem, showIndex: true, showPlayButton: false, showThumbnails: false, startIndex: index }));
18
28
  };
@@ -1 +1 @@
1
- {"version":3,"file":"usePrependMessagesCount.d.ts","sourceRoot":"","sources":["../../../../../src/components/MessageList/hooks/VirtualizedMessageList/usePrependMessagesCount.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAE7E,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAIzE,wBAAgB,yBAAyB,CACvC,kBAAkB,SAAS,yBAAyB,GAAG,yBAAyB,EAChF,QAAQ,EAAE,aAAa,CAAC,kBAAkB,CAAC,EAAE,EAAE,gBAAgB,EAAE,OAAO,UA2DzE"}
1
+ {"version":3,"file":"usePrependMessagesCount.d.ts","sourceRoot":"","sources":["../../../../../src/components/MessageList/hooks/VirtualizedMessageList/usePrependMessagesCount.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAE7E,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAOzE,wBAAgB,yBAAyB,CACvC,kBAAkB,SAAS,yBAAyB,GAAG,yBAAyB,EAChF,QAAQ,EAAE,aAAa,CAAC,kBAAkB,CAAC,EAAE,EAAE,gBAAgB,EAAE,OAAO,UAgEzE"}
@@ -1,9 +1,12 @@
1
1
  import { useMemo, useRef } from 'react';
2
- var STATUSES_EXCLUDED_FROM_PREPEND = ['sending', 'failed'];
2
+ var STATUSES_EXCLUDED_FROM_PREPEND = {
3
+ failed: true,
4
+ sending: true,
5
+ };
3
6
  export function usePrependedMessagesCount(messages, hasDateSeparator) {
4
7
  var firstRealMessageIndex = hasDateSeparator ? 1 : 0;
5
- var firstMessageId = useRef();
6
- var earliestMessageId = useRef();
8
+ var firstMessageOnFirstLoadedPage = useRef();
9
+ var previousFirstMessageOnFirstLoadedPage = useRef();
7
10
  var previousNumItemsPrepended = useRef(0);
8
11
  var numItemsPrepended = useMemo(function () {
9
12
  var _a, _b;
@@ -11,46 +14,42 @@ export function usePrependedMessagesCount(messages, hasDateSeparator) {
11
14
  previousNumItemsPrepended.current = 0;
12
15
  return 0;
13
16
  }
14
- var currentFirstMessageId = (_a = messages === null || messages === void 0 ? void 0 : messages[firstRealMessageIndex]) === null || _a === void 0 ? void 0 : _a.id;
15
- // if no new messages were prepended, return early (same amount as before)
16
- if (currentFirstMessageId === earliestMessageId.current) {
17
+ var currentFirstMessage = messages === null || messages === void 0 ? void 0 : messages[firstRealMessageIndex];
18
+ var noNewMessages = (currentFirstMessage === null || currentFirstMessage === void 0 ? void 0 : currentFirstMessage.id) === ((_a = previousFirstMessageOnFirstLoadedPage.current) === null || _a === void 0 ? void 0 : _a.id);
19
+ // This is possible only, when sending messages very quickly (basically single char messages submitted like a crazy) in empty channel (first page)
20
+ // Optimistic UI update, when sending messages, can lead to a situation, when
21
+ // the order of the messages changes for a moment. This can happen, when a user
22
+ // sends multiple messages withing few milliseconds. E.g. we send a message A
23
+ // then message B. At first we have message array with both messages of status "sending"
24
+ // then response for message A is received with a new - later - created_at timestamp
25
+ // this leads to rearrangement of 1.B ("sending"), 2.A ("received"). Still firstMessageOnFirstLoadedPage.current
26
+ // points to message A, but now this message has index 1 => previousNumItemsPrepended.current === 1
27
+ // That in turn leads to incorrect index calculation in VirtualizedMessageList trying to access a message
28
+ // at non-existent index. Therefore, we ignore messages of status "sending" / "failed" in order they are
29
+ // not considered as prepended messages.
30
+ var firstMsgMovedAfterMessagesInExcludedStatus = (currentFirstMessage === null || currentFirstMessage === void 0 ? void 0 : currentFirstMessage.status) && STATUSES_EXCLUDED_FROM_PREPEND[currentFirstMessage.status];
31
+ if (noNewMessages || firstMsgMovedAfterMessagesInExcludedStatus) {
17
32
  return previousNumItemsPrepended.current;
18
33
  }
19
- if (!firstMessageId.current) {
20
- firstMessageId.current = currentFirstMessageId;
34
+ if (!firstMessageOnFirstLoadedPage.current) {
35
+ firstMessageOnFirstLoadedPage.current = currentFirstMessage;
21
36
  }
22
- earliestMessageId.current = currentFirstMessageId;
37
+ previousFirstMessageOnFirstLoadedPage.current = currentFirstMessage;
23
38
  // if new messages were prepended, find out how many
24
39
  // start with this number because there cannot be fewer prepended items than before
25
- var adjustPrependedMessageCount = 0;
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
- }
43
- if (messages[i].id === firstMessageId.current) {
44
- previousNumItemsPrepended.current = i - adjustPrependedMessageCount;
45
- return previousNumItemsPrepended.current;
40
+ for (var prependedMessageCount = previousNumItemsPrepended.current; prependedMessageCount < messages.length; prependedMessageCount += 1) {
41
+ var messageIsFirstOnFirstLoadedPage = messages[prependedMessageCount].id === ((_b = firstMessageOnFirstLoadedPage.current) === null || _b === void 0 ? void 0 : _b.id);
42
+ if (messageIsFirstOnFirstLoadedPage) {
43
+ previousNumItemsPrepended.current = prependedMessageCount;
44
+ return prependedMessageCount;
46
45
  }
47
46
  }
48
47
  // if no match has found, we have jumped - reset the prepended item count.
49
- firstMessageId.current = currentFirstMessageId;
48
+ firstMessageOnFirstLoadedPage.current = currentFirstMessage;
50
49
  previousNumItemsPrepended.current = 0;
51
50
  return 0;
52
51
  // TODO: there's a bug here, the messages prop is the same array instance (something mutates it)
53
52
  // that's why the second dependency is necessary
54
- }, [messages, messages === null || messages === void 0 ? void 0 : messages.length]);
53
+ }, [firstRealMessageIndex, messages, messages === null || messages === void 0 ? void 0 : messages.length]);
55
54
  return numItemsPrepended;
56
55
  }