This commit is contained in:
Peter Maquiran
2023-01-16 15:47:18 +01:00
6 changed files with 77 additions and 11 deletions
+2 -1
View File
@@ -13,6 +13,7 @@ const object = [
'diplomas',
'expedientes-pr',
'despachos',
'*',
] as const;
export type IdObject = typeof object[number];
export type notificationObject = typeof object[number];
+26 -3
View File
@@ -15,7 +15,7 @@ import { v4 as uuidv4 } from 'uuid';
import { EventTrigger } from '../services/eventTrigger.service';
import { SessionStore } from '../store/session.service';
import { ActionPerformed, PushNotificationSchema, PushNotifications, Token, } from '@capacitor/push-notifications';
import { IdObject } from '../models/notifications';
import { notificationObject } from '../models/notifications';
/* import { Events } from 'ionic-angular' */
@Injectable({
@@ -28,7 +28,7 @@ export class NotificationsService {
DataArray = new Array();
callbacks: {
type: string,
type: notificationObject,
funx: Function
id: string
}[] = []
@@ -52,7 +52,7 @@ export class NotificationsService {
/* private fcm: FCM */) {
}
registerCallback(type: IdObject, funx: Function, object: any = {}) {
registerCallback(type: notificationObject, funx: Function, object: any = {}) {
const id = uuidv4()
this.callbacks.push({ type, funx, id })
@@ -63,6 +63,27 @@ export class NotificationsService {
return id;
}
// registerCallback({type, funx, id = uuidv4()}:{
// type: notificationObject,
// funx: Function
// id?: string
// }) {
// this.callbacks.push({ type, funx, id })
// return id;
// }
private runNotificationCallback(notification) {
this.callbacks.forEach((data) => {
if(data.type == notification.data.IdObject) {
data.funx({notification})
} else if (data.type == '*') {
}
})
}
deleteCallback(id) {
this.callbacks.forEach((e, index) => {
if (e.id == id) {
@@ -155,6 +176,7 @@ export class NotificationsService {
}
})
this.runNotificationCallback(notification)
/* this.eventTriger.publish('notificatioRecive') */
this.eventtrigger.publishSomeData({
notification: "recive"
@@ -174,6 +196,7 @@ export class NotificationsService {
notification: "recive"
}) */
this.notificatinsRoutes(notification)
this.runNotificationCallback(notification)
}
);
}