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: Prevent marking messages as read when tab inactive #1927

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
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
4 changes: 4 additions & 0 deletions src/client/action/notifications.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { MatrixClient } from "matrix-js-sdk";

export async function markAsRead(mx: MatrixClient, roomId: string) {
// Won't mark messages (or whatever in room) as read when tab inactive
// or when browser is inactive (i.e. user interacts with some another app)
if (document.hidden || !document.hasFocus()) return;

Comment on lines +4 to +7
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like a wrong place to add such conditioning as this function intent is to mark room as read. A good place for require changes would be the code where markAsRead is called (i guess in useEventArrive hook in RoomTimeline.tsx file)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you are right. Thanks for suggestions, I'll rewrite my code when I'll have enough time!

const room = mx.getRoom(roomId);
if (!room) return;

Expand Down