Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mark as read messages sent by current user #2211

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/components/Channel/Channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ const ChannelInner = <
mainChannelUpdated = false;
}

if (mainChannelUpdated && event.message?.user?.id !== client.userID) {
if (mainChannelUpdated) {
if (!document.hidden) {
markReadThrottled();
} else if (channelConfig?.read_events && !channel.muteStatus().muted) {
Expand Down Expand Up @@ -536,6 +536,14 @@ const ChannelInner = <
),
type: 'initStateFromChannel',
});

/**
* TODO: maybe pass last_read to the countUnread method to get proper value
* combined with channel.countUnread adjustment (_countMessageAsUnread)
* to allow counting own messages too
*
* const lastRead = channel.state.read[client.userID as string].last_read;
*/
if (channel.countUnread() > 0) markRead();
// The more complex sync logic is done in Chat
document.addEventListener('visibilitychange', onVisibilityChange);
Expand Down
14 changes: 14 additions & 0 deletions src/components/Channel/__tests__/Channel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,20 @@ describe('Channel', () => {
await waitFor(() => expect(markReadSpy).toHaveBeenCalledWith());
});

it('should mark the channel as read if a new message current user comes in and the user is looking at the page', async () => {
arnautov-anton marked this conversation as resolved.
Show resolved Hide resolved
const { channel, chatClient } = await initClient();
const markReadSpy = jest.spyOn(channel, 'markRead');

const message = generateMessage({ user: generateUser() });
const dispatchMessageEvent = createChannelEventDispatcher({ message }, chatClient, channel);

renderComponent({ channel, chatClient }, () => {
dispatchMessageEvent();
});

await waitFor(() => expect(markReadSpy).toHaveBeenCalledWith());
});

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 () => {
const { channel, chatClient } = await initClient();
const unreadAmount = 1;
Expand Down
Loading