diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/analytics/analytics.tsx | 11 | ||||
-rw-r--r-- | src/lib/analytics/analytics.web.tsx | 5 | ||||
-rw-r--r-- | src/lib/api/index.ts | 3 | ||||
-rw-r--r-- | src/lib/hooks/useFollowProfile.ts | 5 | ||||
-rw-r--r-- | src/lib/hooks/useOTAUpdate.ts | 13 | ||||
-rw-r--r-- | src/lib/notifications/notifications.ts | 61 |
6 files changed, 65 insertions, 33 deletions
diff --git a/src/lib/analytics/analytics.tsx b/src/lib/analytics/analytics.tsx index b3db9149c..71bb8569a 100644 --- a/src/lib/analytics/analytics.tsx +++ b/src/lib/analytics/analytics.tsx @@ -10,6 +10,7 @@ import {RootStoreModel, AppInfo} from 'state/models/root-store' import {useStores} from 'state/models/root-store' import {sha256} from 'js-sha256' import {ScreenEvent, TrackEvent} from './types' +import {logger} from '#/logger' const segmentClient = createClient({ writeKey: '8I6DsgfiSLuoONyaunGoiQM7A6y2ybdI', @@ -54,9 +55,9 @@ export function init(store: RootStoreModel) { if (sess.did) { const did_hashed = sha256(sess.did) segmentClient.identify(did_hashed, {did_hashed}) - store.log.debug('Ping w/hash') + logger.debug('Ping w/hash') } else { - store.log.debug('Ping w/o hash') + logger.debug('Ping w/o hash') segmentClient.identify() } } @@ -68,19 +69,19 @@ export function init(store: RootStoreModel) { // -prf segmentClient.isReady.onChange(() => { if (AppState.currentState !== 'active') { - store.log.debug('Prevented a metrics ping while the app was backgrounded') + logger.debug('Prevented a metrics ping while the app was backgrounded') return } const context = segmentClient.context.get() if (typeof context?.app === 'undefined') { - store.log.debug('Aborted metrics ping due to unavailable context') + logger.debug('Aborted metrics ping due to unavailable context') return } const oldAppInfo = store.appInfo const newAppInfo = context.app as AppInfo store.setAppInfo(newAppInfo) - store.log.debug('Recording app info', {new: newAppInfo, old: oldAppInfo}) + logger.debug('Recording app info', {new: newAppInfo, old: oldAppInfo}) if (typeof oldAppInfo === 'undefined') { if (store.session.hasSession) { diff --git a/src/lib/analytics/analytics.web.tsx b/src/lib/analytics/analytics.web.tsx index 78bd9b42b..fe90d1328 100644 --- a/src/lib/analytics/analytics.web.tsx +++ b/src/lib/analytics/analytics.web.tsx @@ -7,6 +7,7 @@ import { import {RootStoreModel} from 'state/models/root-store' import {useStores} from 'state/models/root-store' import {sha256} from 'js-sha256' +import {logger} from '#/logger' const segmentClient = createClient( { @@ -49,9 +50,9 @@ export function init(store: RootStoreModel) { if (sess.did) { const did_hashed = sha256(sess.did) segmentClient.identify(did_hashed, {did_hashed}) - store.log.debug('Ping w/hash') + logger.debug('Ping w/hash') } else { - store.log.debug('Ping w/o hash') + logger.debug('Ping w/o hash') segmentClient.identify() } } diff --git a/src/lib/api/index.ts b/src/lib/api/index.ts index f75ebbd96..9d48a78c0 100644 --- a/src/lib/api/index.ts +++ b/src/lib/api/index.ts @@ -15,6 +15,7 @@ import {LinkMeta} from '../link-meta/link-meta' import {isWeb} from 'platform/detection' import {ImageModel} from 'state/models/media/image' import {shortenLinks} from 'lib/strings/rich-text-manip' +import {logger} from '#/logger' export interface ExternalEmbedDraft { uri: string @@ -178,7 +179,7 @@ export async function post(store: RootStoreModel, opts: PostOpts) { ) { encoding = 'image/jpeg' } else { - store.log.warn('Unexpected image format for thumbnail, skipping', { + logger.warn('Unexpected image format for thumbnail, skipping', { thumbnail: opts.extLink.localThumb.path, }) } diff --git a/src/lib/hooks/useFollowProfile.ts b/src/lib/hooks/useFollowProfile.ts index ca3f7ab8e..98dd63f5f 100644 --- a/src/lib/hooks/useFollowProfile.ts +++ b/src/lib/hooks/useFollowProfile.ts @@ -2,6 +2,7 @@ import React from 'react' import {AppBskyActorDefs} from '@atproto/api' import {useStores} from 'state/index' import {FollowState} from 'state/models/cache/my-follows' +import {logger} from '#/logger' export function useFollowProfile(profile: AppBskyActorDefs.ProfileViewBasic) { const store = useStores() @@ -22,7 +23,7 @@ export function useFollowProfile(profile: AppBskyActorDefs.ProfileViewBasic) { following: false, } } catch (e: any) { - store.log.error('Failed to delete follow', {error: e}) + logger.error('Failed to delete follow', {error: e}) throw e } } else if (state === FollowState.NotFollowing) { @@ -40,7 +41,7 @@ export function useFollowProfile(profile: AppBskyActorDefs.ProfileViewBasic) { following: true, } } catch (e: any) { - store.log.error('Failed to create follow', {error: e}) + logger.error('Failed to create follow', {error: e}) throw e } } diff --git a/src/lib/hooks/useOTAUpdate.ts b/src/lib/hooks/useOTAUpdate.ts index d7855b2d4..0ce97a4c8 100644 --- a/src/lib/hooks/useOTAUpdate.ts +++ b/src/lib/hooks/useOTAUpdate.ts @@ -2,6 +2,7 @@ import * as Updates from 'expo-updates' import {useCallback, useEffect} from 'react' import {AppState} from 'react-native' import {useStores} from 'state/index' +import {logger} from '#/logger' export function useOTAUpdate() { const store = useStores() @@ -21,7 +22,7 @@ export function useOTAUpdate() { }) }, [store.shell]) const checkForUpdate = useCallback(async () => { - store.log.debug('useOTAUpdate: Checking for update...') + logger.debug('useOTAUpdate: Checking for update...') try { // Check if new OTA update is available const update = await Updates.checkForUpdateAsync() @@ -34,16 +35,16 @@ export function useOTAUpdate() { // show a popup modal showUpdatePopup() } catch (e) { - store.log.error('useOTAUpdate: Error while checking for update', { + logger.error('useOTAUpdate: Error while checking for update', { error: e, }) } - }, [showUpdatePopup, store.log]) + }, [showUpdatePopup]) const updateEventListener = useCallback( (event: Updates.UpdateEvent) => { - store.log.debug('useOTAUpdate: Listening for update...') + logger.debug('useOTAUpdate: Listening for update...') if (event.type === Updates.UpdateEventType.ERROR) { - store.log.error('useOTAUpdate: Error while listening for update', { + logger.error('useOTAUpdate: Error while listening for update', { message: event.message, }) } else if (event.type === Updates.UpdateEventType.NO_UPDATE_AVAILABLE) { @@ -55,7 +56,7 @@ export function useOTAUpdate() { showUpdatePopup() } }, - [showUpdatePopup, store.log], + [showUpdatePopup], ) useEffect(() => { 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 |