mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-06 15:30:27 +03:00
Adds the client state listener for toggling whether to use push notifs or app notifs
This commit is contained in:
parent
8a3eee367d
commit
a883963314
1 changed files with 22 additions and 6 deletions
|
|
@ -37,6 +37,7 @@ import { AsyncStatus, useAsyncCallback } from '../../hooks/useAsyncCallback';
|
|||
import { useSyncState } from '../../hooks/useSyncState';
|
||||
import { stopPropagation } from '../../utils/keyboard';
|
||||
import { SyncStatus } from './SyncStatus';
|
||||
import { togglePusher } from '../../features/settings/notifications/PushNotifications';
|
||||
|
||||
function ClientRootLoading() {
|
||||
return (
|
||||
|
|
@ -124,6 +125,18 @@ function ClientRootOptions({ mx }: { mx?: MatrixClient }) {
|
|||
);
|
||||
}
|
||||
|
||||
const pushNotificationListener = (mx: MatrixClient) => {
|
||||
navigator.serviceWorker.ready.then((registration) => {
|
||||
registration.pushManager.getSubscription().then((subscription) => {
|
||||
document.addEventListener('visibilitychange', () => {
|
||||
console.log('Check check baby');
|
||||
togglePusher(mx, subscription, document.visibilityState === 'visible');
|
||||
});
|
||||
togglePusher(mx, subscription, true);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const useLogoutListener = (mx?: MatrixClient) => {
|
||||
useEffect(() => {
|
||||
const handleLogout: HttpApiEventHandlerMap[HttpApiEvent.SessionLoggedOut] = async () => {
|
||||
|
|
@ -171,13 +184,16 @@ export function ClientRoot({ children }: ClientRootProps) {
|
|||
|
||||
useSyncState(
|
||||
mx,
|
||||
useCallback((state) => {
|
||||
if (state === 'PREPARED') {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [])
|
||||
useCallback(
|
||||
(state) => {
|
||||
if (state === 'PREPARED') {
|
||||
setLoading(false);
|
||||
pushNotificationListener(mx);
|
||||
}
|
||||
},
|
||||
[mx]
|
||||
)
|
||||
);
|
||||
|
||||
return (
|
||||
<SpecVersions baseUrl={baseUrl!}>
|
||||
{mx && <SyncStatus mx={mx} />}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue