add a fallback push notification
so that a notification will always be generated from a push event, avoiding being killed for privacy policies from browser and os
This commit is contained in:
1 parent
3ee49852cb
commit
f66545bbd8
2 files changed
+20
-10
No files matched your search
@@ -1,7 +1,7 @@
|
||||
/// <reference lib="WebWorker" />
|
||||
import { precacheAndRoute, cleanupOutdatedCaches } from 'workbox-precaching';
|
||||
import { usePushNotifications } from './sw/pushNotification';
|
||||
import { EventType } from "matrix-js-sdk/lib/@types/event";
|
||||
import { usePushNotifications } from './sw/pushNotification';
|
||||
|
||||
export type {};
|
||||
declare const self: ServiceWorkerGlobalScope;
|
||||
@@ -204,6 +204,8 @@ self.addEventListener('notificationclick', (event: NotificationEvent) => {
|
||||
return Promise.resolve();
|
||||
})
|
||||
);
|
||||
|
||||
return Promise.resolve();
|
||||
});
|
||||
|
||||
if (self.__WB_MANIFEST) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable camelcase */
|
||||
import { EventType } from "matrix-js-sdk/lib/@types/event";
|
||||
|
||||
const DEFAULT_NOTIFICATION_ICON = '/public/res/apple/apple-touch-icon-180x180.png';
|
||||
@@ -79,28 +80,35 @@ export const usePushNotifications = (self: ServiceWorkerGlobalScope) => {
|
||||
)
|
||||
};
|
||||
|
||||
const fallbackNotification = async () => {
|
||||
await self.registration.showNotification("You have a new notification", {
|
||||
icon: DEFAULT_NOTIFICATION_ICON,
|
||||
badge: DEFAULT_NOTIFICATION_BADGE,
|
||||
tag: "Cinny",
|
||||
});
|
||||
};
|
||||
|
||||
const handlePushNotificationPushData = async (pushData: any) => {
|
||||
const eventType = pushData?.type as (EventType | undefined);
|
||||
if (!eventType) {
|
||||
console.log("no event type");
|
||||
return;
|
||||
console.warn("no event type");
|
||||
}
|
||||
|
||||
switch (eventType) {
|
||||
case EventType.RoomMessage:
|
||||
await handleRoomMessageNotification(pushData);
|
||||
return;
|
||||
return handleRoomMessageNotification(pushData);
|
||||
case EventType.RoomMessageEncrypted:
|
||||
await handleEncryptedMessageNotification(pushData);
|
||||
return;
|
||||
return handleEncryptedMessageNotification(pushData);
|
||||
case EventType.RoomMember:
|
||||
if (!(pushData?.content?.membership == "invite")) return;
|
||||
await handleInvitationNotification(pushData);
|
||||
return;
|
||||
if (!(pushData?.content?.membership === "invite")) break;
|
||||
return handleInvitationNotification(pushData);
|
||||
|
||||
default:
|
||||
// no voip support in app anyway
|
||||
return;
|
||||
}
|
||||
|
||||
return fallbackNotification();
|
||||
};
|
||||
|
||||
return { handlePushNotificationPushData };
|
||||
|
||||
Reference in new issue
Block a user