mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 12:37:53 +00:00
merge
This commit is contained in:
@@ -1,22 +1,17 @@
|
||||
/* eslint-disable */
|
||||
/* tslint:disable */
|
||||
import { Injectable, NgZone } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router'
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { StorageService } from 'src/app/services/storage.service';
|
||||
import { AuthConnstants } from 'src/app/config/auth-constants';
|
||||
import { Tokenn } from '../models/token.model';
|
||||
import { ModalController, AlertController, AnimationController, Platform } from '@ionic/angular';
|
||||
import { NavigationExtras, Router } from '@angular/router';
|
||||
import { ToastService } from '../services/toast.service';
|
||||
import { BackgroundService } from './background.service';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { AlertController, Platform } from '@ionic/angular';
|
||||
import { Router } from '@angular/router';
|
||||
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' */
|
||||
import { ActionPerformed, PushNotificationSchema, PushNotifications, Token, } from '@capacitor/push-notifications';
|
||||
import { notificationObject } from '../models/notifications';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -27,52 +22,59 @@ export class NotificationsService {
|
||||
folderId: string;
|
||||
DataArray = new Array();
|
||||
|
||||
callbacks: {
|
||||
type: string,
|
||||
|
||||
callbacks: {[key: string]: {
|
||||
type: notificationObject,
|
||||
funx: Function
|
||||
id: string
|
||||
}[] = []
|
||||
}} = {}
|
||||
|
||||
active = false
|
||||
|
||||
constructor(
|
||||
private http: HttpClient,
|
||||
private storageService: StorageService,
|
||||
private modalController: ModalController,
|
||||
public modalCtrl: AlertController,
|
||||
private animationController: AnimationController,
|
||||
private platform: Platform,
|
||||
private router: Router,
|
||||
private toastService: ToastService,
|
||||
private zone: NgZone,
|
||||
private activeroute: ActivatedRoute,
|
||||
private eventtrigger: EventTrigger,
|
||||
private backgroundservice: BackgroundService,
|
||||
/* private eventTriger: Events, */
|
||||
/* private fcm: FCM */) {
|
||||
private eventtrigger: EventTrigger,) {
|
||||
|
||||
}
|
||||
registerCallback(type: IdObject, 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)
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
// registerCallback({type, funx, id = uuidv4()} : {
|
||||
// type: notificationObject,
|
||||
// funx: Function
|
||||
// id?: string
|
||||
// }) {
|
||||
// this.callbacks[id] = { funx, id, type}
|
||||
// return id;
|
||||
// }
|
||||
|
||||
deleteCallback(id) {
|
||||
this.callbacks.forEach((e, index) => {
|
||||
if (e.id == id) {
|
||||
if (index > -1) {
|
||||
this.callbacks.splice(index, 1);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
// private async runNotificationCallback(notification) {
|
||||
|
||||
// for (const [key, value] of Object.entries(this.callbacks)) {
|
||||
// if(value.type == notification.data.Object) {
|
||||
|
||||
// const dontRepeat = await value.funx(notification)
|
||||
|
||||
// if(dontRepeat) {
|
||||
// delete this.callbacks[key]
|
||||
// }
|
||||
|
||||
// } else if (value.type == '*') {
|
||||
// const dontRepeat = await value.funx(notification)
|
||||
|
||||
// if(dontRepeat) {
|
||||
// delete this.callbacks[key]
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
getTokenByUserIdAndId(user, userID) {
|
||||
// const geturl = environment.apiURL + 'notifications/user/' + userID;
|
||||
@@ -81,14 +83,14 @@ export class NotificationsService {
|
||||
}
|
||||
|
||||
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
|
||||
// }
|
||||
// });
|
||||
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) {
|
||||
@@ -96,86 +98,77 @@ export class NotificationsService {
|
||||
|
||||
} else {
|
||||
const geturl = environment.apiURL + 'notifications/token';
|
||||
// PushNotifications.addListener('registration',
|
||||
// (token: Token) => {
|
||||
PushNotifications.addListener('registration',
|
||||
(token: Token) => {
|
||||
const headers = { 'Authorization': SessionStore.user.BasicAuthKey };
|
||||
const body = {
|
||||
UserId: SessionStore.user.UserId,
|
||||
TokenId: token.value,
|
||||
Status: 1,
|
||||
Service: 1
|
||||
};
|
||||
|
||||
// this.active = false
|
||||
// this.storageService.store(username, token.value);
|
||||
// this.storageService.get(username).then(value => {
|
||||
|
||||
// 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
|
||||
// };
|
||||
|
||||
// this.http.post<Tokenn>(`${geturl}`, body, { headers }).subscribe(data => {
|
||||
// //console.log(data)
|
||||
// }, (error) => {
|
||||
// //console.log(error)
|
||||
// })
|
||||
// }).catch((error) => {
|
||||
// console.error('storage authorization', error)
|
||||
// });;
|
||||
|
||||
// }).catch((error) => {
|
||||
// console.error('storage getAndPostToken', error)
|
||||
// });
|
||||
// }
|
||||
// );
|
||||
this.http.post<Tokenn>(`${geturl}`, body, { headers }).subscribe(data => {
|
||||
this.active = true
|
||||
console.log(data)
|
||||
}, (error) => {
|
||||
console.log(error)
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registrationError() {
|
||||
// PushNotifications.addListener('registrationError',
|
||||
// (error: any) => {
|
||||
// this.active = false
|
||||
// }
|
||||
// );
|
||||
PushNotifications.addListener('registrationError',
|
||||
(error: any) => {
|
||||
this.active = false
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
onReciveForeground() {
|
||||
// PushNotifications.addListener('pushNotificationReceived',
|
||||
// (notification: PushNotificationSchema) => {
|
||||
// console.log(notification)
|
||||
// //this.DataArray.push(notification)
|
||||
// //console.log(this.DataArray)
|
||||
PushNotifications.addListener('pushNotificationReceived',
|
||||
(notification: PushNotificationSchema) => {
|
||||
this.active = true
|
||||
console.log(notification)
|
||||
//this.DataArray.push(notification)
|
||||
//console.log(this.DataArray)
|
||||
|
||||
// this.storageService.get("Notifications").then((store) => {
|
||||
// store.push(notification)
|
||||
// this.storageService.store("Notifications", store)
|
||||
// }).catch((error) => {
|
||||
// if(!error) {
|
||||
// this.storageService.store("Notifications", [notification])
|
||||
// }
|
||||
// })
|
||||
this.storageService.get("Notifications").then((store) => {
|
||||
store.push(notification)
|
||||
this.storageService.store("Notifications", store)
|
||||
}).catch((error) => {
|
||||
if(!error) {
|
||||
this.storageService.store("Notifications", [notification])
|
||||
}
|
||||
})
|
||||
|
||||
// /* this.eventTriger.publish('notificatioRecive') */
|
||||
// this.eventtrigger.publishSomeData({
|
||||
// notification: "recive"
|
||||
// })
|
||||
// }
|
||||
// );
|
||||
// this.runNotificationCallback(notification)
|
||||
/* this.eventTriger.publish('notificatioRecive') */
|
||||
this.eventtrigger.publishSomeData({
|
||||
notification: "recive"
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
onReciveBackground() {
|
||||
// PushNotifications.addListener('pushNotificationActionPerformed',
|
||||
// (notification: ActionPerformed) => {
|
||||
// console.log(notification)
|
||||
// /* this.DataArray.push(notification.notification)
|
||||
PushNotifications.addListener('pushNotificationActionPerformed',
|
||||
(notification: ActionPerformed) => {
|
||||
this.active = true
|
||||
console.log(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)
|
||||
// this.runNotificationCallback(notification)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
tempClearArray(data) {
|
||||
|
||||
Reference in New Issue
Block a user