Skip to content

Commit

Permalink
Merge branch 'fix/unfocused-mark-read' into evergreen
Browse files Browse the repository at this point in the history
  • Loading branch information
greentore committed Apr 18, 2023
2 parents b409495 + 7dd3b8b commit 680abb7
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/app/organisms/room/RoomViewContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
};
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 680abb7

Please sign in to comment.