|
|
|
|
@ -1,21 +1,15 @@
|
|
|
|
|
import { Injectable, NgZone } from '@angular/core';
|
|
|
|
|
// import { Push, PushObject, PushOptions } from '@ionic-native/push/ngx';
|
|
|
|
|
import { CommonService } from '../common/common.service';
|
|
|
|
|
import { TranslatorService } from '../translator/translator.service';
|
|
|
|
|
import { NotificationModel } from './models/notification.model';
|
|
|
|
|
import { SharedDataService } from '../shared-data-service/shared-data.service';
|
|
|
|
|
import { ConnectorService } from '../connector/connector.service';
|
|
|
|
|
//import { Response } from '../models/response';
|
|
|
|
|
import { Response } from 'src/app/hmg-common/services/models/response';
|
|
|
|
|
import { RegisterAuthenticatedUserRequest } from './models/register-authenticated-user.request';
|
|
|
|
|
import { Platform, Events } from '@ionic/angular';
|
|
|
|
|
import { RegisterNormalUserRequest } from './models/register-normal-user.request';
|
|
|
|
|
import { AuthenticationService } from '../authentication/authentication.service';
|
|
|
|
|
// import { AppointmentModel } from 'src/app/eservices/appointments/service/models/appointment.model';
|
|
|
|
|
import { SessionModel } from './models/session.model';
|
|
|
|
|
import { AuthenticatedUser } from '../authentication/models/authenticated-user';
|
|
|
|
|
// import { NotificationsCenterService } from 'src/app/eservices/notifications-center/service/notifications-center.service';
|
|
|
|
|
// import { NotificationsComponent } from 'src/app/eservices/notifications-center/notifications/notifications.component';
|
|
|
|
|
import { FirebaseX } from '@ionic-native/firebase-x/ngx';
|
|
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
@ -28,7 +22,6 @@ export class PushService {
|
|
|
|
|
|
|
|
|
|
public static CHANNEL_ID = '679409052782';//'815750722565';
|
|
|
|
|
constructor(
|
|
|
|
|
// public push: Push,
|
|
|
|
|
public cs: CommonService,
|
|
|
|
|
public ts: TranslatorService,
|
|
|
|
|
public sharedService: SharedDataService,
|
|
|
|
|
@ -36,72 +29,14 @@ export class PushService {
|
|
|
|
|
private platform: Platform,
|
|
|
|
|
private authService: AuthenticationService,
|
|
|
|
|
public ngZone: NgZone,
|
|
|
|
|
// public notifyService: NotificationsCenterService,
|
|
|
|
|
public events: Events,
|
|
|
|
|
public firebasex: FirebaseX,
|
|
|
|
|
|
|
|
|
|
public firebasex: FirebaseX
|
|
|
|
|
) { }
|
|
|
|
|
|
|
|
|
|
public startReceiving() {
|
|
|
|
|
console.log("startReceiving");
|
|
|
|
|
// this.processStartReceiving();
|
|
|
|
|
this.processStartReceivingWithFirebase();
|
|
|
|
|
}
|
|
|
|
|
private processStartReceiving1() {
|
|
|
|
|
// if (this.cs.isCordova()) {
|
|
|
|
|
// this.stopNotifications(() => {
|
|
|
|
|
// this.push.hasPermission()
|
|
|
|
|
// .then((res: any) => {
|
|
|
|
|
// if (res.isEnabled) {
|
|
|
|
|
// this.createChannel();
|
|
|
|
|
// } else {
|
|
|
|
|
// this.cs.presentAlert(this.ts.trPK('push', 'no-permiss'));
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private createChannel() {
|
|
|
|
|
// Create a channel (Android O and above). You'll need to provide the id, description and importance properties.
|
|
|
|
|
// this.push.createChannel({
|
|
|
|
|
// id: PushService.CHANNEL_ID,
|
|
|
|
|
// description: 'HMG push notifications',
|
|
|
|
|
// importance: 3
|
|
|
|
|
// }).then(() => {
|
|
|
|
|
// this.initialize();
|
|
|
|
|
// });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private initialize() {
|
|
|
|
|
// const options: PushOptions = {
|
|
|
|
|
// android: {
|
|
|
|
|
// senderID: PushService.CHANNEL_ID,
|
|
|
|
|
// sound: true,
|
|
|
|
|
// forceShow: true
|
|
|
|
|
// },
|
|
|
|
|
// ios: {
|
|
|
|
|
// alert: true,
|
|
|
|
|
// badge: true,
|
|
|
|
|
// sound: true
|
|
|
|
|
// },
|
|
|
|
|
// windows: {},
|
|
|
|
|
// browser: {
|
|
|
|
|
// pushServiceURL: 'http://push.api.phonegap.com/v1/push'
|
|
|
|
|
// }
|
|
|
|
|
// };
|
|
|
|
|
// const pushObject: PushObject = this.push.init(options);
|
|
|
|
|
// pushObject.on('notification').subscribe((notification: any) => {
|
|
|
|
|
// this.processNotification(notification);
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// pushObject.on('registration').subscribe((data: any) => {
|
|
|
|
|
// this.registerInBackend(data);
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private processNotification(data: any) {
|
|
|
|
|
const notification = new NotificationModel();
|
|
|
|
|
@ -120,12 +55,9 @@ export class PushService {
|
|
|
|
|
const type = Number(data.additionalData.NotificationType);
|
|
|
|
|
if (type === NotificationModel.TYPE_APPOINTMENT) {
|
|
|
|
|
this.sharedService.setSharedData(notification, NotificationModel.SHARED_DATA);
|
|
|
|
|
// this.ngZone.run(() => this.cs.openAppointmentDetails());
|
|
|
|
|
} else if (type === NotificationModel.TYPE_CONFERENCE) {
|
|
|
|
|
const session = data.additionalData.sessionId;
|
|
|
|
|
// console.log('session Id Recieved>>>>>'+ session);
|
|
|
|
|
this.sharedService.setSharedData( new SessionModel(session) , SessionModel.SHARED_DATA);
|
|
|
|
|
// this.ngZone.run( () => this.cs.openConference() );
|
|
|
|
|
} else {
|
|
|
|
|
if (type === NotificationModel.TYPE_VIDEO) {
|
|
|
|
|
notification.MessageType = 'video';
|
|
|
|
|
@ -137,28 +69,11 @@ export class PushService {
|
|
|
|
|
notification.MessageType = 'text';
|
|
|
|
|
}
|
|
|
|
|
this.sharedService.setSharedData(notification, NotificationModel.SHARED_DATA);
|
|
|
|
|
//this.ngZone.run(async () => this.cs.openNotificationDetails());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private setAsReadNotification(notification: NotificationModel) {
|
|
|
|
|
notification.IsRead = true;
|
|
|
|
|
// this.notifyService.setNotificationRead(notification, () => {
|
|
|
|
|
// }).subscribe((result: Response) => {
|
|
|
|
|
// if (this.cs.validResponse(result)) {
|
|
|
|
|
// this.events.publish( NotificationsCenterService.NOTIFICATIONS_COUNT_EVENT, notification.count);
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public stopNotifications(done: any) {
|
|
|
|
|
// Delete a channel (Android O and above)
|
|
|
|
|
// if (this.cs.isCordova()) {
|
|
|
|
|
// this.push.deleteChannel(PushService.CHANNEL_ID).then(() => {
|
|
|
|
|
// done();
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private registerInBackend(data: any) {
|
|
|
|
|
@ -166,14 +81,7 @@ export class PushService {
|
|
|
|
|
if (data) {
|
|
|
|
|
this.cs.sharedService.setSharedData(data, AuthenticationService.DEVICE_TOKEN);
|
|
|
|
|
localStorage.setItem('deviceToken', data);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
// if (this.authService.isAuthenticated()) {
|
|
|
|
|
// this.registerAuthenticatedUser(data);
|
|
|
|
|
// } else {
|
|
|
|
|
// this.registerNotAuthenticatedUser(data);
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -198,7 +106,6 @@ export class PushService {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private registerNotAuthenticatedUser(deviceToken: any) {
|
|
|
|
|
const request = new RegisterNormalUserRequest();
|
|
|
|
|
this.authService.setPublicFields(request);
|
|
|
|
|
@ -220,26 +127,13 @@ export class PushService {
|
|
|
|
|
|
|
|
|
|
private processStartReceivingWithFirebase() {
|
|
|
|
|
console.log("processStartReceivingWithFirebase");
|
|
|
|
|
|
|
|
|
|
this.firebasex.getToken().then(token => {
|
|
|
|
|
// alert("token: "+ token);
|
|
|
|
|
this.cs.sharedService.setSharedData(token, "new-device-token");
|
|
|
|
|
localStorage.setItem('deviceToken', token);
|
|
|
|
|
this.cs.setDeviceToken(token); //last way to set the device Token to get it through getDeviceToken
|
|
|
|
|
|
|
|
|
|
this.registerInBackend(token);
|
|
|
|
|
|
|
|
|
|
}).catch(error => console.error('Error getting token', error));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// this.firebase.getToken()
|
|
|
|
|
// .then(token => console.log(`The token is ${token}`))
|
|
|
|
|
// .catch(error => console.error('Error getting token', error));
|
|
|
|
|
|
|
|
|
|
// this.firebasex.onTokenRefresh().subscribe(token => {
|
|
|
|
|
// alert("token: "+ token);
|
|
|
|
|
// this.registerInBackend(token);
|
|
|
|
|
// });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public onPushReceived(payload: any) {
|
|
|
|
|
@ -253,10 +147,4 @@ export class PushService {
|
|
|
|
|
console.log("onPushOpened openConference");
|
|
|
|
|
this.processNotification(payload);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|