|
|
|
@@ -24,11 +24,13 @@ export class NotificationsService {
|
|
|
|
|
DataArray = new Array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
callbacks: {[key: string]: {
|
|
|
|
|
type: notificationObject,
|
|
|
|
|
funx: Function
|
|
|
|
|
id: string
|
|
|
|
|
}} = {}
|
|
|
|
|
callbacks: {
|
|
|
|
|
[key: string]: {
|
|
|
|
|
type: notificationObject,
|
|
|
|
|
funx: Function
|
|
|
|
|
id: string
|
|
|
|
|
}
|
|
|
|
|
} = {}
|
|
|
|
|
|
|
|
|
|
active = false
|
|
|
|
|
isPushNotificationsAvailable = Capacitor.isPluginAvailable('PushNotifications');
|
|
|
|
@@ -85,8 +87,8 @@ export class NotificationsService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
requestPermissions() {
|
|
|
|
|
if(!this.isPushNotificationsAvailable) {
|
|
|
|
|
return false
|
|
|
|
|
if (!this.isPushNotificationsAvailable) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PushNotifications.requestPermissions().then(result => {
|
|
|
|
@@ -100,36 +102,36 @@ export class NotificationsService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getAndpostToken(username) {
|
|
|
|
|
if(!this.isPushNotificationsAvailable) {
|
|
|
|
|
return false
|
|
|
|
|
if (!this.isPushNotificationsAvailable) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const geturl = environment.apiURL + 'notifications/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
|
|
|
|
|
};
|
|
|
|
|
const headers = { 'Authorization': SessionStore.user.BasicAuthKey };
|
|
|
|
|
const body = {
|
|
|
|
|
UserId: SessionStore.user.UserId,
|
|
|
|
|
TokenId: token.value,
|
|
|
|
|
Status: 1,
|
|
|
|
|
Service: 1
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.http.post<Tokenn>(`${geturl}`, body, { headers }).subscribe(data => {
|
|
|
|
|
this.active = true
|
|
|
|
|
console.log(data)
|
|
|
|
|
}, (error) => {
|
|
|
|
|
console.log(error)
|
|
|
|
|
})
|
|
|
|
|
this.http.post<Tokenn>(`${geturl}`, body, { headers }).subscribe(data => {
|
|
|
|
|
this.active = true
|
|
|
|
|
console.log(data)
|
|
|
|
|
}, (error) => {
|
|
|
|
|
console.log(error)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
registrationError() {
|
|
|
|
|
if(!this.isPushNotificationsAvailable) {
|
|
|
|
|
return false
|
|
|
|
|
if (!this.isPushNotificationsAvailable) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PushNotifications.addListener('registrationError',
|
|
|
|
@@ -140,44 +142,44 @@ export class NotificationsService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onReciveForeground() {
|
|
|
|
|
if(!this.isPushNotificationsAvailable) {
|
|
|
|
|
return false
|
|
|
|
|
if (!this.isPushNotificationsAvailable) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('foregrund');
|
|
|
|
|
PushNotifications.addListener('pushNotificationReceived',
|
|
|
|
|
(notification: PushNotificationSchema) => {
|
|
|
|
|
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.runNotificationCallback(notification)
|
|
|
|
|
/* this.eventTriger.publish('notificatioRecive') */
|
|
|
|
|
this.eventtrigger.publishSomeData({
|
|
|
|
|
notification: "recive"
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
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.runNotificationCallback(notification)
|
|
|
|
|
/* this.eventTriger.publish('notificatioRecive') */
|
|
|
|
|
this.eventtrigger.publishSomeData({
|
|
|
|
|
notification: "recive"
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onReciveBackground() {
|
|
|
|
|
if(!this.isPushNotificationsAvailable) {
|
|
|
|
|
return false
|
|
|
|
|
if (!this.isPushNotificationsAvailable) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('fbackgrund');
|
|
|
|
|
PushNotifications.addListener('pushNotificationActionPerformed',
|
|
|
|
|
(notification: ActionPerformed) => {
|
|
|
|
|
PushNotifications.addListener('pushNotificationActionPerformed',
|
|
|
|
|
(notification: ActionPerformed) => {
|
|
|
|
|
this.active = true
|
|
|
|
|
console.log(notification)
|
|
|
|
|
/* this.DataArray.push(notification.notification)
|
|
|
|
@@ -186,45 +188,48 @@ export class NotificationsService {
|
|
|
|
|
this.eventtrigger.publishSomeData({
|
|
|
|
|
notification: "recive"
|
|
|
|
|
}) */
|
|
|
|
|
this.notificatinsRoutes(notification)
|
|
|
|
|
// this.runNotificationCallback(notification)
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
this.notificatinsRoutes(notification)
|
|
|
|
|
// this.runNotificationCallback(notification)
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ChatSendMessageNotification(userID,title,bodymsg,roomId) {
|
|
|
|
|
ChatSendMessageNotification(userID, title, bodymsg, roomId) {
|
|
|
|
|
const geturl = environment.apiURL + `notifications/sendbyUsername`;
|
|
|
|
|
|
|
|
|
|
const headers = { 'Authorization': SessionStore.user.BasicAuthKey };
|
|
|
|
|
const message = {
|
|
|
|
|
"Service": "chat",
|
|
|
|
|
"IdObject": roomId
|
|
|
|
|
}
|
|
|
|
|
let id = 437
|
|
|
|
|
console.log(userID,title,bodymsg,roomId)
|
|
|
|
|
this.http.post<Tokenn>(geturl+`?username=${userID}&title=${title}&body=${bodymsg}`, message, { headers }).subscribe(data => {
|
|
|
|
|
this.active = true
|
|
|
|
|
console.log(data)
|
|
|
|
|
}, (error) => {
|
|
|
|
|
console.log(error)
|
|
|
|
|
})
|
|
|
|
|
const message = {
|
|
|
|
|
"Service": "chat",
|
|
|
|
|
"IdObject": roomId
|
|
|
|
|
}
|
|
|
|
|
let id = 437
|
|
|
|
|
console.log(userID, title, bodymsg, roomId)
|
|
|
|
|
this.http.post<Tokenn>(geturl + `?username=${userID}&title=${title}&body=${bodymsg}`, message, { headers }).subscribe(data => {
|
|
|
|
|
this.active = true
|
|
|
|
|
console.log(data)
|
|
|
|
|
}, (error) => {
|
|
|
|
|
console.log(error)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ChatSendMessageNotificationGrup(userID,title,bodymsg,roomId) {
|
|
|
|
|
const geturl = environment.apiURL + `notifications/send`;
|
|
|
|
|
ChatSendMessageNotificationGrup(usersID, title, bodymsg, roomId) {
|
|
|
|
|
const geturl = environment.apiURL + `notifications/sendByUsernames`;
|
|
|
|
|
|
|
|
|
|
const headers = { 'Authorization': SessionStore.user.BasicAuthKey };
|
|
|
|
|
const message = {
|
|
|
|
|
"Service": "chat",
|
|
|
|
|
"IdObject": roomId
|
|
|
|
|
}
|
|
|
|
|
console.log(userID,title,bodymsg,roomId)
|
|
|
|
|
this.http.post<Tokenn>(geturl+`?userId=${userID}&title=${title}&body=${bodymsg}`, message, { headers }).subscribe(data => {
|
|
|
|
|
this.active = true
|
|
|
|
|
console.log(data)
|
|
|
|
|
}, (error) => {
|
|
|
|
|
console.log(error)
|
|
|
|
|
})
|
|
|
|
|
const message = {
|
|
|
|
|
"Users": usersID,
|
|
|
|
|
"NotificationData": {
|
|
|
|
|
"Service": "chat",
|
|
|
|
|
"IdObject": roomId
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
console.log(usersID, title, bodymsg, roomId)
|
|
|
|
|
this.http.post<Tokenn>(geturl + `?title=${title}&body=${bodymsg}`, message, { headers }).subscribe(data => {
|
|
|
|
|
this.active = true
|
|
|
|
|
console.log(data)
|
|
|
|
|
}, (error) => {
|
|
|
|
|
console.log(error)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tempClearArray(data) {
|
|
|
|
@@ -234,51 +239,51 @@ export class NotificationsService {
|
|
|
|
|
|
|
|
|
|
notificatinsRoutes = (notification) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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']));
|
|
|
|
|
|
|
|
|
|
} else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "despachos") {
|
|
|
|
|
if (notification.notification.data.Service === "agenda" && notification.notification.data.IdObject.length > 10) {
|
|
|
|
|
|
|
|
|
|
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/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/gabinete-digital/pedidos', notification.notification.data.IdObject, 'gabinete-digital']));
|
|
|
|
|
}
|
|
|
|
|
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "deferimento") {
|
|
|
|
|
} else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "despachos") {
|
|
|
|
|
|
|
|
|
|
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', 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-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/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/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']));
|
|
|
|
|
} else if (notification.notification.data.Service === "chat") {
|
|
|
|
|
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/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']));
|
|
|
|
|
} else if (notification.notification.data.Service === "chat") {
|
|
|
|
|
let navigationExtras: NavigationExtras = { queryParams: { "roomId": notification.notification.data.IdObject, } };
|
|
|
|
|
this.zone.run(() => this.router.navigate(['/home/chat'], navigationExtras));
|
|
|
|
|
}
|
|
|
|
|