diff --git a/src/app/organisms/room/RoomViewContent.jsx b/src/app/organisms/room/RoomViewContent.jsx index 9ee040196f..001157a462 100644 --- a/src/app/organisms/room/RoomViewContent.jsx +++ b/src/app/organisms/room/RoomViewContent.jsx @@ -347,7 +347,7 @@ function useEventArrive(roomTimeline, readUptoEvtStore, timelineScrollRef, event const { timeline } = roomTimeline; const unreadMsgIsLast = timeline[timeline.length - 2].getId() === readUpToId; - if (unreadMsgIsLast) { + if (document.hasFocus() && unreadMsgIsLast) { requestAnimationFrame(() => markAsRead(roomTimeline.roomId)); } }; @@ -483,6 +483,21 @@ function RoomViewContent({ eventId, roomTimeline }) { } }, [newEvent]); + // Dismiss pending notifications on focus + const onFocus = useCallback(() => { + const timelineScroll = timelineScrollRef.current; + if (timelineScroll.bottom < 16) { + requestAnimationFrame(() => markAsRead(roomTimeline.roomId)) + } + }, [roomTimeline]) + + useEffect(() => { + window.addEventListener('focus', onFocus); + return () => { + window.removeEventListener('focus', onFocus); + }; + }, [onFocus]); + const listenKeyboard = useCallback((event) => { if (event.ctrlKey || event.altKey || event.metaKey) return; if (event.key !== 'ArrowUp') return;