From 0c91f108e261bbf27bdaf9ac522d96b3a69450e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Fri, 9 Apr 2021 09:48:14 +0100 Subject: [PATCH] Notification click open app --- src/app/home/home.page.ts | 57 ++++++++++++------------------- src/app/pages/login/login.page.ts | 32 +++++++---------- 2 files changed, 33 insertions(+), 56 deletions(-) diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts index d6a45060a..fb5401529 100644 --- a/src/app/home/home.page.ts +++ b/src/app/home/home.page.ts @@ -98,48 +98,36 @@ export class HomePage implements OnInit { pushCordova() { this.fcm.onNotification().subscribe(data => { - this.viewEventDetail(data.idObject) + this.viewEventDetail(data.IdObject) if (data.click_action) { console.log("Received in background: ", data); - if (data.service === "agenda") { - //this.router.navigate(['/home/', service, idObject, 'home']); - this.viewEventDetail(data.idObject) + if (data.Service === "agenda") { + //this.router.navigate(['/home/', service, IdObject, 'home']); + this.viewEventDetail(data.IdObject) } - else if (data.service === "gabinete-digital" && data.object === "expediente") { - this.viewExpedientDetail(data.idObject) + else if (data.Service === "gabinete-digital" && data.Object === "expediente") { + this.viewExpedientDetail(data.IdObject) } - else if (data.service === "gabinete-digital" && data.object === "event-list") { - // this.ngZone.run(() => {this.router.navigate(['/home/gabinete-digital/event-list', idObject])}) - this.openApproveModal(data.idObject); + else if (data.Service === "gabinete-digital" && data.Object === "event-list") { + // this.ngZone.run(() => {this.router.navigate(['/home/gabinete-digital/event-list', IdObject])}) + this.openApproveModal(data.IdObject); } - else if (data.service === "accoes" && data.object === "accao") { - //this.viewPublications(data.idObject) - alert(data.idObject) + else if (data.Service === "accoes" && data.Object === "accao") { + this.viewPublications(data.IdObject) + alert(data.IdObject) } - else if (data.service === "accoes" && data.object === "publicacao") { - this.viewPublicationDetail(data.idObject) + else if (data.Service === "accoes" && data.Object === "publicacao") { + this.viewPublicationDetail(data.IdObject) } } else { console.log("Received in foreground: ", data); - if (data.service === "agenda") { - //this.router.navigate(['/home/', service, idObject, 'home']); - this.viewEventDetail(data.idObject) - } - else if (data.service === "gabinete-digital" && data.object === "expediente") { - this.viewExpedientDetail(data.idObject) - } - else if (data.service === "gabinete-digital" && data.object === "event-list") { - // this.ngZone.run(() => {this.router.navigate(['/home/gabinete-digital/event-list', idObject])}) - this.openApproveModal(data.idObject); - } - else if (data.service === "accoes" && data.object === "accao") { - this.viewPublications(data.idObject) - } - else if (data.service === "accoes" && data.object === "publicacao") { - this.viewPublicationDetail(data.idObject) - } + + console.log(data.Service) + console.log(data.Object) + console.log(data.IdObject) + }; }); @@ -148,12 +136,9 @@ export class HomePage implements OnInit { // backend.registerToken(token); }); - this.ubscribeToTopic() - this.getToken() - } - ubscribeToTopic() { + /* ubscribeToTopic() { this.fcm.subscribeToTopic('enappd'); } getToken() { @@ -162,7 +147,7 @@ export class HomePage implements OnInit { // Register your new token in your back-end if you want // backend.registerToken(token); }); - } + } */ async viewEventDetail(eventId: any) { console.log(this.profile); diff --git a/src/app/pages/login/login.page.ts b/src/app/pages/login/login.page.ts index 697c9f9e7..3ee0224b5 100644 --- a/src/app/pages/login/login.page.ts +++ b/src/app/pages/login/login.page.ts @@ -11,6 +11,7 @@ import { PhotoService } from 'src/app/services/photo.service'; import { NotificationsService } from 'src/app/services/notifications.service'; import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { Token } from '../../models/token.model'; +import { FCM } from 'cordova-plugin-fcm-with-dependecy-updated/ionic/ngx'; /* import { Plugins, PushNotification, PushNotificationToken, PushNotificationActionPerformed } from '@capacitor/core'; @@ -38,7 +39,8 @@ export class LoginPage implements OnInit { private storageService: StorageService, private toastService: ToastService, private photoService: PhotoService, - public alertController: AlertController) { } + public alertController: AlertController, + private fcm: FCM) { } ngOnInit() { @@ -78,25 +80,18 @@ export class LoginPage implements OnInit { }); } - /* storeUserIdANdToken() { - - (PushNotifications as any).requestPermission().then(result => { - PushNotifications.register(); - }); - - PushNotifications.addListener( - 'registration', - (token: PushNotificationToken) => { - console.log('FIREBASE TOKEN', token.value) - this.storageService.store(this.username, token.value); + getToken() { + this.fcm.getToken().then(token => { + console.log('token: ', token) + this.storageService.store(this.username, token); this.storageService.get(this.username).then(value => { console.log('STORAGE TOKEN', value) this.storageService.get(AuthConnstants.USER).then(res => { console.log('USERID', res); const headers = { 'Authorization': 'Basic cGF1bG8ucGludG9AZ2FiaW5ldGVkaWdpdGFsLmxvY2FsOnRhYnRlc3RlQDAwNg==' }; const body = { - UserId: res, - TokenId: token.value, + UserId: res.UserId, + TokenId: token, Status: 1, Service: 1 }; @@ -107,11 +102,8 @@ export class LoginPage implements OnInit { }); }); - - }, - ); - - }; */ + }); + } async Login() { @@ -127,7 +119,7 @@ export class LoginPage implements OnInit { } if (await this.authService.login(this.userattempt)) { this.loginRocketChat(); - //this.storeUserIdANdToken(); + this.getToken(); this.router.navigate(['/home/events']); }