Skip to content

Commit 3f4b876

Browse files
committed
fix: prevent increasing unread count by useMarkRead hook if read-events are disabled (#2925)
(cherry picked from commit d0e7b5f)
1 parent 2cfc89b commit 3f4b876

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

src/components/MessageList/hooks/__tests__/useMarkRead.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const readLastMessageChannelData = () => {
5959
generateMessage({ created_at: new Date(2) }),
6060
];
6161
return {
62+
channel: { config: { read_events: true } },
6263
messages,
6364
read: [
6465
{
@@ -390,6 +391,35 @@ describe('useMarkRead', () => {
390391
expect(markRead).not.toHaveBeenCalled();
391392
});
392393

394+
it('should not increase unread count if the read events are disabled', async () => {
395+
const channelData = {
396+
...readLastMessageChannelData(),
397+
channel: { config: { read_events: false } },
398+
};
399+
const {
400+
channels: [channel],
401+
client,
402+
} = await initClientWithChannels({
403+
channelsData: [channelData],
404+
customUser: channelData.read[0].user,
405+
});
406+
407+
await render({
408+
channel,
409+
client,
410+
params: {
411+
...shouldMarkReadParams,
412+
isMessageListScrolledToBottom: false,
413+
},
414+
});
415+
416+
await act(() => {
417+
dispatchMessageNewEvent(client, generateMessage(), channel);
418+
});
419+
expect(setChannelUnreadUiState).toHaveBeenCalledTimes(0);
420+
expect(markRead).not.toHaveBeenCalled();
421+
});
422+
393423
it('should not mark channel read from thread message list', async () => {
394424
const channelData = readLastMessageChannelData();
395425
const {

src/components/MessageList/hooks/useMarkRead.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export const useMarkRead = ({
3737
const { channel } = useChannelStateContext('useMarkRead');
3838

3939
useEffect(() => {
40+
if (!channel.getConfig()?.read_events) return;
4041
const shouldMarkRead = () =>
4142
!document.hidden &&
4243
!wasMarkedUnread &&

0 commit comments

Comments
 (0)