This commit is contained in:
Peter Maquiran
2023-09-19 10:21:23 +01:00
parent 527cc0f2a6
commit f51bd246fc
29 changed files with 754 additions and 261 deletions
+36 -18
View File
@@ -34,6 +34,7 @@ export class NotificationsService {
active = false
isPushNotificationsAvailable = Capacitor.isPluginAvailable('PushNotifications');
notificationReceived: EventEmitter<void> = new EventEmitter<void>();
token = ''
constructor(
private http: HttpClient,
@@ -81,6 +82,7 @@ export class NotificationsService {
PushNotifications.addListener('registration',
(token: Token) => {
this.postToken(token.value, geturl)
this.token = token.value
}
);
} else {
@@ -89,6 +91,7 @@ export class NotificationsService {
// Save the token to your server for sending notifications
console.log('Permission granted! Token:', token);
this.postToken(token, geturl)
this.token = token
},
(error) => {
console.error('Permission denied:', error);
@@ -98,6 +101,13 @@ export class NotificationsService {
}
DeletePostToken() {
const geturl = environment.apiURL + `notifications/token?userId=${SessionStore.user.UserId}&tokenId=${this.token}`;
this.DeleteToken(geturl)
}
postToken(token, geturl) {
const headers = { 'Authorization': SessionStore.user.BasicAuthKey };
const body = {
@@ -113,6 +123,19 @@ export class NotificationsService {
})
}
DeleteToken(geturl) {
const headers = { 'Authorization': SessionStore.user.BasicAuthKey };
const body = {};
this.http.delete<Tokenn>(`${geturl}`, { headers, body }).subscribe(data => {
this.active = true
}, (error) => {
})
}
registrationError() {
if (!this.isPushNotificationsAvailable) {
return false
@@ -137,8 +160,8 @@ export class NotificationsService {
this.active = true
console.log('NOtification Listener', notification)
this.storenotification(notification)
}
);
@@ -154,7 +177,7 @@ export class NotificationsService {
}
}
storenotification(notification) {
console.log('Store Notification ',notification)
this.storageService.get("Notifications").then((store) => {
@@ -168,21 +191,21 @@ export class NotificationsService {
let exists = accumulator.find(item => {
return item.id === current.id;
});
if(!exists) {
if(!exists) {
accumulator = accumulator.concat(current);
}
return accumulator;
}, []);
console.log('Notification Result',result);
this.storageService.store("Notifications", result).then(() => {
this.eventtrigger.publishSomeData({
notification: "recive"
})
})
} else {
this.storageService.store("Notifications", store).then(() => {
this.eventtrigger.publishSomeData({
@@ -190,11 +213,6 @@ export class NotificationsService {
})
})
}
}).catch((error) => {
if (!error) {
this.storageService.store("Notifications", [notification])
@@ -208,13 +226,13 @@ export class NotificationsService {
if (!this.isPushNotificationsAvailable) {
return false
}
PushNotifications.addListener('pushNotificationActionPerformed',
(notification: ActionPerformed) => {
this.active = true
console.log('NOtification Listener Backgroud', notification)
/* this.DataArray.push(notification.notification)
this.storageService.store("Notifications", this.DataArray)
this.eventtrigger.publishSomeData({
notification: "recive"
@@ -236,7 +254,7 @@ export class NotificationsService {
}
};
}
}
sendNotificationWithSend(userID, title, bodymsg, roomId) {
@@ -254,7 +272,7 @@ export class NotificationsService {
})
}
ChatSendMessageNotification(userID, title, bodymsg, roomId) {
const geturl = environment.apiURL + `notifications/sendbyUsername`;
@@ -298,7 +316,7 @@ export class NotificationsService {
notificatinsRoutes = (notification) => {
console.log('BACK BACK',notification)
console.log('BACK BACK',notification)
if (notification.notification.data.Service === "agenda" && notification.notification.data.IdObject.length > 10) {