Skip to content

Commit

Permalink
feat: Push notifications using cloud messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
l00pinfinity committed Aug 25, 2023
1 parent f11ec24 commit f448088
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 deletions.
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@capacitor/core": "4.3.0",
"@capacitor/haptics": "4.0.1",
"@capacitor/keyboard": "4.0.1",
"@capacitor/push-notifications": "^4.1.2",
"@capacitor/splash-screen": "^4.2.0",
"@capacitor/status-bar": "4.0.1",
"@ionic/angular": "^6.1.9",
Expand Down
1 change: 1 addition & 0 deletions src/app/components/auth/pages/profile/profile.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ <h2 class="section-header">Account</h2>
</ion-row>

<ion-progress-bar *ngIf="!userProfile$" type="indeterminate"></ion-progress-bar>
<ion-progress-bar *ngIf="images?.length < 0" type="indeterminate"></ion-progress-bar>

<ion-item-group class="shadow-none rounded">
<ion-item-divider>
Expand Down
4 changes: 2 additions & 2 deletions src/app/components/home/home.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ <h2 class="section-header">{{welcomeMessage}}</h2>
<button class="top-right-button" (click)="openProfile()">
<ion-icon name="person-outline"></ion-icon>
</button>
<button class="top-right-button" (click)="openNotification()">
<!-- <button class="top-right-button" (click)="openNotification()">
<ion-icon name="notifications-outline"></ion-icon>
</button>
</button> -->
<button id="open-modal" class="top-right-button" (click)="openModal()">
<ion-icon name="add-outline"></ion-icon>
</button>
Expand Down
37 changes: 36 additions & 1 deletion src/app/components/home/home.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import { DocumentSnapshot } from '@angular/fire/firestore';
import { OnlineStatusService, OnlineStatusType } from 'ngx-online-status';
import { Subscription } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { Router, ActivatedRoute } from '@angular/router';
import {
ActionPerformed,
PushNotificationSchema,
PushNotifications,
Token,
} from '@capacitor/push-notifications';

@Component({
selector: 'app-home',
Expand Down Expand Up @@ -54,6 +59,36 @@ export class HomePage implements OnInit, OnDestroy {
this.checkOnlineStatus();
this.presentingElement = document.querySelector('.ion-page');
this.fetchImagePosts();
this.notificationStatus();
}

notificationStatus() {
PushNotifications.requestPermissions().then((result) => {
if (result.receive === 'granted') {
PushNotifications.register();
} else {

}
});

// On success, we should be able to receive notifications
PushNotifications.addListener('registration', (token: Token) => {
});

// Some issue with our setup and push will not work
PushNotifications.addListener('registrationError', (error: any) => {});

// Show us the notification payload if the app is open on our device
PushNotifications.addListener(
'pushNotificationReceived',
(notification: PushNotificationSchema) => {}
);

// Method called when tapping on a notification
PushNotifications.addListener(
'pushNotificationActionPerformed',
(notification: ActionPerformed) => {}
);
}

ngOnDestroy() {
Expand Down

0 comments on commit f448088

Please sign in to comment.