-
Notifications
You must be signed in to change notification settings - Fork 15
feat: add redirection for notifications + API integrations #4079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: fyle-fix-setup-keys
Are you sure you want to change the base?
Changes from 12 commits
082e946
03f0a14
f5879c7
2e73a08
060f63f
178a224
ce1f560
249829c
e112f85
b8832ae
56ea99a
be63e04
52554fb
5897bb6
d787bac
b26d6e0
88cfed2
f6ec718
a440a25
7cf5cfa
ccbf3f7
2ce020f
8d22251
53013f3
448562f
2d25b9b
2b867db
f418f33
3462fde
82f5600
f070816
721d8ac
c0ba3eb
0815453
d4f18d1
50e8495
7750455
bc25593
a575594
8d3a4ae
4cbbf17
d21b725
afaa507
e55921e
b37f3c8
b32f422
fc141cf
ba510e3
adb990b
ca32a7a
fe356a4
a44f505
67d5a95
99782e3
2603fdc
6424719
3534acc
b280e92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ import { NgClass } from '@angular/common'; | |
| import { FyConnectionComponent } from './shared/components/fy-connection/fy-connection.component'; | ||
| import { Capacitor } from '@capacitor/core'; | ||
| import { AppShortcuts } from '@capawesome/capacitor-app-shortcuts'; | ||
| import { PushNotificationService } from './core/services/push-notification.service'; | ||
|
|
||
| @Component({ | ||
| selector: 'app-root', | ||
|
|
@@ -53,6 +54,8 @@ export class AppComponent implements OnInit, AfterViewInit { | |
|
|
||
| private router = inject(Router); | ||
|
|
||
| private pushNotificationService = inject(PushNotificationService); | ||
|
|
||
| private activatedRoute = inject(ActivatedRoute); | ||
|
|
||
| private userEventService = inject(UserEventService); | ||
|
|
@@ -293,6 +296,7 @@ export class AppComponent implements OnInit, AfterViewInit { | |
| this.userEventService.onLogout(() => { | ||
| this.trackingService.onSignOut(); | ||
| this.freshChatService.destroy(); | ||
| this.pushNotificationService.unregister(); | ||
| this.isSwitchedToDelegator = false; | ||
|
Comment on lines
301
to
305
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle unregister promise (and avoid double-unregister). 🐛 Suggested fix (keep call, guard it)- this.pushNotificationService.unregister();
+ void this.pushNotificationService.unregister().catch(noop);🤖 Prompt for AI Agents |
||
| this.router.navigate(['/', 'auth', 'sign_in']); | ||
| }); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,27 @@ | ||
| import { Injectable } from '@angular/core'; | ||
| import { Injectable, inject } from '@angular/core'; | ||
| import { PushNotifications, Token } from '@capacitor/push-notifications'; | ||
| import { DeepLinkService } from './deep-link.service'; | ||
| import { TrackingService } from './tracking.service'; | ||
| import { UserEventService } from './user-event.service'; | ||
|
|
||
| @Injectable({ | ||
| providedIn: 'root', | ||
| }) | ||
| export class PushNotificationService { | ||
| private listenersInitialized = false; | ||
|
|
||
| private deepLinkService: DeepLinkService = inject(DeepLinkService); | ||
|
|
||
| private trackingService: TrackingService = inject(TrackingService); | ||
|
|
||
| private userEventService: UserEventService = inject(UserEventService); | ||
|
|
||
| constructor() { | ||
| this.userEventService.onLogout(() => { | ||
| void this.unregister(); | ||
| }); | ||
| } | ||
|
|
||
| async initializePushNotifications(): Promise<void> { | ||
| const permission = await PushNotifications.requestPermissions(); | ||
|
|
||
|
|
@@ -16,18 +31,38 @@ | |
| } | ||
| } | ||
|
|
||
| async unregister(): Promise<void> { | ||
| await PushNotifications.unregister(); | ||
| } | ||
|
|
||
| private initListeners(): void { | ||
| if (this.listenersInitialized) { | ||
| return; | ||
| } | ||
|
|
||
| this.listenersInitialized = true; | ||
|
|
||
| PushNotifications.addListener('registration', (_token: Token) => { | ||
| // TODO: Integrate API for sending token to backend | ||
| PushNotifications.addListener('registration', (token: Token) => { | ||
| const tokenValue = token?.value; | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-call | ||
| this.trackingService.eventTrack('Push Notification Registered'); | ||
| }); | ||
| PushNotifications.addListener('registrationError', () => undefined); | ||
| PushNotifications.addListener('pushNotificationActionPerformed', () => undefined); | ||
| PushNotifications.addListener('pushNotificationActionPerformed', (event) => { | ||
| const data = (event?.notification?.data as { url?: string; actionType?: string } | undefined) ?? {}; | ||
| const url = data.url; | ||
| const actionType = data.actionType; | ||
|
|
||
| if (!url || typeof url !== 'string') { | ||
| return; | ||
| } | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-call | ||
| this.trackingService.eventTrack('Push Notification Clicked', { actionType }); | ||
|
|
||
| const redirectParams = this.deepLinkService.getJsonFromUrl(url); | ||
| this.deepLinkService.redirect(redirectParams); | ||
| }); | ||
|
Comment on lines
116
to
134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard deep-link parsing to avoid crash. 🛡️ Suggested fix this.trackingService.eventTrack('Push Notification Clicked', { actionType });
-const redirectParams = this.deepLinkService.getJsonFromUrl(url);
-this.deepLinkService.redirect(redirectParams);
+try {
+ const redirectParams = this.deepLinkService.getJsonFromUrl(url);
+ this.deepLinkService.redirect(redirectParams);
+} catch (error) {
+ this.trackingService.eventTrack('Push Notification Redirect Failed', { error });
+}🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unregisters a token on log out