|
|
|
@ -2,6 +2,8 @@ import {getMxcFromUserId, getAvatarUrl} from '@/lib/getMxc';
|
|
|
|
|
import {calcUserName} from '@/lib/matrixUtils';
|
|
|
|
|
import {getRoom} from '@/lib/matrixUtils';
|
|
|
|
|
import {router} from '@/router';
|
|
|
|
|
import {Capacitor, Plugins} from '@capacitor/core';
|
|
|
|
|
const {LocalNotifications} = Plugins;
|
|
|
|
|
|
|
|
|
|
export class NotificationHandler{
|
|
|
|
|
constructor() {
|
|
|
|
@ -17,6 +19,7 @@ export class NotificationHandler{
|
|
|
|
|
.then(permission => {return permission === 'granted'});
|
|
|
|
|
}
|
|
|
|
|
showNotification(event){
|
|
|
|
|
if (Capacitor.isNative) return this.showNativeNotification(event);
|
|
|
|
|
if (Notification.permission !== 'granted') return false;
|
|
|
|
|
console.log(event);
|
|
|
|
|
let mxc = getMxcFromUserId(event.sender);
|
|
|
|
@ -25,4 +28,20 @@ export class NotificationHandler{
|
|
|
|
|
icon: mxc?getAvatarUrl(mxc):undefined
|
|
|
|
|
}).onclick = ()=>router.push(`/rooms/${event.room_id}`);
|
|
|
|
|
}
|
|
|
|
|
showNativeNotification(event){
|
|
|
|
|
LocalNotifications.schedule({
|
|
|
|
|
notifications: [
|
|
|
|
|
{
|
|
|
|
|
title: `${calcUserName(event.sender)} in ${getRoom(event.room_id).name}`,
|
|
|
|
|
body: event.content.body,
|
|
|
|
|
id: 1,
|
|
|
|
|
schedule: { at: new Date(Date.now() + 1000 * 5) },
|
|
|
|
|
sound: null,
|
|
|
|
|
attachments: null,
|
|
|
|
|
actionTypeId: '',
|
|
|
|
|
extra: null
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|