stream-chat-react 11.1.1 → 11.1.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.
@@ -10007,7 +10007,16 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
10007
10007
 
10008
10008
  var ImageGallery = /*@__PURE__*/getDefaultExportFromCjs(imageGallery.exports);
10009
10009
 
10010
- window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var ModalGallery = function (props) {
10010
+ window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var onError = function (e) {
10011
+ // Prevent having alt attribute on img as the img takes the height of the alt text
10012
+ // instead of the CSS / element width & height when the CSS mask (fallback) is applied.
10013
+ e.target.alt = '';
10014
+ };
10015
+ var renderItem = function (_a) {
10016
+ var original = _a.original, originalAlt = _a.originalAlt;
10017
+ return (React__default["default"].createElement(BaseImage, { alt: originalAlt, className: 'image-gallery-image', onError: onError, src: original }));
10018
+ };
10019
+ var ModalGallery = function (props) {
10011
10020
  var images = props.images, index = props.index;
10012
10021
  var t = useTranslationContext('ModalGallery').t;
10013
10022
  var formattedArray = React$2.useMemo(function () {
@@ -10020,7 +10029,7 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
10020
10029
  };
10021
10030
  });
10022
10031
  }, [images]);
10023
- return (React__default["default"].createElement(ImageGallery, { items: formattedArray, showIndex: true, showPlayButton: false, showThumbnails: false, startIndex: index }));
10032
+ return (React__default["default"].createElement(ImageGallery, { items: formattedArray, renderItem: renderItem, showIndex: true, showPlayButton: false, showThumbnails: false, startIndex: index }));
10024
10033
  };
10025
10034
 
10026
10035
  window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var UnMemoizedGallery = function (props) {
@@ -43590,6 +43599,7 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
43590
43599
  currentTrigger: null,
43591
43600
  data: null,
43592
43601
  dataLoading: false,
43602
+ isComposing: false,
43593
43603
  left: null,
43594
43604
  selectionEnd: 0,
43595
43605
  selectionStart: 0,
@@ -43640,22 +43650,23 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
43640
43650
  SuggestionItem,
43641
43651
  SuggestionList = List$1
43642
43652
  } = this.props;
43653
+ const {
43654
+ isComposing
43655
+ } = this.state;
43643
43656
  const triggerProps = this.getTriggerProps();
43644
- if (triggerProps.values && triggerProps.currentTrigger && !(disableMentions && triggerProps.currentTrigger === '@')) {
43645
- return /*#__PURE__*/React__default["default"].createElement("div", {
43646
- className: clsx('rta__autocomplete', 'str-chat__suggestion-list-container', dropdownClassName),
43647
- ref: this.setDropdownRef,
43648
- style: dropdownStyle
43649
- }, /*#__PURE__*/React__default["default"].createElement(SuggestionList, _extends$2({
43650
- className: clsx('str-chat__suggestion-list', listClassName),
43651
- dropdownScroll: this._dropdownScroll,
43652
- itemClassName: clsx('str-chat__suggestion-list-item', itemClassName),
43653
- itemStyle: itemStyle,
43654
- onSelect: this._onSelect,
43655
- SuggestionItem: SuggestionItem
43656
- }, triggerProps)));
43657
- }
43658
- return null;
43657
+ if (isComposing || !triggerProps.values || !triggerProps.currentTrigger || disableMentions && triggerProps.currentTrigger === '@') return null;
43658
+ return /*#__PURE__*/React__default["default"].createElement("div", {
43659
+ className: clsx('rta__autocomplete', 'str-chat__suggestion-list-container', dropdownClassName),
43660
+ ref: this.setDropdownRef,
43661
+ style: dropdownStyle
43662
+ }, /*#__PURE__*/React__default["default"].createElement(SuggestionList, _extends$2({
43663
+ className: clsx('str-chat__suggestion-list', listClassName),
43664
+ dropdownScroll: this._dropdownScroll,
43665
+ itemClassName: clsx('str-chat__suggestion-list-item', itemClassName),
43666
+ itemStyle: itemStyle,
43667
+ onSelect: this._onSelect,
43668
+ SuggestionItem: SuggestionItem
43669
+ }, triggerProps)));
43659
43670
  }
43660
43671
  render() {
43661
43672
  const {
@@ -43709,6 +43720,14 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
43709
43720
  this._onClickAndBlurHandler(e);
43710
43721
  onClick === null || onClick === void 0 ? void 0 : onClick(e);
43711
43722
  },
43723
+ onCompositionEnd: () => this.setState(pv => ({
43724
+ ...pv,
43725
+ isComposing: false
43726
+ })),
43727
+ onCompositionStart: () => this.setState(pv => ({
43728
+ ...pv,
43729
+ isComposing: true
43730
+ })),
43712
43731
  onFocus: e => {
43713
43732
  var _this$props$onFocus, _this$props;
43714
43733
  (_this$props$onFocus = (_this$props = this.props).onFocus) === null || _this$props$onFocus === void 0 ? void 0 : _this$props$onFocus.call(_this$props, e);
@@ -47788,19 +47807,22 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
47788
47807
  };
47789
47808
 
47790
47809
  window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var CooldownTimer = function (_a) {
47791
- var cooldownInterval = _a.cooldownInterval, setCooldownRemaining = _a.setCooldownRemaining;
47792
- var _b = React$2.useState(cooldownInterval), seconds = _b[0], setSeconds = _b[1];
47810
+ var cooldownInterval = _a.cooldownInterval;
47811
+ var _b = React$2.useState(), seconds = _b[0], setSeconds = _b[1];
47793
47812
  React$2.useEffect(function () {
47794
- var countdownInterval = setInterval(function () {
47795
- if (seconds > 0) {
47813
+ var countdownTimeout;
47814
+ if (typeof seconds === 'number' && seconds > 0) {
47815
+ countdownTimeout = setTimeout(function () {
47796
47816
  setSeconds(seconds - 1);
47797
- }
47798
- else {
47799
- setCooldownRemaining(0);
47800
- }
47801
- }, 1000);
47802
- return function () { return clearInterval(countdownInterval); };
47803
- });
47817
+ }, 1000);
47818
+ }
47819
+ return function () {
47820
+ clearTimeout(countdownTimeout);
47821
+ };
47822
+ }, [seconds]);
47823
+ React$2.useEffect(function () {
47824
+ setSeconds(cooldownInterval !== null && cooldownInterval !== void 0 ? cooldownInterval : 0);
47825
+ }, [cooldownInterval]);
47804
47826
  return (React__default["default"].createElement("div", { className: 'str-chat__message-input-cooldown', "data-testid": 'cooldown-timer' }, seconds));
47805
47827
  };
47806
47828
 
@@ -48530,11 +48552,20 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
48530
48552
  ? // prevent negative values
48531
48553
  Math.max(0, (new Date().getTime() - ownLatestMessageDate.getTime()) / 1000)
48532
48554
  : undefined;
48533
- setCooldownRemaining(!skipCooldown &&
48555
+ var remaining = !skipCooldown &&
48534
48556
  typeof timeSinceOwnLastMessage !== 'undefined' &&
48535
48557
  cooldownInterval > timeSinceOwnLastMessage
48536
48558
  ? Math.round(cooldownInterval - timeSinceOwnLastMessage)
48537
- : 0);
48559
+ : 0;
48560
+ setCooldownRemaining(remaining);
48561
+ if (!remaining)
48562
+ return;
48563
+ var timeout = setTimeout(function () {
48564
+ setCooldownRemaining(0);
48565
+ }, remaining * 1000);
48566
+ return function () {
48567
+ clearTimeout(timeout);
48568
+ };
48538
48569
  }, [cooldownInterval, ownLatestMessageDate, skipCooldown]);
48539
48570
  return {
48540
48571
  cooldownInterval: cooldownInterval,
@@ -50461,9 +50492,9 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
50461
50492
  var markReadThrottled = lodash_throttle(markRead, 500, { leading: true, trailing: true });
50462
50493
  var handleEvent = function (event) { return __awaiter(void 0, void 0, void 0, function () {
50463
50494
  var mainChannelUpdated, unread, messageDate, cid, oldestID;
50464
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
50465
- return __generator(this, function (_m) {
50466
- switch (_m.label) {
50495
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
50496
+ return __generator(this, function (_k) {
50497
+ switch (_k.label) {
50467
50498
  case 0:
50468
50499
  if (event.message) {
50469
50500
  dispatch({
@@ -50485,7 +50516,7 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
50485
50516
  if (((_a = event.message) === null || _a === void 0 ? void 0 : _a.parent_id) && !((_b = event.message) === null || _b === void 0 ? void 0 : _b.show_in_channel)) {
50486
50517
  mainChannelUpdated = false;
50487
50518
  }
50488
- if (mainChannelUpdated && ((_d = (_c = event.message) === null || _c === void 0 ? void 0 : _c.user) === null || _d === void 0 ? void 0 : _d.id) !== client.userID) {
50519
+ if (mainChannelUpdated) {
50489
50520
  if (!document.hidden) {
50490
50521
  markReadThrottled();
50491
50522
  }
@@ -50499,9 +50530,9 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
50499
50530
  }
50500
50531
  }
50501
50532
  }
50502
- if (((_f = (_e = event.message) === null || _e === void 0 ? void 0 : _e.user) === null || _f === void 0 ? void 0 : _f.id) === client.userID &&
50503
- ((_g = event === null || event === void 0 ? void 0 : event.message) === null || _g === void 0 ? void 0 : _g.created_at) &&
50504
- ((_h = event === null || event === void 0 ? void 0 : event.message) === null || _h === void 0 ? void 0 : _h.cid)) {
50533
+ if (((_d = (_c = event.message) === null || _c === void 0 ? void 0 : _c.user) === null || _d === void 0 ? void 0 : _d.id) === client.userID &&
50534
+ ((_e = event === null || event === void 0 ? void 0 : event.message) === null || _e === void 0 ? void 0 : _e.created_at) &&
50535
+ ((_f = event === null || event === void 0 ? void 0 : event.message) === null || _f === void 0 ? void 0 : _f.cid)) {
50505
50536
  messageDate = new Date(event.message.created_at);
50506
50537
  cid = event.message.cid;
50507
50538
  if (!latestMessageDatesByChannels[cid] ||
@@ -50511,7 +50542,7 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
50511
50542
  }
50512
50543
  }
50513
50544
  if (!(event.type === 'user.deleted')) return [3 /*break*/, 2];
50514
- oldestID = (_l = (_k = (_j = channel.state) === null || _j === void 0 ? void 0 : _j.messages) === null || _k === void 0 ? void 0 : _k[0]) === null || _l === void 0 ? void 0 : _l.id;
50545
+ oldestID = (_j = (_h = (_g = channel.state) === null || _g === void 0 ? void 0 : _g.messages) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.id;
50515
50546
  /**
50516
50547
  * As the channel state is not normalized we re-fetch the channel data. Thus, we avoid having to search for user references in the channel state.
50517
50548
  */
@@ -50525,8 +50556,8 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
50525
50556
  * As the channel state is not normalized we re-fetch the channel data. Thus, we avoid having to search for user references in the channel state.
50526
50557
  */
50527
50558
  // FIXME: we should use channelQueryOptions if they are available
50528
- _m.sent();
50529
- _m.label = 2;
50559
+ _k.sent();
50560
+ _k.label = 2;
50530
50561
  case 2:
50531
50562
  throttledCopyStateFromChannel();
50532
50563
  return [2 /*return*/];
@@ -50588,6 +50619,13 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
50588
50619
  hasMore: hasMoreMessagesProbably(channel.state.messages.length, (_e = (_d = channelQueryOptions === null || channelQueryOptions === void 0 ? void 0 : channelQueryOptions.messages) === null || _d === void 0 ? void 0 : _d.limit) !== null && _e !== void 0 ? _e : DEFAULT_INITIAL_CHANNEL_PAGE_SIZE),
50589
50620
  type: 'initStateFromChannel',
50590
50621
  });
50622
+ /**
50623
+ * TODO: maybe pass last_read to the countUnread method to get proper value
50624
+ * combined with channel.countUnread adjustment (_countMessageAsUnread)
50625
+ * to allow counting own messages too
50626
+ *
50627
+ * const lastRead = channel.state.read[client.userID as string].last_read;
50628
+ */
50591
50629
  if (channel.countUnread() > 0)
50592
50630
  markRead();
50593
50631
  // The more complex sync logic is done in Chat
@@ -52387,7 +52425,7 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
52387
52425
 
52388
52426
  window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};
52389
52427
 
52390
- window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var version$1 = '11.1.1';
52428
+ window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var version$1 = '11.1.2';
52391
52429
 
52392
52430
  window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var useChat = function (_a) {
52393
52431
  var _b, _c;