about summary refs log tree commit diff
path: root/src/lib/notifications/notifications.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/notifications/notifications.ts')
-rw-r--r--src/lib/notifications/notifications.ts61
1 files changed, 44 insertions, 17 deletions
diff --git a/src/lib/notifications/notifications.ts b/src/lib/notifications/notifications.ts
index 01b0ba935..73f9c56f6 100644
--- a/src/lib/notifications/notifications.ts
+++ b/src/lib/notifications/notifications.ts
@@ -3,6 +3,7 @@ import {RootStoreModel} from '../../state'
 import {resetToTab} from '../../Navigation'
 import {devicePlatform, isIOS} from 'platform/detection'
 import {track} from 'lib/analytics/analytics'
+import {logger} from '#/logger'
 
 const SERVICE_DID = (serviceUrl?: string) =>
   serviceUrl?.includes('staging')
@@ -29,19 +30,27 @@ export function init(store: RootStoreModel) {
           token: token.data,
           appId: 'xyz.blueskyweb.app',
         })
-        store.log.debug('Notifications: Sent push token (init)', {
-          tokenType: token.type,
-          token: token.data,
-        })
+        logger.debug(
+          'Notifications: Sent push token (init)',
+          {
+            tokenType: token.type,
+            token: token.data,
+          },
+          logger.DebugContext.notifications,
+        )
       } catch (error) {
-        store.log.error('Notifications: Failed to set push token', {error})
+        logger.error('Notifications: Failed to set push token', {error})
       }
     }
 
     // listens for new changes to the push token
     // In rare situations, a push token may be changed by the push notification service while the app is running. When a token is rolled, the old one becomes invalid and sending notifications to it will fail. A push token listener will let you handle this situation gracefully by registering the new token with your backend right away.
     Notifications.addPushTokenListener(async ({data: t, type}) => {
-      store.log.debug('Notifications: Push token changed', {t, tokenType: type})
+      logger.debug(
+        'Notifications: Push token changed',
+        {t, tokenType: type},
+        logger.DebugContext.notifications,
+      )
       if (t) {
         try {
           await store.agent.api.app.bsky.notification.registerPush({
@@ -50,12 +59,16 @@ export function init(store: RootStoreModel) {
             token: t,
             appId: 'xyz.blueskyweb.app',
           })
-          store.log.debug('Notifications: Sent push token (event)', {
-            tokenType: type,
-            token: t,
-          })
+          logger.debug(
+            'Notifications: Sent push token (event)',
+            {
+              tokenType: type,
+              token: t,
+            },
+            logger.DebugContext.notifications,
+          )
         } catch (error) {
-          store.log.error('Notifications: Failed to set push token', {error})
+          logger.error('Notifications: Failed to set push token', {error})
         }
       }
     })
@@ -63,7 +76,11 @@ export function init(store: RootStoreModel) {
 
   // handle notifications that are received, both in the foreground or background
   Notifications.addNotificationReceivedListener(event => {
-    store.log.debug('Notifications: received', {event})
+    logger.debug(
+      'Notifications: received',
+      {event},
+      logger.DebugContext.notifications,
+    )
     if (event.request.trigger.type === 'push') {
       // refresh notifications in the background
       store.me.notifications.syncQueue()
@@ -75,7 +92,11 @@ export function init(store: RootStoreModel) {
         // TODO: handle android payload deeplink
       }
       if (payload) {
-        store.log.debug('Notifications: received payload', payload)
+        logger.debug(
+          'Notifications: received payload',
+          payload,
+          logger.DebugContext.notifications,
+        )
         // TODO: deeplink notif here
       }
     }
@@ -84,14 +105,20 @@ export function init(store: RootStoreModel) {
   // handle notifications that are tapped on
   const sub = Notifications.addNotificationResponseReceivedListener(
     response => {
-      store.log.debug('Notifications: response received', {
-        actionIdentifier: response.actionIdentifier,
-      })
+      logger.debug(
+        'Notifications: response received',
+        {
+          actionIdentifier: response.actionIdentifier,
+        },
+        logger.DebugContext.notifications,
+      )
       if (
         response.actionIdentifier === Notifications.DEFAULT_ACTION_IDENTIFIER
       ) {
-        store.log.debug(
+        logger.debug(
           'User pressed a notification, opening notifications tab',
+          {},
+          logger.DebugContext.notifications,
         )
         track('Notificatons:OpenApp')
         store.me.notifications.refresh() // refresh notifications