This commit is contained in:
Peter Maquiran
2023-01-03 21:08:49 +01:00
parent f7aae9aa00
commit fcc8bc6b74
20 changed files with 356 additions and 68 deletions
+14 -11
View File
@@ -15,6 +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 { Events } from 'ionic-angular' */
@Injectable({
@@ -32,6 +33,8 @@ export class NotificationsService {
id: string
}[] = []
active = false
constructor(
private http: HttpClient,
private storageService: StorageService,
@@ -48,18 +51,17 @@ export class NotificationsService {
/* private eventTriger: Events, */
/* private fcm: FCM */) {
this.storageService.get("Notifications").then((value) => {
this.storageService.get("Notifications").then((value) => {
}).catch((error)=>{
console.error('storage getnotification',error)
}).catch((error)=>{
console.error('storage getnotification',error)
}).catch(() => {
this.storageService.store("Notifications", [])
})
}
registerCallback(type: string, funx: Function, object: any = {}) {
registerCallback(type: IdObject, funx: Function, object: any = {}) {
const id = uuidv4()
this.callbacks.push({ type, funx, id })
@@ -105,7 +107,8 @@ export class NotificationsService {
const geturl = environment.apiURL + 'notifications/token';
PushNotifications.addListener('registration',
(token: Token) => {
this.active = false
this.storageService.store(username, token.value);
this.storageService.get(username).then(value => {
@@ -138,11 +141,11 @@ export class NotificationsService {
}
registrationError() {
PushNotifications.addListener('registrationError',
(error: any) => {
}
);
PushNotifications.addListener('registrationError',
(error: any) => {
this.active = false
}
);
}
onReciveForeground() {