stream-chat-react 10.8.4 → 10.8.5

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":"useCooldownTimer.d.ts","sourceRoot":"","sources":["../../../../src/components/MessageInput/hooks/useCooldownTimer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAO5D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAEtE,oBAAY,kBAAkB,GAAG;IAC/B,gBAAgB,EAAE,MAAM,CAAC;IACzB,oBAAoB,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;IAC/E,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,eAAO,MAAM,gBAAgB,0FAExB,kBAmCJ,CAAC"}
1
+ {"version":3,"file":"useCooldownTimer.d.ts","sourceRoot":"","sources":["../../../../src/components/MessageInput/hooks/useCooldownTimer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAK5D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAEtE,oBAAY,kBAAkB,GAAG;IAC/B,gBAAgB,EAAE,MAAM,CAAC;IACzB,oBAAoB,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;IAC/E,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,eAAO,MAAM,gBAAgB,0FAExB,kBAsCJ,CAAC"}
@@ -8,31 +8,30 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
8
8
  return to.concat(ar || Array.prototype.slice.call(from));
9
9
  };
10
10
  import { useEffect, useMemo, useState } from 'react';
11
- import { useChatContext } from '../../../context/ChatContext';
12
- import { useChannelStateContext } from '../../../context/ChannelStateContext';
11
+ import { useChannelStateContext, useChatContext } from '../../../context';
13
12
  export var useCooldownTimer = function () {
14
13
  var _a;
15
- var latestMessageDatesByChannels = useChatContext('useCooldownTimer').latestMessageDatesByChannels;
16
- var _b = useChannelStateContext('useCooldownTimer'), channel = _b.channel, _c = _b.messages, messages = _c === void 0 ? [] : _c;
17
- var client = useChatContext('useCooldownTimer').client;
18
- var _d = useState(), cooldownRemaining = _d[0], setCooldownRemaining = _d[1];
19
- var _e = (channel.data ||
20
- {}), cooldownInterval = _e.cooldown, own_capabilities = _e.own_capabilities;
21
- var skipCooldown = !(own_capabilities === null || own_capabilities === void 0 ? void 0 : own_capabilities.includes('slow-mode'));
14
+ var _b = useChatContext('useCooldownTimer'), client = _b.client, latestMessageDatesByChannels = _b.latestMessageDatesByChannels;
15
+ var _c = useChannelStateContext('useCooldownTimer'), channel = _c.channel, _d = _c.messages, messages = _d === void 0 ? [] : _d;
16
+ var _e = useState(), cooldownRemaining = _e[0], setCooldownRemaining = _e[1];
17
+ var _f = (channel.data ||
18
+ {}), _g = _f.cooldown, cooldownInterval = _g === void 0 ? 0 : _g, own_capabilities = _f.own_capabilities;
19
+ var skipCooldown = own_capabilities === null || own_capabilities === void 0 ? void 0 : own_capabilities.includes('skip-slow-mode');
22
20
  var ownLatestMessageDate = useMemo(function () {
23
21
  var _a, _b;
24
22
  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()); })
25
23
  .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;
26
24
  }, [messages, (_a = client.user) === null || _a === void 0 ? void 0 : _a.id, latestMessageDatesByChannels, channel.cid]);
27
25
  useEffect(function () {
28
- if (skipCooldown || !cooldownInterval || !ownLatestMessageDate)
29
- return;
30
- var remainingCooldown = Math.round(cooldownInterval - (new Date().getTime() - ownLatestMessageDate.getTime()) / 1000);
31
- if (remainingCooldown > 0)
32
- setCooldownRemaining(remainingCooldown);
26
+ var timeSinceOwnLastMessage = ownLatestMessageDate
27
+ ? (new Date().getTime() - ownLatestMessageDate.getTime()) / 1000
28
+ : undefined;
29
+ setCooldownRemaining(!skipCooldown && timeSinceOwnLastMessage && cooldownInterval > timeSinceOwnLastMessage
30
+ ? Math.round(cooldownInterval - timeSinceOwnLastMessage)
31
+ : 0);
33
32
  }, [cooldownInterval, ownLatestMessageDate, skipCooldown]);
34
33
  return {
35
- cooldownInterval: cooldownInterval !== null && cooldownInterval !== void 0 ? cooldownInterval : 0,
34
+ cooldownInterval: cooldownInterval,
36
35
  cooldownRemaining: cooldownRemaining,
37
36
  setCooldownRemaining: setCooldownRemaining,
38
37
  };
package/dist/index.cjs.js CHANGED
@@ -30285,27 +30285,27 @@ var EditMessageForm = function () {
30285
30285
 
30286
30286
  var useCooldownTimer = function () {
30287
30287
  var _a;
30288
- var latestMessageDatesByChannels = useChatContext('useCooldownTimer').latestMessageDatesByChannels;
30289
- var _b = useChannelStateContext('useCooldownTimer'), channel = _b.channel, _c = _b.messages, messages = _c === void 0 ? [] : _c;
30290
- var client = useChatContext('useCooldownTimer').client;
30291
- var _d = React.useState(), cooldownRemaining = _d[0], setCooldownRemaining = _d[1];
30292
- var _e = (channel.data ||
30293
- {}), cooldownInterval = _e.cooldown, own_capabilities = _e.own_capabilities;
30294
- var skipCooldown = !(own_capabilities === null || own_capabilities === void 0 ? void 0 : own_capabilities.includes('slow-mode'));
30288
+ var _b = useChatContext('useCooldownTimer'), client = _b.client, latestMessageDatesByChannels = _b.latestMessageDatesByChannels;
30289
+ var _c = useChannelStateContext('useCooldownTimer'), channel = _c.channel, _d = _c.messages, messages = _d === void 0 ? [] : _d;
30290
+ var _e = React.useState(), cooldownRemaining = _e[0], setCooldownRemaining = _e[1];
30291
+ var _f = (channel.data ||
30292
+ {}), _g = _f.cooldown, cooldownInterval = _g === void 0 ? 0 : _g, own_capabilities = _f.own_capabilities;
30293
+ var skipCooldown = own_capabilities === null || own_capabilities === void 0 ? void 0 : own_capabilities.includes('skip-slow-mode');
30295
30294
  var ownLatestMessageDate = React.useMemo(function () {
30296
30295
  var _a, _b;
30297
30296
  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()); })
30298
30297
  .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;
30299
30298
  }, [messages, (_a = client.user) === null || _a === void 0 ? void 0 : _a.id, latestMessageDatesByChannels, channel.cid]);
30300
30299
  React.useEffect(function () {
30301
- if (skipCooldown || !cooldownInterval || !ownLatestMessageDate)
30302
- return;
30303
- var remainingCooldown = Math.round(cooldownInterval - (new Date().getTime() - ownLatestMessageDate.getTime()) / 1000);
30304
- if (remainingCooldown > 0)
30305
- setCooldownRemaining(remainingCooldown);
30300
+ var timeSinceOwnLastMessage = ownLatestMessageDate
30301
+ ? (new Date().getTime() - ownLatestMessageDate.getTime()) / 1000
30302
+ : undefined;
30303
+ setCooldownRemaining(!skipCooldown && timeSinceOwnLastMessage && cooldownInterval > timeSinceOwnLastMessage
30304
+ ? Math.round(cooldownInterval - timeSinceOwnLastMessage)
30305
+ : 0);
30306
30306
  }, [cooldownInterval, ownLatestMessageDate, skipCooldown]);
30307
30307
  return {
30308
- cooldownInterval: cooldownInterval !== null && cooldownInterval !== void 0 ? cooldownInterval : 0,
30308
+ cooldownInterval: cooldownInterval,
30309
30309
  cooldownRemaining: cooldownRemaining,
30310
30310
  setCooldownRemaining: setCooldownRemaining,
30311
30311
  };
@@ -33777,7 +33777,7 @@ var UnMemoizedChannelList = function (props) {
33777
33777
  */
33778
33778
  var ChannelList = React__default["default"].memo(UnMemoizedChannelList);
33779
33779
 
33780
- var version = '10.8.4';
33780
+ var version = '10.8.5';
33781
33781
 
33782
33782
  var useChat = function (_a) {
33783
33783
  var _b, _c;