diff options
author | Samuel Newman <mozzius@protonmail.com> | 2024-03-20 15:37:14 +0000 |
---|---|---|
committer | Samuel Newman <mozzius@protonmail.com> | 2024-03-20 15:37:14 +0000 |
commit | d24ffba01d7aa5a505b4e3d319dfecffc3d039ca (patch) | |
tree | 4e860ca6a6dd038f41bba1839d180177b70c877b /src/lib | |
parent | 2fa26ceedc1c7f6f3c4a1bdeab621b34c24bcb17 (diff) | |
parent | 023e12bb4ec1dade373c810a13d8bba6d96a22be (diff) | |
download | voidsky-d24ffba01d7aa5a505b4e3d319dfecffc3d039ca.tar.zst |
Merge remote-tracking branch 'origin/main' into samuel/alf-login
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/hooks/useAccountSwitcher.ts | 8 | ||||
-rw-r--r-- | src/lib/hooks/useWebBodyScrollLock.ts | 2 | ||||
-rw-r--r-- | src/lib/media/picker.e2e.tsx | 3 | ||||
-rw-r--r-- | src/lib/moderation/useModerationCauseDescription.ts | 6 | ||||
-rw-r--r-- | src/lib/notifications/notifications.ts | 2 | ||||
-rw-r--r-- | src/lib/statsig/events.ts | 16 | ||||
-rw-r--r-- | src/lib/statsig/statsig.tsx | 29 |
7 files changed, 60 insertions, 6 deletions
diff --git a/src/lib/hooks/useAccountSwitcher.ts b/src/lib/hooks/useAccountSwitcher.ts index 74b5674d5..eb1685a0a 100644 --- a/src/lib/hooks/useAccountSwitcher.ts +++ b/src/lib/hooks/useAccountSwitcher.ts @@ -6,6 +6,7 @@ import {useSessionApi, SessionAccount} from '#/state/session' import * as Toast from '#/view/com/util/Toast' import {useCloseAllActiveElements} from '#/state/util' import {useLoggedOutViewControls} from '#/state/shell/logged-out' +import {LogEvents} from '../statsig/statsig' export function useAccountSwitcher() { const {track} = useAnalytics() @@ -14,7 +15,10 @@ export function useAccountSwitcher() { const {requestSwitchToAccount} = useLoggedOutViewControls() const onPressSwitchAccount = useCallback( - async (account: SessionAccount) => { + async ( + account: SessionAccount, + logContext: LogEvents['account:loggedIn']['logContext'], + ) => { track('Settings:SwitchAccountButtonClicked') try { @@ -28,7 +32,7 @@ export function useAccountSwitcher() { // So we change the URL ourselves. The navigator will pick it up on remount. history.pushState(null, '', '/') } - await selectAccount(account) + await selectAccount(account, logContext) setTimeout(() => { Toast.show(`Signed in as @${account.handle}`) }, 100) diff --git a/src/lib/hooks/useWebBodyScrollLock.ts b/src/lib/hooks/useWebBodyScrollLock.ts index 585f193f1..0dcf911fe 100644 --- a/src/lib/hooks/useWebBodyScrollLock.ts +++ b/src/lib/hooks/useWebBodyScrollLock.ts @@ -6,6 +6,7 @@ let refCount = 0 function incrementRefCount() { if (refCount === 0) { document.body.style.overflow = 'hidden' + document.documentElement.style.scrollbarGutter = 'auto' } refCount++ } @@ -14,6 +15,7 @@ function decrementRefCount() { refCount-- if (refCount === 0) { document.body.style.overflow = '' + document.documentElement.style.scrollbarGutter = '' } } diff --git a/src/lib/media/picker.e2e.tsx b/src/lib/media/picker.e2e.tsx index d7b608041..31702ab22 100644 --- a/src/lib/media/picker.e2e.tsx +++ b/src/lib/media/picker.e2e.tsx @@ -3,7 +3,6 @@ import RNFS from 'react-native-fs' import {CropperOptions} from './types' import {compressIfNeeded} from './manip' -let _imageCounter = 0 async function getFile() { let files = await RNFS.readDir( RNFS.LibraryDirectoryPath.split('/') @@ -12,7 +11,7 @@ async function getFile() { .join('/'), ) files = files.filter(file => file.path.endsWith('.JPG')) - const file = files[_imageCounter++ % files.length] + const file = files[0] return await compressIfNeeded({ path: file.path, mime: 'image/jpeg', diff --git a/src/lib/moderation/useModerationCauseDescription.ts b/src/lib/moderation/useModerationCauseDescription.ts index 46771e958..57b50d777 100644 --- a/src/lib/moderation/useModerationCauseDescription.ts +++ b/src/lib/moderation/useModerationCauseDescription.ts @@ -118,11 +118,15 @@ export function useModerationCauseDescription( (labeler?.creator.handle ? '@' + labeler?.creator.handle : undefined) if (!source) { if (cause.label.src === BSKY_LABELER_DID) { - source = 'Bluesky Moderation' + source = 'Bluesky Moderation Service' } else { source = cause.label.src } } + if (def.identifier === 'porn' || def.identifier === 'sexual') { + strings.name = 'Adult Content' + } + return { icon: def.identifier === '!no-unauthenticated' diff --git a/src/lib/notifications/notifications.ts b/src/lib/notifications/notifications.ts index 62d0bfc4b..e811f690e 100644 --- a/src/lib/notifications/notifications.ts +++ b/src/lib/notifications/notifications.ts @@ -7,6 +7,7 @@ import {logger} from '#/logger' import {RQKEY as RQKEY_NOTIFS} from '#/state/queries/notifications/feed' import {truncateAndInvalidate} from '#/state/queries/util' import {SessionAccount, getAgent} from '#/state/session' +import {logEvent} from '../statsig/statsig' const SERVICE_DID = (serviceUrl?: string) => serviceUrl?.includes('staging') @@ -123,6 +124,7 @@ export function init(queryClient: QueryClient) { logger.DebugContext.notifications, ) track('Notificatons:OpenApp') + logEvent('notifications:openApp', {}) truncateAndInvalidate(queryClient, RQKEY_NOTIFS()) resetToTab('NotificationsTab') // open notifications tab } diff --git a/src/lib/statsig/events.ts b/src/lib/statsig/events.ts index fa7e597fb..b83095976 100644 --- a/src/lib/statsig/events.ts +++ b/src/lib/statsig/events.ts @@ -2,10 +2,26 @@ export type LogEvents = { init: { initMs: number } + 'account:loggedIn': { + logContext: 'LoginForm' | 'SwitchAccount' | 'ChooseAccountForm' | 'Settings' + withPassword: boolean + } + 'account:loggedOut': { + logContext: 'SwitchAccount' | 'Settings' | 'Deactivated' + } + 'notifications:openApp': {} + 'state:background': { + secondsActive: number + } + 'state:foreground': {} 'feed:endReached': { feedType: string itemCount: number } + 'feed:refresh': { + feedType: string + reason: 'pull-to-refresh' | 'soft-reset' | 'load-latest' + } 'post:create': { imageCount: number isReply: boolean diff --git a/src/lib/statsig/statsig.tsx b/src/lib/statsig/statsig.tsx index 5745d204a..9fa6cce2d 100644 --- a/src/lib/statsig/statsig.tsx +++ b/src/lib/statsig/statsig.tsx @@ -1,9 +1,11 @@ import React from 'react' +import {Platform} from 'react-native' import { Statsig, StatsigProvider, useGate as useStatsigGate, } from 'statsig-react-native-expo' +import {AppState, AppStateStatus} from 'react-native' import {useSession} from '../../state/session' import {sha256} from 'js-sha256' import {LogEvents} from './events' @@ -58,9 +60,34 @@ function toStatsigUser(did: string | undefined) { if (did) { userID = sha256(did) } - return {userID} + return { + userID, + platform: Platform.OS, + } } +let lastState: AppStateStatus = AppState.currentState +let lastActive = lastState === 'active' ? performance.now() : null +AppState.addEventListener('change', (state: AppStateStatus) => { + if (state === lastState) { + return + } + lastState = state + if (state === 'active') { + lastActive = performance.now() + logEvent('state:foreground', {}) + } else { + let secondsActive = 0 + if (lastActive != null) { + secondsActive = Math.round((performance.now() - lastActive) / 1e3) + } + lastActive = null + logEvent('state:background', { + secondsActive, + }) + } +}) + export function Provider({children}: {children: React.ReactNode}) { const {currentAccount} = useSession() const currentStatsigUser = React.useMemo( |