This commit is contained in:
Peter Maquiran
2023-09-22 15:27:43 +01:00
9 changed files with 250 additions and 153 deletions
+9 -38
View File
@@ -13,6 +13,9 @@ import { ActionPerformed, PushNotificationSchema, PushNotifications, Token, } fr
import { notificationObject } from '../models/notifications';
import { Capacitor } from '@capacitor/core';
import { AngularFireMessaging } from '@angular/fire/messaging';
import { NotificationHolderService } from 'src/app/store/notification-holder.service';
@Injectable({
providedIn: 'root'
})
@@ -23,6 +26,7 @@ export class NotificationsService {
DataArray = new Array();
callbacks: {
[key: string]: {
type: notificationObject,
@@ -44,7 +48,8 @@ export class NotificationsService {
private router: Router,
private zone: NgZone,
private eventtrigger: EventTrigger,
private afMessaging: AngularFireMessaging,) {
private afMessaging: AngularFireMessaging,
public NotificationHolderService: NotificationHolderService) {
}
@@ -179,45 +184,11 @@ export class NotificationsService {
storenotification(notification) {
console.log('Store Notification ',notification)
this.storageService.get("Notifications").then((store) => {
store.push(notification)
console.log('Store Notification ',store)
if(this.platform.is('mobile')) {
const result = store.reduce((accumulator, current) => {
let exists = accumulator.find(item => {
return item.id === current.id;
});
if(!exists) {
accumulator = accumulator.concat(current);
}
return accumulator;
}, []);
console.log('Notification Result',result);
this.storageService.store("Notifications", result).then(() => {
this.eventtrigger.publishSomeData({
notification: "recive"
})
})
} else {
this.storageService.store("Notifications", store).then(() => {
this.eventtrigger.publishSomeData({
notification: "recive"
})
})
}
}).catch((error) => {
if (!error) {
this.storageService.store("Notifications", [notification])
}
})
this.NotificationHolderService.addNotification(notification)
}
onReciveBackground() {