This commit is contained in:
Peter Maquiran
2022-12-19 17:04:21 +01:00
parent 7543f319b8
commit 2b85796a5f
15 changed files with 325 additions and 416 deletions
+127 -127
View File
@@ -14,7 +14,7 @@ import { BackgroundService } from './background.service';
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 { ActionPerformed, PushNotificationSchema, PushNotifications, Token, } from '@capacitor/push-notifications';
@Injectable({
providedIn: 'root'
@@ -57,170 +57,170 @@ export class NotificationsService {
}
registerCallback(type: string, funx: Function, object: any = {}) {
// registerCallback(type: string, funx: Function, object: any = {}) {
const id = uuidv4()
this.callbacks.push({ type, funx, id })
if (!object.hasOwnProperty('desktop') && object['desktop'] != false) {
this.backgroundservice.registerBackService('Notification', funx, type)
}
// const id = uuidv4()
// this.callbacks.push({ type, funx, id })
// if (!object.hasOwnProperty('desktop') && object['desktop'] != false) {
// this.backgroundservice.registerBackService('Notification', funx, type)
// }
return id;
}
// return id;
// }
deleteCallback(id) {
this.callbacks.forEach((e, index) => {
if (e.id == id) {
if (index > -1) {
this.callbacks.splice(index, 1);
}
}
})
// deleteCallback(id) {
// this.callbacks.forEach((e, index) => {
// if (e.id == id) {
// if (index > -1) {
// this.callbacks.splice(index, 1);
// }
// }
// })
}
// }
getTokenByUserIdAndId(user, userID) {
// const geturl = environment.apiURL + 'notifications/user/' + userID;
// getTokenByUserIdAndId(user, userID) {
// // const geturl = environment.apiURL + 'notifications/user/' + userID;
// return this.http.get<Tokenn[]>(`${geturl}`);
}
// // return this.http.get<Tokenn[]>(`${geturl}`);
// }
requestPermissions() {
PushNotifications.requestPermissions().then(result => {
if (result.receive === 'granted') {
// Register with Apple / Google to receive push via APNS/FCM
PushNotifications.register();
} else {
// Show some error
}
});
}
// requestPermissions() {
// PushNotifications.requestPermissions().then(result => {
// if (result.receive === 'granted') {
// // Register with Apple / Google to receive push via APNS/FCM
// PushNotifications.register();
// } else {
// // Show some error
// }
// });
// }
getAndpostToken(username) {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
// getAndpostToken(username) {
// if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
} else {
const geturl = environment.apiURL + 'notifications/token';
PushNotifications.addListener('registration',
(token: Token) => {
// } else {
// const geturl = environment.apiURL + 'notifications/token';
// PushNotifications.addListener('registration',
// (token: Token) => {
this.storageService.store(username, token.value);
this.storageService.get(username).then(value => {
// this.storageService.store(username, token.value);
// this.storageService.get(username).then(value => {
this.storageService.get(AuthConnstants.USER).then(res => {
// this.storageService.get(AuthConnstants.USER).then(res => {
const headers = { 'Authorization': SessionStore.user.BasicAuthKey };
const body = {
UserId: res.UserId,
TokenId: token.value,
Status: 1,
Service: 1
};
// const headers = { 'Authorization': SessionStore.user.BasicAuthKey };
// const body = {
// UserId: res.UserId,
// TokenId: token.value,
// Status: 1,
// Service: 1
// };
this.http.post<Tokenn>(`${geturl}`, body, { headers }).subscribe(data => {
// this.http.post<Tokenn>(`${geturl}`, body, { headers }).subscribe(data => {
}, (error) => {
// }, (error) => {
})
});
// })
// });
});
}
);
}
// });
// }
// );
// }
}
// }
registrationError() {
PushNotifications.addListener('registrationError',
(error: any) => {
// registrationError() {
// PushNotifications.addListener('registrationError',
// (error: any) => {
}
);
}
// }
// );
// }
onReciveForeground() {
PushNotifications.addListener('pushNotificationReceived',
(notification: PushNotificationSchema) => {
// onReciveForeground() {
// PushNotifications.addListener('pushNotificationReceived',
// (notification: PushNotificationSchema) => {
this.DataArray.push(notification)
// this.DataArray.push(notification)
this.storageService.store("Notifications", this.DataArray)
this.eventtrigger.publishSomeData({
notification: "recive"
})
}
);
}
// this.storageService.store("Notifications", this.DataArray)
// this.eventtrigger.publishSomeData({
// notification: "recive"
// })
// }
// );
// }
onReciveBackground() {
PushNotifications.addListener('pushNotificationActionPerformed',
(notification: ActionPerformed) => {
// onReciveBackground() {
// PushNotifications.addListener('pushNotificationActionPerformed',
// (notification: ActionPerformed) => {
/* this.DataArray.push(notification.notification)
// /* this.DataArray.push(notification.notification)
this.storageService.store("Notifications", this.DataArray)
this.eventtrigger.publishSomeData({
notification: "recive"
}) */
this.notificatinsRoutes(notification)
}
);
}
// this.storageService.store("Notifications", this.DataArray)
// this.eventtrigger.publishSomeData({
// notification: "recive"
// }) */
// this.notificatinsRoutes(notification)
// }
// );
// }
tempClearArray() {
this.DataArray = new Array;
}
// tempClearArray() {
// this.DataArray = new Array;
// }
notificatinsRoutes = (notification) => {
// notificatinsRoutes = (notification) => {
if (notification.notification.data.Service === "agenda" && notification.notification.data.IdObject.length > 10) {
// if (notification.notification.data.Service === "agenda" && notification.notification.data.IdObject.length > 10) {
this.zone.run(() => this.router.navigate(['/home/agenda', notification.notification.data.IdObject, 'agenda']));
}
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "expediente") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expediente', notification.notification.data.IdObject, 'gabinete-digital']));
}
else if (notification.notification.data.Service === "agenda" && notification.notification.data.Object === "event-list") {
//this.zone.run(() => this.router.navigate(['/home/gabinete-digital/event-list/approve-event',IdObject, 'agenda']));
this.zone.run(() => this.router.navigate(['/home/agenda/event-list/approve-event', notification.notification.data.IdObject, 'agenda']));
// this.zone.run(() => this.router.navigate(['/home/agenda', notification.notification.data.IdObject, 'agenda']));
// }
// else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "expediente") {
// this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expediente', notification.notification.data.IdObject, 'gabinete-digital']));
// }
// else if (notification.notification.data.Service === "agenda" && notification.notification.data.Object === "event-list") {
// //this.zone.run(() => this.router.navigate(['/home/gabinete-digital/event-list/approve-event',IdObject, 'agenda']));
// this.zone.run(() => this.router.navigate(['/home/agenda/event-list/approve-event', notification.notification.data.IdObject, 'agenda']));
} else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "despachos") {
// } else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "despachos") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos', notification.notification.data.IdObject, 'gabinete-digital'], { replaceUrl: true }));
}
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "parecer") {
// this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos', notification.notification.data.IdObject, 'gabinete-digital'], { replaceUrl: true }));
// }
// else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "parecer") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos', notification.notification.data.IdObject, 'gabinete-digital']));
}
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "deferimento") {
// this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos', notification.notification.data.IdObject, 'gabinete-digital']));
// }
// else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "deferimento") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos', notification.notification.data.IdObject, 'gabinete-digital']));
}
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "despachos-pr") {
// this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos', notification.notification.data.IdObject, 'gabinete-digital']));
// }
// else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "despachos-pr") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos-pr', notification.notification.data.IdObject, 'gabinete-digital']));
}
else if (notification.notification.data.Service === "accoes" && notification.notification.data.Object === "accao") {
this.zone.run(() => this.router.navigate(['/home/publications', notification.notification.data.IdObject]));
}
else if (notification.notification.data.Service === "accoes" && notification.notification.data.Object === "publicacao") {
this.zone.run(() => this.router.navigate(['/home/publications/view-publications', notification.notification.data.FolderId, notification.data.IdObject]));
}
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "diplomas") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas', notification.notification.data.IdObject, 'gabinete-digital']));
}
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "diplomas-assinar") {
// this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos-pr', notification.notification.data.IdObject, 'gabinete-digital']));
// }
// else if (notification.notification.data.Service === "accoes" && notification.notification.data.Object === "accao") {
// this.zone.run(() => this.router.navigate(['/home/publications', notification.notification.data.IdObject]));
// }
// else if (notification.notification.data.Service === "accoes" && notification.notification.data.Object === "publicacao") {
// this.zone.run(() => this.router.navigate(['/home/publications/view-publications', notification.notification.data.FolderId, notification.data.IdObject]));
// }
// else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "diplomas") {
// this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas', notification.notification.data.IdObject, 'gabinete-digital']));
// }
// else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "diplomas-assinar") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas-assinar', notification.notification.data.IdObject, 'gabinete-digital']));
}
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "expedientes-pr") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expedientes-pr', notification.notification.data.IdObject, 'gabinete-digital']));
}
// this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas-assinar', notification.notification.data.IdObject, 'gabinete-digital']));
// }
// else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "expedientes-pr") {
// this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expedientes-pr', notification.notification.data.IdObject, 'gabinete-digital']));
// }
}
// }
}