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 { useSyncState } from '../../hooks/useSyncState';
|
||||||
import { stopPropagation } from '../../utils/keyboard';
|
import { stopPropagation } from '../../utils/keyboard';
|
||||||
import { SyncStatus } from './SyncStatus';
|
import { SyncStatus } from './SyncStatus';
|
||||||
|
import { togglePusher } from '../../features/settings/notifications/PushNotifications';
|
||||||
|
|
||||||
function ClientRootLoading() {
|
function ClientRootLoading() {
|
||||||
return (
|
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) => {
|
const useLogoutListener = (mx?: MatrixClient) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleLogout: HttpApiEventHandlerMap[HttpApiEvent.SessionLoggedOut] = async () => {
|
const handleLogout: HttpApiEventHandlerMap[HttpApiEvent.SessionLoggedOut] = async () => {
|
||||||
|
|
@ -171,13 +184,16 @@ export function ClientRoot({ children }: ClientRootProps) {
|
||||||
|
|
||||||
useSyncState(
|
useSyncState(
|
||||||
mx,
|
mx,
|
||||||
useCallback((state) => {
|
useCallback(
|
||||||
if (state === 'PREPARED') {
|
(state) => {
|
||||||
setLoading(false);
|
if (state === 'PREPARED') {
|
||||||
}
|
setLoading(false);
|
||||||
}, [])
|
pushNotificationListener(mx);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[mx]
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SpecVersions baseUrl={baseUrl!}>
|
<SpecVersions baseUrl={baseUrl!}>
|
||||||
{mx && <SyncStatus mx={mx} />}
|
{mx && <SyncStatus mx={mx} />}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue