-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #353 from e-picsa/ft-push-notifications
Add push notifications service
- Loading branch information
Showing
12 changed files
with
111 additions
and
63 deletions.
There are no files selected for viewing
3 changes: 0 additions & 3 deletions
3
apps/picsa-apps/extension-app-native/android/.idea/.gitignore
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
apps/picsa-apps/extension-app-native/android/.idea/compiler.xml
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
apps/picsa-apps/extension-app-native/android/.idea/jarRepositories.xml
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
apps/picsa-apps/extension-app-native/android/.idea/misc.xml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
apps/picsa-apps/extension-app-native/android/gradle/wrapper/gradle-wrapper.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
libs/shared/src/services/core/push-notifications.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { ActionPerformed, PushNotifications, PushNotificationSchema, Token } from '@capacitor/push-notifications'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class PicsaPushNotificationService { | ||
//constructor() {} | ||
|
||
public async initializePushNotifications() { | ||
try { | ||
// Check if permission is already granted | ||
const permResult = await PushNotifications.checkPermissions(); | ||
|
||
if (permResult.receive === 'prompt' || permResult.receive === 'prompt-with-rationale') { | ||
// Request permissions | ||
const reqResult = await PushNotifications.requestPermissions(); | ||
if (reqResult.receive !== 'granted') { | ||
console.error('Push notification permission was denied'); | ||
return; | ||
} | ||
} | ||
// Register with Apple / Google to receive push via FCM | ||
await PushNotifications.register(); | ||
|
||
// Remove any existing listeners to prevent duplicates | ||
await PushNotifications.removeAllListeners(); | ||
|
||
// Add listeners | ||
PushNotifications.addListener('registration', (token: Token) => { | ||
console.log('Push registration success'); | ||
// in case we have logic to save and update device tokens | ||
//this.sendTokenToServer(token.value); | ||
}); | ||
|
||
PushNotifications.addListener('registrationError', (error: any) => { | ||
// handle error logic | ||
console.error('Error on registration:', error); | ||
}); | ||
|
||
PushNotifications.addListener('pushNotificationReceived', (notification: PushNotificationSchema) => { | ||
console.log('Push received'); | ||
// Handle foreground notification if required | ||
this.handleForegroundNotification(notification); | ||
}); | ||
|
||
PushNotifications.addListener('pushNotificationActionPerformed', (notification: ActionPerformed) => { | ||
console.log('Push action performed'); | ||
// Handle notification click | ||
this.handleNotificationClick(notification); | ||
}); | ||
} catch (err) { | ||
console.error('Error initializing push notifications:', err); | ||
} | ||
} | ||
|
||
private async sendTokenToServer(token: string) { | ||
//TODO: Implement sending token to your backend if required | ||
//guidence on where we can save this | ||
} | ||
|
||
private handleForegroundNotification(notification: PushNotificationSchema) { | ||
// Implement custom foreground notification handling | ||
} | ||
|
||
private handleNotificationClick(actionPerformed: ActionPerformed) { | ||
// Implement navigation or other actions when notification is clicked | ||
const notification = actionPerformed.notification; | ||
// in the case notification has extra infromations like a route to navigate to | ||
// this.router.navigate([notification.data.route]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters