Firebase web notifications added

This commit is contained in:
Eudes Inácio
2023-06-26 11:12:57 +01:00
parent 2178ad88c2
commit b9bd42e138
11 changed files with 253 additions and 503 deletions
+77 -50
View File
@@ -45,31 +45,36 @@ export class ProfilePage implements OnInit {
private platform: Platform,
private eventTriger: EventTrigger,
public ThemeService: ThemeService,
private notificationService: NotificationsService
) {
router.events.subscribe((val) => {
this.isProfileOpen = false
this.logoutOut = true
});
this.eventTriger.getObservable().subscribe((event) => {
if(event.notification == "recive") {
if (event.notification == "recive") {
this.getNotificationData();
} else if(event.notification == "deleted") {
console.log('header', event.notification)
this.getNotificationData();
}
});
this.notificationService.notificationReceived.subscribe(() => {
this.getNotificationData();
});
setTimeout(() => {
this.hideImage = true
}, 2000)
}
ngOnInit() {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
this.getNotificationData();
} else {
this.getNotificationData();
}
this.getNotificationData();
}
@@ -83,32 +88,52 @@ export class ProfilePage implements OnInit {
asyncNotification() { }
async getNotificationData() {
//const keyExist = await this.storageservice.keyExist("Notifications")
//if(keyExist) {
this.storageservice.get("Notifications").then((value) => {
this.DataArray = []
value.forEach((element, i) => {
let notificationObject;
if (element.data) {
notificationObject = {
index: i,
title: element.title,
Service: element.data.Service,
Object: element.data.Object,
IdObject: element.data.IdObject,
FolderId: element.data.FolderId,
body: element.body,
dateInit: this.getFormatedTime(element.data.dateInit),
dateEnd: this.getFormatedTime(element.data.dateEnd),
Location: element.data.Location,
TypeAgenda: element.data.TypeAgenda,
Role: element.data.Role,
Status: element.data.Status
}
} else {
//const keyExist = await this.storageservice.keyExist("Notifications")
//if(keyExist) {
await this.storageservice.get("Notifications").then((value) => {
this.DataArray = []
value.forEach((element, i) => {
let notificationObject;
if (element.notification) {
notificationObject = {
index: i,
title: element.notification.title,
Service: element.data.Service,
Object: element.data.Object,
IdObject: element.data.IdObject,
FolderId: element.data.FolderId,
body: element.notification.body,
dateInit: this.getFormatedTime(element.data.dateInit),
dateEnd: this.getFormatedTime(element.data.dateEnd),
Location: element.data.Location,
TypeAgenda: element.data.TypeAgenda,
Role: element.data.Role,
Status: element.data.Status
}
} else if (element.data) {
notificationObject = {
index: i,
title: element.title,
Service: element.data.Service,
Object: element.data.Object,
IdObject: element.data.IdObject,
FolderId: element.data.FolderId,
body: element.body,
dateInit: this.getFormatedTime(element.data.dateInit),
dateEnd: this.getFormatedTime(element.data.dateEnd),
Location: element.data.Location,
TypeAgenda: element.data.TypeAgenda,
Role: element.data.Role,
Status: element.data.Status
}
} else {
{
notificationObject = {
FolderId: element.FolderId,
IdObject: element.IdObject,
@@ -125,14 +150,15 @@ export class ProfilePage implements OnInit {
title: element.title
}
}
this.DataArray.push(notificationObject)
});
this.notificationdata = this.DataArray
}).catch((error) => {
console.error('storage getnotification: ',error)
})
// }
}
this.DataArray.push(notificationObject)
});
this.notificationdata = this.DataArray
}).catch((error) => {
console.error('storage getnotification: ', error)
})
// }
}
@@ -198,9 +224,6 @@ export class ProfilePage implements OnInit {
// this.notificationservice.tempClearArray();
this.deleteNotification(index);
this.eventTriger.publishSomeData({
notification: "deleted"
})
@@ -213,8 +236,12 @@ export class ProfilePage implements OnInit {
this.storageservice.get("Notifications").then((value) => {
this.eventTriger.publishSomeData({
notification: "deleted"
})
}).catch((error) => {
console.error('storage delete notification: ',error)
console.error('storage delete notification: ', error)
})
});
@@ -225,14 +252,14 @@ export class ProfilePage implements OnInit {
SessionStore.setUrlBeforeInactivity(this.router.url);
this.logoutOut == false
if(environment.production) {
if (environment.production) {
window.location.pathname = '/auth'
} else {
const pathBeforeGoOut = window.location.pathname
this.router.navigateByUrl('/auth', { replaceUrl: true });
setTimeout(() => {
if(this.logoutOut == false || pathBeforeGoOut == window.location.pathname) {
if (this.logoutOut == false || pathBeforeGoOut == window.location.pathname) {
window.location.pathname = '/auth'
} else {
@@ -268,7 +295,7 @@ export class ProfilePage implements OnInit {
}
if(this.isProfileOpen == false) {
if (this.isProfileOpen == false) {
this.isProfileOpen = true;
const modal = await this.modalController.create({
@@ -278,11 +305,11 @@ export class ProfilePage implements OnInit {
}
});
await modal.present();
modal.onDidDismiss().then(() => {
this.isProfileOpen = false;
})
}
}