client: pass along notifications if push notifs disabled

This commit is contained in:
Johann150 2022-11-12 18:48:25 +01:00
parent 23953b9ad1
commit cd87e262fe
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1

View file

@ -19,6 +19,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { defineAsyncComponent, Ref, ref } from 'vue'; import { defineAsyncComponent, Ref, ref } from 'vue';
import { swInject } from './sw-inject'; import { swInject } from './sw-inject';
import { instance } from '@/instance';
import { popup as showPopup, popups, pendingApiRequestsCount } from '@/os'; import { popup as showPopup, popups, pendingApiRequestsCount } from '@/os';
import { uploads } from '@/scripts/upload'; import { uploads } from '@/scripts/upload';
import * as sound from '@/scripts/sound'; import * as sound from '@/scripts/sound';
@ -32,14 +33,12 @@ const dev: Ref<boolean> = ref(_DEV_);
const onNotification = (notification: { type: string; id: any; }): void => { const onNotification = (notification: { type: string; id: any; }): void => {
if ($i?.mutingNotificationTypes.includes(notification.type)) return; if ($i?.mutingNotificationTypes.includes(notification.type)) return;
if (document.visibilityState === 'visible') { // if push notifications are enabled there is no need to pass the notification along
stream.send('readNotification', { if (!instance.enableServiceWorker) {
id: notification.id, // service worker is not enabled or set up on the server, pass the notification along
navigator.serviceWorker.ready.then(registration => {
registration.active.postMessage({ type: 'notification', body: notification });
}); });
showPopup(defineAsyncComponent(() => import('@/components/notification-toast.vue')), {
notification,
}, {}, 'closed');
} }
sound.play('notification'); sound.play('notification');