Remove IBM push notification and jsonstore, added cordova notifications

This commit is contained in:
Eudes Inácio
2021-10-30 16:51:29 +01:00
parent cd88f49469
commit f61723599e
13 changed files with 165 additions and 473 deletions
+70 -6
View File
@@ -1,6 +1,6 @@
/* eslint-disable */
/* tslint:disable */
///<reference path="../../../plugins/cordova-plugin-mfp-push/typings/mfppush.d.ts" />
/* ///<reference path="../../../plugins/cordova-plugin-mfp-push/typings/mfppush.d.ts" /> */
import { Injectable, NgZone } from '@angular/core';
import { ActivatedRoute } from '@angular/router'
import { HttpClient } from '@angular/common/http';
@@ -17,6 +17,8 @@ import { v4 as uuidv4 } from 'uuid';
import { EventTrigger } from '../services/eventTrigger.service';
import { SessionStore } from '../store/session.service';
import { FCM } from '@ionic-native/fcm/ngx';
@Injectable({
providedIn: 'root'
})
@@ -45,7 +47,8 @@ export class NotificationsService {
private activeroute: ActivatedRoute,
private jsonstore: JsonStore,
private eventtrigger: EventTrigger,
private backgroundservice: BackgroundService) {
private backgroundservice: BackgroundService,
private fcm: FCM) {
this.storageService.get("Notifications").then((value) => {
@@ -85,6 +88,67 @@ export class NotificationsService {
}
getAndpostToken(username) {
if(this.platform.is('desktop') || this.platform.is('mobileweb')) {
console.log('Notifications not supported')
} else {
const geturl = environment.apiURL + 'notifications/token';
return this.fcm.getToken().then(token => {
console.log('token: ', token)
this.storageService.store(username, token);
this.storageService.get(username).then(value => {
console.log('STORAGE TOKEN', value)
this.storageService.get(AuthConnstants.USER).then(res => {
console.log('USERID', res);
const headers = { 'Authorization': SessionStore.user.BasicAuthKey };
const body = {
UserId: res.UserId,
TokenId: token,
Status: 1,
Service: 1
};
this.http.post<Token>(`${geturl}`, body, { headers }).subscribe(data => {
console.log('TOKEN USER MIDLE', data);
})
});
});
});
}
}
async onReceviNotification() {
this.fcm.onNotification().subscribe(data => {
if (data.click_action) {
console.log("Received in background: ", data);
this.notificatinsRoutes(data)
} /* else {
console.log("Received in foreground: ", data);
console.log(data.Service)
console.log(data.Object)
console.log(data.IdObject)
this.openApproveModal(data.IdObject);
}; */
});
}
/////////////////////////////////////////////////////
/* getTokenByUserIdAndId(user, userID) {
const geturl = environment.apiURL + 'notifications/user/' + userID;
return this.http.get<Token[]>(`${geturl}`);
}
*/
/* getAndpostToken(username) {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
//console.log('Notifications not supported')
@@ -144,13 +208,13 @@ export class NotificationsService {
}
}
} */
tempClearArray(){
this.DataArray = [];
}
async onReceviNotification() {
/* async onReceviNotification() {
if(window['WLAuthorizationManager']) {
if(window['WLAuthorizationManager'].obtainAccessToken) {
@@ -188,7 +252,7 @@ export class NotificationsService {
if(message.actionName){
this.notificatinsRoutes(data);
} else {
/* this.toastService.notificationMessage(message.alert,this.notificatinsRoutes, data); */
/* this.toastService.notificationMessage(message.alert,this.notificatinsRoutes, data);
//this.notificatinsRoutes(data);
console.log(data)
}
@@ -209,7 +273,7 @@ export class NotificationsService {
}
}
} */
notificatinsRoutes = (data) => {
if (data.Service === "agenda") {