Skip to content

Commit 38f2363

Browse files
fix: mark as read messages sent by current user (#2211)
### 🎯 Goal Adjusts Channel behavior to mark as read messages sent by current user as well, this adjustment is made to match the behavior of Angular SDK. --------- Co-authored-by: MartinCupela <[email protected]>
1 parent 409db05 commit 38f2363

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/components/Channel/Channel.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ const ChannelInner = <
438438
mainChannelUpdated = false;
439439
}
440440

441-
if (mainChannelUpdated && event.message?.user?.id !== client.userID) {
441+
if (mainChannelUpdated) {
442442
if (!document.hidden) {
443443
markReadThrottled();
444444
} else if (channelConfig?.read_events && !channel.muteStatus().muted) {
@@ -536,6 +536,14 @@ const ChannelInner = <
536536
),
537537
type: 'initStateFromChannel',
538538
});
539+
540+
/**
541+
* TODO: maybe pass last_read to the countUnread method to get proper value
542+
* combined with channel.countUnread adjustment (_countMessageAsUnread)
543+
* to allow counting own messages too
544+
*
545+
* const lastRead = channel.state.read[client.userID as string].last_read;
546+
*/
539547
if (channel.countUnread() > 0) markRead();
540548
// The more complex sync logic is done in Chat
541549
document.addEventListener('visibilitychange', onVisibilityChange);

src/components/Channel/__tests__/Channel.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,20 @@ describe('Channel', () => {
13471347
await waitFor(() => expect(markReadSpy).toHaveBeenCalledWith());
13481348
});
13491349

1350+
it('should mark the channel as read if the new message author is the current user and the user is looking at the page', async () => {
1351+
const { channel, chatClient } = await initClient();
1352+
const markReadSpy = jest.spyOn(channel, 'markRead');
1353+
1354+
const message = generateMessage({ user: generateUser() });
1355+
const dispatchMessageEvent = createChannelEventDispatcher({ message }, chatClient, channel);
1356+
1357+
renderComponent({ channel, chatClient }, () => {
1358+
dispatchMessageEvent();
1359+
});
1360+
1361+
await waitFor(() => expect(markReadSpy).toHaveBeenCalledWith());
1362+
});
1363+
13501364
it('title of the page should include the unread count if the user is not looking at the page when a new message event happens', async () => {
13511365
const { channel, chatClient } = await initClient();
13521366
const unreadAmount = 1;

0 commit comments

Comments
 (0)