stream-chat-react 10.4.0 → 10.4.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.
package/dist/index.cjs.js CHANGED
@@ -28,10 +28,10 @@ require('dayjs/locale/tr');
28
28
  require('dayjs/locale/en');
29
29
  var ImageGallery = require('react-image-gallery');
30
30
  var reactFileUtils = require('react-file-utils');
31
+ var linkify = require('linkifyjs');
31
32
  var _defineProperty$2 = require('@babel/runtime/helpers/defineProperty');
32
33
  var _slicedToArray$2 = require('@babel/runtime/helpers/slicedToArray');
33
34
  var emojiRegex = require('emoji-regex');
34
- var linkify = require('linkifyjs');
35
35
  var nanoid = require('nanoid');
36
36
  var uniqBy = require('lodash.uniqby');
37
37
  var PropTypes = require('prop-types');
@@ -89,10 +89,10 @@ var updateLocale__default = /*#__PURE__*/_interopDefaultLegacy(updateLocale);
89
89
  var localeData__default = /*#__PURE__*/_interopDefaultLegacy(localeData);
90
90
  var relativeTime__default = /*#__PURE__*/_interopDefaultLegacy(relativeTime);
91
91
  var ImageGallery__default = /*#__PURE__*/_interopDefaultLegacy(ImageGallery);
92
+ var linkify__namespace = /*#__PURE__*/_interopNamespace(linkify);
92
93
  var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty$2);
93
94
  var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray$2);
94
95
  var emojiRegex__default = /*#__PURE__*/_interopDefaultLegacy(emojiRegex);
95
- var linkify__namespace = /*#__PURE__*/_interopNamespace(linkify);
96
96
  var uniqBy__default = /*#__PURE__*/_interopDefaultLegacy(uniqBy);
97
97
  var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
98
98
  var ReactIs__default = /*#__PURE__*/_interopDefaultLegacy(ReactIs);
@@ -1746,12 +1746,11 @@ var AttachmentActionsContainer = function (_a) {
1746
1746
  return (React__default["default"].createElement(AttachmentActions$1, __assign({}, attachment, { actionHandler: actionHandler, actions: attachment.actions, id: attachment.id || '', text: attachment.text || '' })));
1747
1747
  };
1748
1748
  function getCssDimensionsVariables(url) {
1749
- var _a;
1750
- var cssVars = (_a = {},
1751
- _a['--original-height'] = 1000000,
1752
- _a['--original-width'] = 1000000,
1753
- _a);
1754
- if (url) {
1749
+ var cssVars = {
1750
+ '--original-height': 1000000,
1751
+ '--original-width': 1000000,
1752
+ };
1753
+ if (linkify__namespace.test(url, 'url')) {
1755
1754
  var urlParams = new URL(url).searchParams;
1756
1755
  var oh = Number(urlParams.get('oh'));
1757
1756
  var ow = Number(urlParams.get('ow'));
@@ -23798,7 +23797,7 @@ var mentionsMarkdownPlugin = function (mentioned_users) { return function () {
23798
23797
  // valid cases: "text @", "@", " @"
23799
23798
  // invalid cases: "text@", "@text",
23800
23799
  /.?\s?@$|^@$/.test(node.value) &&
23801
- nextChildHref.startsWith('mailto:')) {
23800
+ (nextChildHref === null || nextChildHref === void 0 ? void 0 : nextChildHref.startsWith('mailto:'))) {
23802
23801
  var newTextValue = node.value.replace(/@$/, '');
23803
23802
  var username = nextChildHref.replace('mailto:', '');
23804
23803
  parent.children[index] = u('text', newTextValue);
@@ -28365,7 +28364,8 @@ var useUserTrigger = function (params) {
28365
28364
  _a.label = 1;
28366
28365
  case 1:
28367
28366
  _a.trys.push([1, 3, , 4]);
28368
- return [4 /*yield*/, client.queryUsers(__assign({ $or: [{ id: { $autocomplete: query } }, { name: { $autocomplete: query } }], id: { $ne: client.userID } }, mentionQueryParams.filters), __assign({ id: 1 }, mentionQueryParams.sort), __assign({ limit: 10 }, mentionQueryParams.options))];
28367
+ return [4 /*yield*/, client.queryUsers(__assign({ $or: [{ id: { $autocomplete: query } }, { name: { $autocomplete: query } }], id: { $ne: client.userID } }, mentionQueryParams.filters), Array.isArray(mentionQueryParams.sort)
28368
+ ? __spreadArray([{ id: 1 }], mentionQueryParams.sort, true) : __assign({ id: 1 }, mentionQueryParams.sort), __assign({ limit: 10 }, mentionQueryParams.options))];
28369
28369
  case 2:
28370
28370
  users = (_a.sent()).users;
28371
28371
  if (onReady && users.length) {
@@ -30343,24 +30343,28 @@ var EditMessageForm = function () {
30343
30343
  };
30344
30344
 
30345
30345
  var useCooldownTimer = function () {
30346
+ var _a;
30346
30347
  var latestMessageDatesByChannels = useChatContext('useCooldownTimer').latestMessageDatesByChannels;
30347
- var channel = useChannelStateContext('useCooldownTimer').channel;
30348
- var _a = (channel.data ||
30349
- {}), cooldownInterval = _a.cooldown, own_capabilities = _a.own_capabilities;
30350
- var _b = React.useState(), cooldownRemaining = _b[0], setCooldownRemaining = _b[1];
30348
+ var _b = useChannelStateContext('useCooldownTimer'), channel = _b.channel, _c = _b.messages, messages = _c === void 0 ? [] : _c;
30349
+ var client = useChatContext('useCooldownTimer').client;
30350
+ var _d = React.useState(), cooldownRemaining = _d[0], setCooldownRemaining = _d[1];
30351
+ var _e = (channel.data ||
30352
+ {}), cooldownInterval = _e.cooldown, own_capabilities = _e.own_capabilities;
30351
30353
  var skipCooldown = !(own_capabilities === null || own_capabilities === void 0 ? void 0 : own_capabilities.includes('slow-mode'));
30354
+ var ownLatestMessageDate = React.useMemo(function () {
30355
+ var _a, _b;
30356
+ return (_a = latestMessageDatesByChannels[channel.cid]) !== null && _a !== void 0 ? _a : (_b = __spreadArray([], messages, true).sort(function (a, b) { var _a, _b; return ((_a = b.created_at) === null || _a === void 0 ? void 0 : _a.getTime()) - ((_b = a.created_at) === null || _b === void 0 ? void 0 : _b.getTime()); })
30357
+ .find(function (v) { var _a, _b; return ((_a = v.user) === null || _a === void 0 ? void 0 : _a.id) === ((_b = client.user) === null || _b === void 0 ? void 0 : _b.id); })) === null || _b === void 0 ? void 0 : _b.created_at;
30358
+ }, [messages, (_a = client.user) === null || _a === void 0 ? void 0 : _a.id, latestMessageDatesByChannels, channel.cid]);
30352
30359
  React.useEffect(function () {
30353
- var latestMessageDate = latestMessageDatesByChannels[channel.cid];
30354
- if (!cooldownInterval || !latestMessageDate) {
30360
+ if (skipCooldown || !cooldownInterval || !ownLatestMessageDate)
30355
30361
  return;
30356
- }
30357
- var remainingCooldown = Math.round(cooldownInterval - (new Date().getTime() - latestMessageDate.getTime()) / 1000);
30358
- if (remainingCooldown > 0 && !skipCooldown) {
30362
+ var remainingCooldown = Math.round(cooldownInterval - (new Date().getTime() - ownLatestMessageDate.getTime()) / 1000);
30363
+ if (remainingCooldown > 0)
30359
30364
  setCooldownRemaining(remainingCooldown);
30360
- }
30361
- }, [channel.id, cooldownInterval, latestMessageDatesByChannels[channel.cid]]);
30365
+ }, [cooldownInterval, ownLatestMessageDate, skipCooldown]);
30362
30366
  return {
30363
- cooldownInterval: cooldownInterval || 0,
30367
+ cooldownInterval: cooldownInterval !== null && cooldownInterval !== void 0 ? cooldownInterval : 0,
30364
30368
  cooldownRemaining: cooldownRemaining,
30365
30369
  setCooldownRemaining: setCooldownRemaining,
30366
30370
  };
@@ -31940,21 +31944,28 @@ var useChannelContainerClasses = function (_a) {
31940
31944
  };
31941
31945
 
31942
31946
  var getImageAttachmentConfiguration = function (attachment, element) {
31943
- var url = new URL((attachment.image_url || attachment.thumb_url || ''));
31944
- var resizeDimensions = getSizingRestrictions(url, element);
31945
- if (resizeDimensions) {
31946
- // Apply 2x for retina displays
31947
- resizeDimensions.height *= 2;
31948
- resizeDimensions.width *= 2;
31949
- addResizingParamsToUrl(resizeDimensions, url);
31947
+ var newUrl = undefined;
31948
+ var urlToTest = attachment.image_url || attachment.thumb_url || '';
31949
+ if (linkify__namespace.test(urlToTest, 'url')) {
31950
+ var url = new URL(urlToTest);
31951
+ var resizeDimensions = getSizingRestrictions(url, element);
31952
+ if (resizeDimensions) {
31953
+ // Apply 2x for retina displays
31954
+ resizeDimensions.height *= 2;
31955
+ resizeDimensions.width *= 2;
31956
+ addResizingParamsToUrl(resizeDimensions, url);
31957
+ }
31958
+ newUrl = url.href;
31950
31959
  }
31951
31960
  return {
31952
- url: url.href,
31961
+ url: newUrl || '',
31953
31962
  };
31954
31963
  };
31955
31964
  var getVideoAttachmentConfiguration = function (attachment, element, shouldGenerateVideoThumbnail) {
31956
31965
  var thumbUrl = undefined;
31957
- if (attachment.thumb_url && shouldGenerateVideoThumbnail) {
31966
+ if (attachment.thumb_url &&
31967
+ shouldGenerateVideoThumbnail &&
31968
+ linkify__namespace.test(attachment.thumb_url, 'url')) {
31958
31969
  var url = new URL(attachment.thumb_url);
31959
31970
  var resizeDimensions = getSizingRestrictions(url, element);
31960
31971
  if (resizeDimensions) {
@@ -33765,7 +33776,7 @@ var UnMemoizedChannelList = function (props) {
33765
33776
  */
33766
33777
  var ChannelList = React__default["default"].memo(UnMemoizedChannelList);
33767
33778
 
33768
- var version = '10.4.0';
33779
+ var version = '10.4.2';
33769
33780
 
33770
33781
  var useChat = function (_a) {
33771
33782
  var _b, _c;