stream-chat-react 10.7.2 → 10.7.4
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/browser.full-bundle.js +93 -52
- package/dist/browser.full-bundle.js.map +1 -1
- package/dist/browser.full-bundle.min.js +3 -3
- package/dist/browser.full-bundle.min.js.map +1 -1
- package/dist/components/Channel/Channel.d.ts.map +1 -1
- package/dist/components/Channel/Channel.js +69 -46
- package/dist/components/MessageList/hooks/usePrependMessagesCount.d.ts.map +1 -1
- package/dist/components/MessageList/hooks/usePrependMessagesCount.js +22 -4
- package/dist/index.cjs.js +92 -51
- package/dist/index.cjs.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -46653,55 +46653,78 @@ var StreamChatReact = (function (exports, React$2, streamChat, ReactDOM) {
|
|
|
46653
46653
|
}
|
|
46654
46654
|
};
|
|
46655
46655
|
var markReadThrottled = lodash_throttle(markRead, 500, { leading: true, trailing: true });
|
|
46656
|
-
var handleEvent = function (event) {
|
|
46657
|
-
var
|
|
46658
|
-
|
|
46659
|
-
|
|
46660
|
-
|
|
46661
|
-
|
|
46662
|
-
|
|
46663
|
-
|
|
46664
|
-
|
|
46665
|
-
|
|
46666
|
-
|
|
46667
|
-
|
|
46668
|
-
return dispatch({ channel: channel, type: 'setTyping' });
|
|
46669
|
-
}
|
|
46670
|
-
if (event.type === 'connection.changed' && typeof event.online === 'boolean') {
|
|
46671
|
-
online.current = event.online;
|
|
46672
|
-
}
|
|
46673
|
-
if (event.type === 'message.new') {
|
|
46674
|
-
var mainChannelUpdated = true;
|
|
46675
|
-
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)) {
|
|
46676
|
-
mainChannelUpdated = false;
|
|
46677
|
-
}
|
|
46678
|
-
if (mainChannelUpdated && ((_d = (_c = event.message) === null || _c === void 0 ? void 0 : _c.user) === null || _d === void 0 ? void 0 : _d.id) !== client.userID) {
|
|
46679
|
-
if (!document.hidden) {
|
|
46680
|
-
markReadThrottled();
|
|
46681
|
-
}
|
|
46682
|
-
else if ((channelConfig === null || channelConfig === void 0 ? void 0 : channelConfig.read_events) && !channel.muteStatus().muted) {
|
|
46683
|
-
var unread = channel.countUnread(lastRead.current);
|
|
46684
|
-
if (activeUnreadHandler) {
|
|
46685
|
-
activeUnreadHandler(unread, originalTitle.current);
|
|
46656
|
+
var handleEvent = function (event) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
46657
|
+
var mainChannelUpdated, unread, messageDate, cid, oldestID;
|
|
46658
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
46659
|
+
return __generator$1(this, function (_m) {
|
|
46660
|
+
switch (_m.label) {
|
|
46661
|
+
case 0:
|
|
46662
|
+
if (event.message) {
|
|
46663
|
+
dispatch({
|
|
46664
|
+
channel: channel,
|
|
46665
|
+
message: event.message,
|
|
46666
|
+
type: 'updateThreadOnEvent',
|
|
46667
|
+
});
|
|
46686
46668
|
}
|
|
46687
|
-
|
|
46688
|
-
|
|
46669
|
+
if (event.type === 'user.watching.start' || event.type === 'user.watching.stop')
|
|
46670
|
+
return [2 /*return*/];
|
|
46671
|
+
if (event.type === 'typing.start' || event.type === 'typing.stop') {
|
|
46672
|
+
return [2 /*return*/, dispatch({ channel: channel, type: 'setTyping' })];
|
|
46689
46673
|
}
|
|
46690
|
-
|
|
46691
|
-
|
|
46692
|
-
|
|
46693
|
-
|
|
46694
|
-
|
|
46695
|
-
|
|
46696
|
-
|
|
46697
|
-
|
|
46698
|
-
|
|
46699
|
-
|
|
46700
|
-
|
|
46674
|
+
if (event.type === 'connection.changed' && typeof event.online === 'boolean') {
|
|
46675
|
+
online.current = event.online;
|
|
46676
|
+
}
|
|
46677
|
+
if (event.type === 'message.new') {
|
|
46678
|
+
mainChannelUpdated = true;
|
|
46679
|
+
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)) {
|
|
46680
|
+
mainChannelUpdated = false;
|
|
46681
|
+
}
|
|
46682
|
+
if (mainChannelUpdated && ((_d = (_c = event.message) === null || _c === void 0 ? void 0 : _c.user) === null || _d === void 0 ? void 0 : _d.id) !== client.userID) {
|
|
46683
|
+
if (!document.hidden) {
|
|
46684
|
+
markReadThrottled();
|
|
46685
|
+
}
|
|
46686
|
+
else if ((channelConfig === null || channelConfig === void 0 ? void 0 : channelConfig.read_events) && !channel.muteStatus().muted) {
|
|
46687
|
+
unread = channel.countUnread(lastRead.current);
|
|
46688
|
+
if (activeUnreadHandler) {
|
|
46689
|
+
activeUnreadHandler(unread, originalTitle.current);
|
|
46690
|
+
}
|
|
46691
|
+
else {
|
|
46692
|
+
document.title = "(".concat(unread, ") ").concat(originalTitle.current);
|
|
46693
|
+
}
|
|
46694
|
+
}
|
|
46695
|
+
}
|
|
46696
|
+
if (((_f = (_e = event.message) === null || _e === void 0 ? void 0 : _e.user) === null || _f === void 0 ? void 0 : _f.id) === client.userID &&
|
|
46697
|
+
((_g = event === null || event === void 0 ? void 0 : event.message) === null || _g === void 0 ? void 0 : _g.created_at) &&
|
|
46698
|
+
((_h = event === null || event === void 0 ? void 0 : event.message) === null || _h === void 0 ? void 0 : _h.cid)) {
|
|
46699
|
+
messageDate = new Date(event.message.created_at);
|
|
46700
|
+
cid = event.message.cid;
|
|
46701
|
+
if (!latestMessageDatesByChannels[cid] ||
|
|
46702
|
+
latestMessageDatesByChannels[cid].getTime() < messageDate.getTime()) {
|
|
46703
|
+
latestMessageDatesByChannels[cid] = messageDate;
|
|
46704
|
+
}
|
|
46705
|
+
}
|
|
46706
|
+
}
|
|
46707
|
+
if (!(event.type === 'user.deleted')) return [3 /*break*/, 2];
|
|
46708
|
+
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;
|
|
46709
|
+
/**
|
|
46710
|
+
* 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.
|
|
46711
|
+
*/
|
|
46712
|
+
return [4 /*yield*/, channel.query({
|
|
46713
|
+
messages: { id_lt: oldestID, limit: DEFAULT_NEXT_CHANNEL_PAGE_SIZE },
|
|
46714
|
+
watchers: { limit: DEFAULT_NEXT_CHANNEL_PAGE_SIZE },
|
|
46715
|
+
})];
|
|
46716
|
+
case 1:
|
|
46717
|
+
/**
|
|
46718
|
+
* 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.
|
|
46719
|
+
*/
|
|
46720
|
+
_m.sent();
|
|
46721
|
+
_m.label = 2;
|
|
46722
|
+
case 2:
|
|
46723
|
+
throttledCopyStateFromChannel();
|
|
46724
|
+
return [2 /*return*/];
|
|
46701
46725
|
}
|
|
46702
|
-
}
|
|
46703
|
-
|
|
46704
|
-
};
|
|
46726
|
+
});
|
|
46727
|
+
}); };
|
|
46705
46728
|
// useLayoutEffect here to prevent spinner. Use Suspense when it is available in stable release
|
|
46706
46729
|
React$2.useLayoutEffect(function () {
|
|
46707
46730
|
var errored = false;
|
|
@@ -48355,7 +48378,7 @@ var StreamChatReact = (function (exports, React$2, streamChat, ReactDOM) {
|
|
|
48355
48378
|
|
|
48356
48379
|
window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};
|
|
48357
48380
|
|
|
48358
|
-
window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var version$1 = '10.7.
|
|
48381
|
+
window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var version$1 = '10.7.4';
|
|
48359
48382
|
|
|
48360
48383
|
window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var useChat = function (_a) {
|
|
48361
48384
|
var _b, _c;
|
|
@@ -51180,13 +51203,14 @@ var StreamChatReact = (function (exports, React$2, streamChat, ReactDOM) {
|
|
|
51180
51203
|
};
|
|
51181
51204
|
}
|
|
51182
51205
|
|
|
51183
|
-
window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};
|
|
51206
|
+
window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var STATUSES_EXCLUDED_FROM_PREPEND = ['sending', 'failed'];
|
|
51207
|
+
function usePrependedMessagesCount(messages, hasDateSeparator) {
|
|
51184
51208
|
var firstRealMessageIndex = hasDateSeparator ? 1 : 0;
|
|
51185
51209
|
var firstMessageId = React$2.useRef();
|
|
51186
51210
|
var earliestMessageId = React$2.useRef();
|
|
51187
51211
|
var previousNumItemsPrepended = React$2.useRef(0);
|
|
51188
51212
|
var numItemsPrepended = React$2.useMemo(function () {
|
|
51189
|
-
var _a;
|
|
51213
|
+
var _a, _b;
|
|
51190
51214
|
if (!messages || !messages.length) {
|
|
51191
51215
|
previousNumItemsPrepended.current = 0;
|
|
51192
51216
|
return 0;
|
|
@@ -51202,13 +51226,30 @@ var StreamChatReact = (function (exports, React$2, streamChat, ReactDOM) {
|
|
|
51202
51226
|
earliestMessageId.current = currentFirstMessageId;
|
|
51203
51227
|
// if new messages were prepended, find out how many
|
|
51204
51228
|
// start with this number because there cannot be fewer prepended items than before
|
|
51229
|
+
var adjustPrependedMessageCount = 0;
|
|
51205
51230
|
for (var i = previousNumItemsPrepended.current; i < messages.length; i += 1) {
|
|
51231
|
+
// Optimistic UI update, when sending messages, can lead to a situation, when
|
|
51232
|
+
// the order of the messages changes for a moment. This can happen, when a user
|
|
51233
|
+
// sends multiple messages withing few milliseconds. E.g. we send a message A
|
|
51234
|
+
// then message B. At first we have message array with both messages of status "sending"
|
|
51235
|
+
// then response for message A is received with a new - later - created_at timestamp
|
|
51236
|
+
// this leads to rearrangement of 1.B ("sending"), 2.A ("received"). Still firstMessageId.current
|
|
51237
|
+
// points to message A, but now this message has index 1 => previousNumItemsPrepended.current === 1
|
|
51238
|
+
// That in turn leads to incorrect index calculation in VirtualizedMessageList trying to access a message
|
|
51239
|
+
// at non-existent index. Therefore, we ignore messages of status "sending" / "failed" in order they are
|
|
51240
|
+
// not considered as prepended messages.
|
|
51241
|
+
if (((_b = messages[i]) === null || _b === void 0 ? void 0 : _b.status) &&
|
|
51242
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
51243
|
+
STATUSES_EXCLUDED_FROM_PREPEND.includes(messages[i].status) &&
|
|
51244
|
+
messages[i].id !== firstMessageId.current) {
|
|
51245
|
+
adjustPrependedMessageCount++;
|
|
51246
|
+
}
|
|
51206
51247
|
if (messages[i].id === firstMessageId.current) {
|
|
51207
|
-
previousNumItemsPrepended.current = i;
|
|
51208
|
-
return
|
|
51248
|
+
previousNumItemsPrepended.current = i - adjustPrependedMessageCount;
|
|
51249
|
+
return previousNumItemsPrepended.current;
|
|
51209
51250
|
}
|
|
51210
51251
|
}
|
|
51211
|
-
// if no match has found, we have jumped - reset the
|
|
51252
|
+
// if no match has found, we have jumped - reset the prepended item count.
|
|
51212
51253
|
firstMessageId.current = currentFirstMessageId;
|
|
51213
51254
|
previousNumItemsPrepended.current = 0;
|
|
51214
51255
|
return 0;
|