stream-chat-react 12.0.0-rc.8 → 12.0.0-rc.9
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/components/Channel/Channel.js +19 -32
- package/dist/index.browser.cjs +19 -31
- package/dist/index.browser.cjs.map +2 -2
- package/dist/index.node.cjs +19 -31
- package/dist/index.node.cjs.map +2 -2
- package/package.json +2 -2
|
@@ -68,7 +68,11 @@ const ChannelInner = (props) => {
|
|
|
68
68
|
const [state, dispatch] = useReducer(channelReducer,
|
|
69
69
|
// channel.initialized === false if client.channel().query() was not called, e.g. ChannelList is not used
|
|
70
70
|
// => Channel will call channel.watch() in useLayoutEffect => state.loading is used to signal the watch() call state
|
|
71
|
-
{
|
|
71
|
+
{
|
|
72
|
+
...initialState,
|
|
73
|
+
hasMore: channel.state.messagePagination.hasPrev,
|
|
74
|
+
loading: !channel.initialized,
|
|
75
|
+
});
|
|
72
76
|
const isMounted = useIsMounted();
|
|
73
77
|
const originalTitle = useRef('');
|
|
74
78
|
const lastRead = useRef();
|
|
@@ -184,7 +188,6 @@ const ChannelInner = (props) => {
|
|
|
184
188
|
useLayoutEffect(() => {
|
|
185
189
|
let errored = false;
|
|
186
190
|
let done = false;
|
|
187
|
-
let channelInitializedExternally = true;
|
|
188
191
|
(async () => {
|
|
189
192
|
if (!channel.initialized && initializeOnMount) {
|
|
190
193
|
try {
|
|
@@ -210,7 +213,6 @@ const ChannelInner = (props) => {
|
|
|
210
213
|
await getChannel({ channel, client, members, options: channelQueryOptions });
|
|
211
214
|
const config = channel.getConfig();
|
|
212
215
|
setChannelConfig(config);
|
|
213
|
-
channelInitializedExternally = false;
|
|
214
216
|
}
|
|
215
217
|
catch (e) {
|
|
216
218
|
dispatch({ error: e, type: 'setError' });
|
|
@@ -222,8 +224,7 @@ const ChannelInner = (props) => {
|
|
|
222
224
|
if (!errored) {
|
|
223
225
|
dispatch({
|
|
224
226
|
channel,
|
|
225
|
-
hasMore:
|
|
226
|
-
hasMoreMessagesProbably(channel.state.messages.length, channelQueryOptions.messages.limit),
|
|
227
|
+
hasMore: channel.state.messagePagination.hasPrev,
|
|
227
228
|
type: 'initStateFromChannel',
|
|
228
229
|
});
|
|
229
230
|
if (client.user?.id && channel.state.read[client.user.id]) {
|
|
@@ -283,7 +284,7 @@ const ChannelInner = (props) => {
|
|
|
283
284
|
dispatch({ hasMore, messages, type: 'loadMoreFinished' });
|
|
284
285
|
}, 2000, { leading: true, trailing: true }), []);
|
|
285
286
|
const loadMore = async (limit = DEFAULT_NEXT_CHANNEL_PAGE_SIZE) => {
|
|
286
|
-
if (!online.current || !window.navigator.onLine || !state.
|
|
287
|
+
if (!online.current || !window.navigator.onLine || !channel.state.messagePagination.hasPrev)
|
|
287
288
|
return 0;
|
|
288
289
|
// prevent duplicate loading events...
|
|
289
290
|
const oldestMessage = state?.messages?.[0];
|
|
@@ -305,12 +306,11 @@ const ChannelInner = (props) => {
|
|
|
305
306
|
dispatch({ loadingMore: false, type: 'setLoadingMore' });
|
|
306
307
|
return 0;
|
|
307
308
|
}
|
|
308
|
-
|
|
309
|
-
loadMoreFinished(hasMoreMessages, channel.state.messages);
|
|
309
|
+
loadMoreFinished(channel.state.messagePagination.hasPrev, channel.state.messages);
|
|
310
310
|
return queryResponse.messages.length;
|
|
311
311
|
};
|
|
312
312
|
const loadMoreNewer = async (limit = DEFAULT_NEXT_CHANNEL_PAGE_SIZE) => {
|
|
313
|
-
if (!online.current || !window.navigator.onLine || !state.
|
|
313
|
+
if (!online.current || !window.navigator.onLine || !channel.state.messagePagination.hasNext)
|
|
314
314
|
return 0;
|
|
315
315
|
const newestMessage = state?.messages?.[state?.messages?.length - 1];
|
|
316
316
|
if (state.loadingMore || state.loadingMoreNewer)
|
|
@@ -330,9 +330,8 @@ const ChannelInner = (props) => {
|
|
|
330
330
|
dispatch({ loadingMoreNewer: false, type: 'setLoadingMoreNewer' });
|
|
331
331
|
return 0;
|
|
332
332
|
}
|
|
333
|
-
const hasMoreNewerMessages = channel.state.messages !== channel.state.latestMessages;
|
|
334
333
|
dispatch({
|
|
335
|
-
hasMoreNewer:
|
|
334
|
+
hasMoreNewer: channel.state.messagePagination.hasNext,
|
|
336
335
|
messages: channel.state.messages,
|
|
337
336
|
type: 'loadMoreNewerFinished',
|
|
338
337
|
});
|
|
@@ -342,15 +341,9 @@ const ChannelInner = (props) => {
|
|
|
342
341
|
const jumpToMessage = useCallback(async (messageId, messageLimit = DEFAULT_JUMP_TO_PAGE_SIZE, highlightDuration = DEFAULT_HIGHLIGHT_DURATION) => {
|
|
343
342
|
dispatch({ loadingMore: true, type: 'setLoadingMore' });
|
|
344
343
|
await channel.state.loadMessageIntoState(messageId, undefined, messageLimit);
|
|
345
|
-
|
|
346
|
-
* if the message we are jumping to has less than half of the page size older messages,
|
|
347
|
-
* we have jumped to the beginning of the channel.
|
|
348
|
-
*/
|
|
349
|
-
const indexOfMessage = channel.state.messages.findIndex((message) => message.id === messageId);
|
|
350
|
-
const hasMoreMessages = indexOfMessage >= Math.floor(messageLimit / 2);
|
|
351
|
-
loadMoreFinished(hasMoreMessages, channel.state.messages);
|
|
344
|
+
loadMoreFinished(channel.state.messagePagination.hasPrev, channel.state.messages);
|
|
352
345
|
dispatch({
|
|
353
|
-
hasMoreNewer: channel.state.
|
|
346
|
+
hasMoreNewer: channel.state.messagePagination.hasNext,
|
|
354
347
|
highlightedMessageId: messageId,
|
|
355
348
|
type: 'jumpToMessageFinished',
|
|
356
349
|
});
|
|
@@ -364,9 +357,7 @@ const ChannelInner = (props) => {
|
|
|
364
357
|
}, [channel, loadMoreFinished]);
|
|
365
358
|
const jumpToLatestMessage = useCallback(async () => {
|
|
366
359
|
await channel.state.loadMessageIntoState('latest');
|
|
367
|
-
|
|
368
|
-
const hasMoreOlder = channel.state.messages.length >= 25;
|
|
369
|
-
loadMoreFinished(hasMoreOlder, channel.state.messages);
|
|
360
|
+
loadMoreFinished(channel.state.messagePagination.hasPrev, channel.state.messages);
|
|
370
361
|
dispatch({
|
|
371
362
|
type: 'jumpToLatestMessage',
|
|
372
363
|
});
|
|
@@ -377,7 +368,6 @@ const ChannelInner = (props) => {
|
|
|
377
368
|
let lastReadMessageId = channelUnreadUiState?.last_read_message_id;
|
|
378
369
|
let firstUnreadMessageId = channelUnreadUiState?.first_unread_message_id;
|
|
379
370
|
let isInCurrentMessageSet = false;
|
|
380
|
-
let hasMoreMessages = true;
|
|
381
371
|
if (firstUnreadMessageId) {
|
|
382
372
|
const result = findInMsgSetById(firstUnreadMessageId, channel.state.messages);
|
|
383
373
|
isInCurrentMessageSet = result.index !== -1;
|
|
@@ -409,27 +399,25 @@ const ChannelInner = (props) => {
|
|
|
409
399
|
}
|
|
410
400
|
catch (e) {
|
|
411
401
|
addNotification(t('Failed to jump to the first unread message'), 'error');
|
|
412
|
-
loadMoreFinished(
|
|
402
|
+
loadMoreFinished(channel.state.messagePagination.hasPrev, channel.state.messages);
|
|
413
403
|
return;
|
|
414
404
|
}
|
|
415
405
|
const firstMessageWithCreationDate = messages.find((msg) => msg.created_at);
|
|
416
406
|
if (!firstMessageWithCreationDate) {
|
|
417
407
|
addNotification(t('Failed to jump to the first unread message'), 'error');
|
|
418
|
-
loadMoreFinished(
|
|
408
|
+
loadMoreFinished(channel.state.messagePagination.hasPrev, channel.state.messages);
|
|
419
409
|
return;
|
|
420
410
|
}
|
|
421
411
|
const firstMessageTimestamp = new Date(firstMessageWithCreationDate.created_at).getTime();
|
|
422
412
|
if (lastReadTimestamp < firstMessageTimestamp) {
|
|
423
413
|
// whole channel is unread
|
|
424
414
|
firstUnreadMessageId = firstMessageWithCreationDate.id;
|
|
425
|
-
hasMoreMessages = false;
|
|
426
415
|
}
|
|
427
416
|
else {
|
|
428
417
|
const result = findInMsgSetByDate(channelUnreadUiState.last_read, messages);
|
|
429
418
|
lastReadMessageId = result.target?.id;
|
|
430
|
-
hasMoreMessages = result.index >= Math.floor(queryMessageLimit / 2);
|
|
431
419
|
}
|
|
432
|
-
loadMoreFinished(
|
|
420
|
+
loadMoreFinished(channel.state.messagePagination.hasPrev, channel.state.messages);
|
|
433
421
|
}
|
|
434
422
|
}
|
|
435
423
|
if (!firstUnreadMessageId && !lastReadMessageId) {
|
|
@@ -446,14 +434,13 @@ const ChannelInner = (props) => {
|
|
|
446
434
|
* we have arrived to the oldest page of the channel
|
|
447
435
|
*/
|
|
448
436
|
const indexOfTarget = channel.state.messages.findIndex((message) => message.id === targetId);
|
|
449
|
-
|
|
450
|
-
loadMoreFinished(hasMoreMessages, channel.state.messages);
|
|
437
|
+
loadMoreFinished(channel.state.messagePagination.hasPrev, channel.state.messages);
|
|
451
438
|
firstUnreadMessageId =
|
|
452
439
|
firstUnreadMessageId ?? channel.state.messages[indexOfTarget + 1]?.id;
|
|
453
440
|
}
|
|
454
441
|
catch (e) {
|
|
455
442
|
addNotification(t('Failed to jump to the first unread message'), 'error');
|
|
456
|
-
loadMoreFinished(
|
|
443
|
+
loadMoreFinished(channel.state.messagePagination.hasPrev, channel.state.messages);
|
|
457
444
|
return;
|
|
458
445
|
}
|
|
459
446
|
}
|
|
@@ -468,7 +455,7 @@ const ChannelInner = (props) => {
|
|
|
468
455
|
last_read_message_id: lastReadMessageId,
|
|
469
456
|
});
|
|
470
457
|
dispatch({
|
|
471
|
-
hasMoreNewer: channel.state.
|
|
458
|
+
hasMoreNewer: channel.state.messagePagination.hasNext,
|
|
472
459
|
highlightedMessageId: firstUnreadMessageId,
|
|
473
460
|
type: 'jumpToMessageFinished',
|
|
474
461
|
});
|
package/dist/index.browser.cjs
CHANGED
|
@@ -44834,7 +44834,11 @@ var ChannelInner = (props) => {
|
|
|
44834
44834
|
channelReducer,
|
|
44835
44835
|
// channel.initialized === false if client.channel().query() was not called, e.g. ChannelList is not used
|
|
44836
44836
|
// => Channel will call channel.watch() in useLayoutEffect => state.loading is used to signal the watch() call state
|
|
44837
|
-
{
|
|
44837
|
+
{
|
|
44838
|
+
...initialState,
|
|
44839
|
+
hasMore: channel.state.messagePagination.hasPrev,
|
|
44840
|
+
loading: !channel.initialized
|
|
44841
|
+
}
|
|
44838
44842
|
);
|
|
44839
44843
|
const isMounted = useIsMounted();
|
|
44840
44844
|
const originalTitle = (0, import_react165.useRef)("");
|
|
@@ -44956,7 +44960,6 @@ var ChannelInner = (props) => {
|
|
|
44956
44960
|
(0, import_react165.useLayoutEffect)(() => {
|
|
44957
44961
|
let errored = false;
|
|
44958
44962
|
let done = false;
|
|
44959
|
-
let channelInitializedExternally = true;
|
|
44960
44963
|
(async () => {
|
|
44961
44964
|
if (!channel.initialized && initializeOnMount) {
|
|
44962
44965
|
try {
|
|
@@ -44978,7 +44981,6 @@ var ChannelInner = (props) => {
|
|
|
44978
44981
|
await getChannel({ channel, client, members, options: channelQueryOptions });
|
|
44979
44982
|
const config = channel.getConfig();
|
|
44980
44983
|
setChannelConfig(config);
|
|
44981
|
-
channelInitializedExternally = false;
|
|
44982
44984
|
} catch (e2) {
|
|
44983
44985
|
dispatch({ error: e2, type: "setError" });
|
|
44984
44986
|
errored = true;
|
|
@@ -44989,10 +44991,7 @@ var ChannelInner = (props) => {
|
|
|
44989
44991
|
if (!errored) {
|
|
44990
44992
|
dispatch({
|
|
44991
44993
|
channel,
|
|
44992
|
-
hasMore:
|
|
44993
|
-
channel.state.messages.length,
|
|
44994
|
-
channelQueryOptions.messages.limit
|
|
44995
|
-
),
|
|
44994
|
+
hasMore: channel.state.messagePagination.hasPrev,
|
|
44996
44995
|
type: "initStateFromChannel"
|
|
44997
44996
|
});
|
|
44998
44997
|
if (client.user?.id && channel.state.read[client.user.id]) {
|
|
@@ -45049,7 +45048,7 @@ var ChannelInner = (props) => {
|
|
|
45049
45048
|
[]
|
|
45050
45049
|
);
|
|
45051
45050
|
const loadMore = async (limit = DEFAULT_NEXT_CHANNEL_PAGE_SIZE) => {
|
|
45052
|
-
if (!online.current || !window.navigator.onLine || !state.
|
|
45051
|
+
if (!online.current || !window.navigator.onLine || !channel.state.messagePagination.hasPrev)
|
|
45053
45052
|
return 0;
|
|
45054
45053
|
const oldestMessage = state?.messages?.[0];
|
|
45055
45054
|
if (state.loadingMore || state.loadingMoreNewer || oldestMessage?.status !== "received") {
|
|
@@ -45069,12 +45068,11 @@ var ChannelInner = (props) => {
|
|
|
45069
45068
|
dispatch({ loadingMore: false, type: "setLoadingMore" });
|
|
45070
45069
|
return 0;
|
|
45071
45070
|
}
|
|
45072
|
-
|
|
45073
|
-
loadMoreFinished(hasMoreMessages, channel.state.messages);
|
|
45071
|
+
loadMoreFinished(channel.state.messagePagination.hasPrev, channel.state.messages);
|
|
45074
45072
|
return queryResponse.messages.length;
|
|
45075
45073
|
};
|
|
45076
45074
|
const loadMoreNewer = async (limit = DEFAULT_NEXT_CHANNEL_PAGE_SIZE) => {
|
|
45077
|
-
if (!online.current || !window.navigator.onLine || !state.
|
|
45075
|
+
if (!online.current || !window.navigator.onLine || !channel.state.messagePagination.hasNext)
|
|
45078
45076
|
return 0;
|
|
45079
45077
|
const newestMessage = state?.messages?.[state?.messages?.length - 1];
|
|
45080
45078
|
if (state.loadingMore || state.loadingMoreNewer)
|
|
@@ -45093,9 +45091,8 @@ var ChannelInner = (props) => {
|
|
|
45093
45091
|
dispatch({ loadingMoreNewer: false, type: "setLoadingMoreNewer" });
|
|
45094
45092
|
return 0;
|
|
45095
45093
|
}
|
|
45096
|
-
const hasMoreNewerMessages = channel.state.messages !== channel.state.latestMessages;
|
|
45097
45094
|
dispatch({
|
|
45098
|
-
hasMoreNewer:
|
|
45095
|
+
hasMoreNewer: channel.state.messagePagination.hasNext,
|
|
45099
45096
|
messages: channel.state.messages,
|
|
45100
45097
|
type: "loadMoreNewerFinished"
|
|
45101
45098
|
});
|
|
@@ -45106,13 +45103,9 @@ var ChannelInner = (props) => {
|
|
|
45106
45103
|
async (messageId, messageLimit = DEFAULT_JUMP_TO_PAGE_SIZE, highlightDuration = DEFAULT_HIGHLIGHT_DURATION) => {
|
|
45107
45104
|
dispatch({ loadingMore: true, type: "setLoadingMore" });
|
|
45108
45105
|
await channel.state.loadMessageIntoState(messageId, void 0, messageLimit);
|
|
45109
|
-
|
|
45110
|
-
(message) => message.id === messageId
|
|
45111
|
-
);
|
|
45112
|
-
const hasMoreMessages = indexOfMessage >= Math.floor(messageLimit / 2);
|
|
45113
|
-
loadMoreFinished(hasMoreMessages, channel.state.messages);
|
|
45106
|
+
loadMoreFinished(channel.state.messagePagination.hasPrev, channel.state.messages);
|
|
45114
45107
|
dispatch({
|
|
45115
|
-
hasMoreNewer: channel.state.
|
|
45108
|
+
hasMoreNewer: channel.state.messagePagination.hasNext,
|
|
45116
45109
|
highlightedMessageId: messageId,
|
|
45117
45110
|
type: "jumpToMessageFinished"
|
|
45118
45111
|
});
|
|
@@ -45128,8 +45121,7 @@ var ChannelInner = (props) => {
|
|
|
45128
45121
|
);
|
|
45129
45122
|
const jumpToLatestMessage = (0, import_react165.useCallback)(async () => {
|
|
45130
45123
|
await channel.state.loadMessageIntoState("latest");
|
|
45131
|
-
|
|
45132
|
-
loadMoreFinished(hasMoreOlder, channel.state.messages);
|
|
45124
|
+
loadMoreFinished(channel.state.messagePagination.hasPrev, channel.state.messages);
|
|
45133
45125
|
dispatch({
|
|
45134
45126
|
type: "jumpToLatestMessage"
|
|
45135
45127
|
});
|
|
@@ -45141,7 +45133,6 @@ var ChannelInner = (props) => {
|
|
|
45141
45133
|
let lastReadMessageId = channelUnreadUiState?.last_read_message_id;
|
|
45142
45134
|
let firstUnreadMessageId = channelUnreadUiState?.first_unread_message_id;
|
|
45143
45135
|
let isInCurrentMessageSet = false;
|
|
45144
|
-
let hasMoreMessages = true;
|
|
45145
45136
|
if (firstUnreadMessageId) {
|
|
45146
45137
|
const result = findInMsgSetById(firstUnreadMessageId, channel.state.messages);
|
|
45147
45138
|
isInCurrentMessageSet = result.index !== -1;
|
|
@@ -45175,13 +45166,13 @@ var ChannelInner = (props) => {
|
|
|
45175
45166
|
)).messages;
|
|
45176
45167
|
} catch (e2) {
|
|
45177
45168
|
addNotification(t2("Failed to jump to the first unread message"), "error");
|
|
45178
|
-
loadMoreFinished(
|
|
45169
|
+
loadMoreFinished(channel.state.messagePagination.hasPrev, channel.state.messages);
|
|
45179
45170
|
return;
|
|
45180
45171
|
}
|
|
45181
45172
|
const firstMessageWithCreationDate = messages.find((msg) => msg.created_at);
|
|
45182
45173
|
if (!firstMessageWithCreationDate) {
|
|
45183
45174
|
addNotification(t2("Failed to jump to the first unread message"), "error");
|
|
45184
|
-
loadMoreFinished(
|
|
45175
|
+
loadMoreFinished(channel.state.messagePagination.hasPrev, channel.state.messages);
|
|
45185
45176
|
return;
|
|
45186
45177
|
}
|
|
45187
45178
|
const firstMessageTimestamp = new Date(
|
|
@@ -45189,13 +45180,11 @@ var ChannelInner = (props) => {
|
|
|
45189
45180
|
).getTime();
|
|
45190
45181
|
if (lastReadTimestamp < firstMessageTimestamp) {
|
|
45191
45182
|
firstUnreadMessageId = firstMessageWithCreationDate.id;
|
|
45192
|
-
hasMoreMessages = false;
|
|
45193
45183
|
} else {
|
|
45194
45184
|
const result = findInMsgSetByDate(channelUnreadUiState.last_read, messages);
|
|
45195
45185
|
lastReadMessageId = result.target?.id;
|
|
45196
|
-
hasMoreMessages = result.index >= Math.floor(queryMessageLimit / 2);
|
|
45197
45186
|
}
|
|
45198
|
-
loadMoreFinished(
|
|
45187
|
+
loadMoreFinished(channel.state.messagePagination.hasPrev, channel.state.messages);
|
|
45199
45188
|
}
|
|
45200
45189
|
}
|
|
45201
45190
|
if (!firstUnreadMessageId && !lastReadMessageId) {
|
|
@@ -45210,12 +45199,11 @@ var ChannelInner = (props) => {
|
|
|
45210
45199
|
const indexOfTarget = channel.state.messages.findIndex(
|
|
45211
45200
|
(message) => message.id === targetId
|
|
45212
45201
|
);
|
|
45213
|
-
|
|
45214
|
-
loadMoreFinished(hasMoreMessages, channel.state.messages);
|
|
45202
|
+
loadMoreFinished(channel.state.messagePagination.hasPrev, channel.state.messages);
|
|
45215
45203
|
firstUnreadMessageId = firstUnreadMessageId ?? channel.state.messages[indexOfTarget + 1]?.id;
|
|
45216
45204
|
} catch (e2) {
|
|
45217
45205
|
addNotification(t2("Failed to jump to the first unread message"), "error");
|
|
45218
|
-
loadMoreFinished(
|
|
45206
|
+
loadMoreFinished(channel.state.messagePagination.hasPrev, channel.state.messages);
|
|
45219
45207
|
return;
|
|
45220
45208
|
}
|
|
45221
45209
|
}
|
|
@@ -45230,7 +45218,7 @@ var ChannelInner = (props) => {
|
|
|
45230
45218
|
last_read_message_id: lastReadMessageId
|
|
45231
45219
|
});
|
|
45232
45220
|
dispatch({
|
|
45233
|
-
hasMoreNewer: channel.state.
|
|
45221
|
+
hasMoreNewer: channel.state.messagePagination.hasNext,
|
|
45234
45222
|
highlightedMessageId: firstUnreadMessageId,
|
|
45235
45223
|
type: "jumpToMessageFinished"
|
|
45236
45224
|
});
|