aboutsummaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
Diffstat (limited to 'src/services')
-rw-r--r--src/services/FCMService.ts54
1 files changed, 18 insertions, 36 deletions
diff --git a/src/services/FCMService.ts b/src/services/FCMService.ts
index 11cb7510..b6cd18af 100644
--- a/src/services/FCMService.ts
+++ b/src/services/FCMService.ts
@@ -3,7 +3,7 @@ import messaging from '@react-native-firebase/messaging';
import {Platform} from 'react-native';
import {getDeviceId, getDeviceName} from 'react-native-device-info';
import {FCM_ENDPOINT} from '../constants';
-
+import * as RootNavigation from '../RootNavigation';
class FCMService {
setUpPushNotifications = () => {
// Requesting user to permit notifications
@@ -27,7 +27,7 @@ class FCMService {
// });
// // Send local notification when app in foreground since remote notifications
- // // aren't displayed when app is in the foreground
+ // // aren't displayed when app is in the foreground
// PushNotification.localNotification({
// //... You can use all the options from localNotifications
// message: 'My Notification Message', // (required)
@@ -123,48 +123,30 @@ class FCMService {
};
deactivateFcmService = async () => {
- //Make PATCH call to deactivate device
+ // TODO: Make PATCH call to deactivate device
console.log('Deactivating FCM device');
};
createNotificationListeners = () => {
- // messaging().onNotificationOpenedApp((remoteMessage) => {
- // console.log(
- // '[FCMService] onNotificationOpenedApp Notification caused app to open',
- // );
- // if (remoteMessage) {
- // const notification = remoteMessage.notification;
- // onOpenNotification(notification);
- // }
- // });
-
- // messaging()
- // .getInitialNotification()
- // .then((remoteMessage) => {
- // console.log(
- // '[FCMService] getInitialNotification Notification caused app to open',
- // );
-
- // if (remoteMessage) {
- // const notification = remoteMessage.notification;
- // onOpenNotification(notification);
- // }
- // });
-
- messaging().onMessage((remoteMessage) => {
- console.log('Received a remote notification!!');
+ // Called when app is opened from backrground state
+ messaging().onNotificationOpenedApp((remoteMessage) => {
if (remoteMessage) {
- let notification = remoteMessage.notification;
- let notificationId = remoteMessage.messageId;
- console.log(
- 'notificationsId: ',
- notificationId,
- ' notification: ',
- notification,
- );
+ // TODO: Get {name, params} of screen when user must be redirected to
+ // Redirected to Notification Screen for now
+ const redirectTo = 'Notifications';
+ /* TODO: Check login status and redirect user/store screen to async as
+ initialRoute for NavigationBar Stack */
+ RootNavigation.navigate(redirectTo);
}
});
+ messaging().onMessage((remoteMessage) => {
+ console.log(
+ 'Received a remote notification!!',
+ remoteMessage.notification?.body,
+ );
+ });
+
messaging().onTokenRefresh((fcmToken) => {
AsyncStorage.setItem('@fcmToken', fcmToken).catch((err) => {
console.log('Failed to store new token!');