mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-09-16 15:52:25 +03:00
update presence status when window lose focus
(cherry picked from commit 9c99a84ad0513abf33c119ab68590997435f62c8) Signed-off-by: Kris Hu <i@krishu.moe>
This commit is contained in:
parent
c757b8967f
commit
ecf65b7ca7
1 changed files with 24 additions and 1 deletions
|
@ -1,7 +1,7 @@
|
|||
import { useAtomValue } from 'jotai';
|
||||
import React, { ReactNode, useCallback, useEffect, useRef } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { RoomEvent, RoomEventHandlerMap } from 'matrix-js-sdk';
|
||||
import { RoomEvent, RoomEventHandlerMap, SetPresence } from 'matrix-js-sdk';
|
||||
import { roomToUnreadAtom, unreadEqual, unreadInfoToUnread } from '../../state/room/roomToUnread';
|
||||
import LogoSVG from '../../../../public/res/svg/cinny.svg';
|
||||
import LogoUnreadSVG from '../../../../public/res/svg/cinny-unread.svg';
|
||||
|
@ -253,6 +253,28 @@ function MessageNotifications() {
|
|||
);
|
||||
}
|
||||
|
||||
function UpdatePresence() {
|
||||
const mx = useMatrixClient();
|
||||
const onFocus = () => {
|
||||
mx.setSyncPresence(SetPresence.Online);
|
||||
};
|
||||
const onBlur = () => {
|
||||
mx.setSyncPresence(SetPresence.Unavailable);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
window.addEventListener("focus", onFocus);
|
||||
window.addEventListener("blur", onBlur);
|
||||
onFocus();
|
||||
return () => {
|
||||
window.removeEventListener("focus", onFocus);
|
||||
window.removeEventListener("blur", onBlur);
|
||||
};
|
||||
}, [mx]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
type ClientNonUIFeaturesProps = {
|
||||
children: ReactNode;
|
||||
};
|
||||
|
@ -265,6 +287,7 @@ export function ClientNonUIFeatures({ children }: ClientNonUIFeaturesProps) {
|
|||
<FaviconUpdater />
|
||||
<InviteNotifications />
|
||||
<MessageNotifications />
|
||||
<UpdatePresence />
|
||||
{children}
|
||||
</>
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue