stream-chat-react 10.4.1 → 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.
@@ -1 +1 @@
1
- {"version":3,"file":"useCooldownTimer.d.ts","sourceRoot":"","sources":["../../../../src/components/MessageInput/hooks/useCooldownTimer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAOnD,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,kBA6BJ,CAAC"}
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,25 +1,38 @@
1
- import { useEffect, useState } from 'react';
1
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
+ if (ar || !(i in from)) {
4
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5
+ ar[i] = from[i];
6
+ }
7
+ }
8
+ return to.concat(ar || Array.prototype.slice.call(from));
9
+ };
10
+ import { useEffect, useMemo, useState } from 'react';
2
11
  import { useChatContext } from '../../../context/ChatContext';
3
12
  import { useChannelStateContext } from '../../../context/ChannelStateContext';
4
13
  export var useCooldownTimer = function () {
14
+ var _a;
5
15
  var latestMessageDatesByChannels = useChatContext('useCooldownTimer').latestMessageDatesByChannels;
6
- var channel = useChannelStateContext('useCooldownTimer').channel;
7
- var _a = (channel.data ||
8
- {}), cooldownInterval = _a.cooldown, own_capabilities = _a.own_capabilities;
9
- var _b = useState(), cooldownRemaining = _b[0], setCooldownRemaining = _b[1];
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;
10
21
  var skipCooldown = !(own_capabilities === null || own_capabilities === void 0 ? void 0 : own_capabilities.includes('slow-mode'));
22
+ var ownLatestMessageDate = useMemo(function () {
23
+ var _a, _b;
24
+ 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
+ .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
+ }, [messages, (_a = client.user) === null || _a === void 0 ? void 0 : _a.id, latestMessageDatesByChannels, channel.cid]);
11
27
  useEffect(function () {
12
- var latestMessageDate = latestMessageDatesByChannels[channel.cid];
13
- if (!cooldownInterval || !latestMessageDate) {
28
+ if (skipCooldown || !cooldownInterval || !ownLatestMessageDate)
14
29
  return;
15
- }
16
- var remainingCooldown = Math.round(cooldownInterval - (new Date().getTime() - latestMessageDate.getTime()) / 1000);
17
- if (remainingCooldown > 0 && !skipCooldown) {
30
+ var remainingCooldown = Math.round(cooldownInterval - (new Date().getTime() - ownLatestMessageDate.getTime()) / 1000);
31
+ if (remainingCooldown > 0)
18
32
  setCooldownRemaining(remainingCooldown);
19
- }
20
- }, [channel.id, cooldownInterval, latestMessageDatesByChannels[channel.cid]]);
33
+ }, [cooldownInterval, ownLatestMessageDate, skipCooldown]);
21
34
  return {
22
- cooldownInterval: cooldownInterval || 0,
35
+ cooldownInterval: cooldownInterval !== null && cooldownInterval !== void 0 ? cooldownInterval : 0,
23
36
  cooldownRemaining: cooldownRemaining,
24
37
  setCooldownRemaining: setCooldownRemaining,
25
38
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useUserTrigger.d.ts","sourceRoot":"","sources":["../../../../src/components/MessageInput/hooks/useUserTrigger.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAC;AACpF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAC;AAEpF,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAEtE,oBAAY,iBAAiB,CAC3B,kBAAkB,SAAS,yBAAyB,GAAG,yBAAyB,IAC9E;IACF,YAAY,EAAE,CAAC,IAAI,EAAE,YAAY,CAAC,kBAAkB,CAAC,KAAK,IAAI,CAAC;IAC/D,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,kBAAkB,CAAC,EAAE,iBAAiB,CAAC,kBAAkB,CAAC,CAAC,aAAa,CAAC,CAAC;IAC1E,0BAA0B,CAAC,EAAE,OAAO,CAAC;CACtC,CAAC;AAEF,eAAO,MAAM,cAAc,6KAgK1B,CAAC"}
1
+ {"version":3,"file":"useUserTrigger.d.ts","sourceRoot":"","sources":["../../../../src/components/MessageInput/hooks/useUserTrigger.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAC;AACpF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAC;AAEpF,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAEtE,oBAAY,iBAAiB,CAC3B,kBAAkB,SAAS,yBAAyB,GAAG,yBAAyB,IAC9E;IACF,YAAY,EAAE,CAAC,IAAI,EAAE,YAAY,CAAC,kBAAkB,CAAC,KAAK,IAAI,CAAC;IAC/D,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,kBAAkB,CAAC,EAAE,iBAAiB,CAAC,kBAAkB,CAAC,CAAC,aAAa,CAAC,CAAC;IAC1E,0BAA0B,CAAC,EAAE,OAAO,CAAC;CACtC,CAAC;AAEF,eAAO,MAAM,cAAc,6KAkK1B,CAAC"}
@@ -121,7 +121,8 @@ export var useUserTrigger = function (params) {
121
121
  _a.label = 1;
122
122
  case 1:
123
123
  _a.trys.push([1, 3, , 4]);
124
- 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))];
124
+ return [4 /*yield*/, client.queryUsers(__assign({ $or: [{ id: { $autocomplete: query } }, { name: { $autocomplete: query } }], id: { $ne: client.userID } }, mentionQueryParams.filters), Array.isArray(mentionQueryParams.sort)
125
+ ? __spreadArray([{ id: 1 }], mentionQueryParams.sort, true) : __assign({ id: 1 }, mentionQueryParams.sort), __assign({ limit: 10 }, mentionQueryParams.options))];
125
126
  case 2:
126
127
  users = (_a.sent()).users;
127
128
  if (onReady && users.length) {