From 271d00156cf371c8d56e69fc32278d67a92f2cc8 Mon Sep 17 00:00:00 2001 From: really-not-lavacat Date: Thu, 5 Sep 2024 16:40:01 +0300 Subject: [PATCH 1/2] Fix: Prevent marking messages as read when tab inactive --- src/client/action/notifications.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/client/action/notifications.ts b/src/client/action/notifications.ts index 17ea1ed61..045de16d7 100644 --- a/src/client/action/notifications.ts +++ b/src/client/action/notifications.ts @@ -1,6 +1,9 @@ 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 + if (document.hidden) return; + const room = mx.getRoom(roomId); if (!room) return; From ebc7b4b6373e8d51aeb657647784dc76023fe988 Mon Sep 17 00:00:00 2001 From: really-not-lavacat Date: Sun, 8 Sep 2024 18:27:10 +0300 Subject: [PATCH 2/2] Updated `markAsRead` to check both `document.hidden` and `document.hasFocus()` --- src/client/action/notifications.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/client/action/notifications.ts b/src/client/action/notifications.ts index 045de16d7..11edb9b61 100644 --- a/src/client/action/notifications.ts +++ b/src/client/action/notifications.ts @@ -2,7 +2,8 @@ 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 - if (document.hidden) return; + // or when browser is inactive (i.e. user interacts with some another app) + if (document.hidden || !document.hasFocus()) return; const room = mx.getRoom(roomId); if (!room) return;