Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[AAv2] Drop regionCode if we can't get a short code on Android (#9542)

* Drop regionCode if we can't get a short code on Android

* Add a debug metric

authored by

Eric Bailey and committed by
GitHub
8d5b1c83 37a73b17

+39 -9
+16 -5
src/ageAssurance/useBeginAgeAssurance.ts
··· 1 import {type AppBskyAgeassuranceBegin, AtpAgent} from '@atproto/api' 2 import {useMutation} from '@tanstack/react-query' 3 ··· 8 PUBLIC_APPVIEW_DID, 9 } from '#/lib/constants' 10 import {isNetworkError} from '#/lib/hooks/useCleanError' 11 - import {logger} from '#/logger' 12 import {useAgent} from '#/state/session' 13 import {usePatchAgeAssuranceServerState} from '#/ageAssurance' 14 import {BLUESKY_PROXY_DID} from '#/env' 15 import {useGeolocation} from '#/geolocation' 16 ··· 29 'countryCode' | 'regionCode' 30 >, 31 ) { 32 - const countryCode = geolocation?.countryCode 33 - const regionCode = geolocation?.regionCode 34 if (!countryCode) { 35 throw new Error(`Geolocation not available, cannot init age assurance.`) 36 } ··· 47 appView.sessionManager.session.accessJwt = token 48 appView.sessionManager.session.refreshJwt = '' 49 50 /* 51 * 2s wait is good actually. Email sending takes a hot sec and this helps 52 * ensure the email is ready for the user once they open their inbox. ··· 55 2e3, 56 appView.app.bsky.ageassurance.begin({ 57 ...props, 58 - countryCode: countryCode.toUpperCase(), 59 - regionCode: regionCode ? regionCode.toUpperCase() : undefined, 60 }), 61 ) 62
··· 1 + import {Platform} from 'react-native' 2 import {type AppBskyAgeassuranceBegin, AtpAgent} from '@atproto/api' 3 import {useMutation} from '@tanstack/react-query' 4 ··· 9 PUBLIC_APPVIEW_DID, 10 } from '#/lib/constants' 11 import {isNetworkError} from '#/lib/hooks/useCleanError' 12 import {useAgent} from '#/state/session' 13 import {usePatchAgeAssuranceServerState} from '#/ageAssurance' 14 + import {logger} from '#/ageAssurance/logger' 15 import {BLUESKY_PROXY_DID} from '#/env' 16 import {useGeolocation} from '#/geolocation' 17 ··· 30 'countryCode' | 'regionCode' 31 >, 32 ) { 33 + const countryCode = geolocation?.countryCode?.toUpperCase() 34 + const regionCode = geolocation?.regionCode?.toUpperCase() 35 if (!countryCode) { 36 throw new Error(`Geolocation not available, cannot init age assurance.`) 37 } ··· 48 appView.sessionManager.session.accessJwt = token 49 appView.sessionManager.session.refreshJwt = '' 50 51 + logger.metric( 52 + 'ageAssurance:api:begin', 53 + { 54 + platform: Platform.OS, 55 + countryCode, 56 + regionCode, 57 + }, 58 + {statsig: false}, 59 + ) 60 + 61 /* 62 * 2s wait is good actually. Email sending takes a hot sec and this helps 63 * ensure the email is ready for the user once they open their inbox. ··· 66 2e3, 67 appView.app.bsky.ageassurance.begin({ 68 ...props, 69 + countryCode, 70 + regionCode, 71 }), 72 ) 73
+18 -4
src/geolocation/util.ts
··· 1 import {type LocationGeocodedAddress} from 'expo-location' 2 3 import {logger} from '#/geolocation/logger' 4 import {type Geolocation} from '#/geolocation/types' 5 ··· 75 location: LocationGeocodedAddress, 76 ): Geolocation { 77 let {isoCountryCode, region} = location 78 79 - if (region) { 80 - if (isoCountryCode === 'US') { 81 - region = USRegionNameToRegionCode[region] ?? region 82 } 83 } 84 85 return { 86 countryCode: isoCountryCode ?? undefined, 87 - regionCode: region ?? undefined, 88 } 89 } 90
··· 1 import {type LocationGeocodedAddress} from 'expo-location' 2 3 + import {isAndroid} from '#/platform/detection' 4 import {logger} from '#/geolocation/logger' 5 import {type Geolocation} from '#/geolocation/types' 6 ··· 76 location: LocationGeocodedAddress, 77 ): Geolocation { 78 let {isoCountryCode, region} = location 79 + let regionCode: string | undefined = region ?? undefined 80 81 + /* 82 + * Android doesn't give us ISO 3166-2 short codes. We need these for US 83 + */ 84 + if (isAndroid) { 85 + if (region && isoCountryCode === 'US') { 86 + /* 87 + * We need short codes for US states. If we can't remap it, just drop it 88 + * entirely for now. 89 + */ 90 + regionCode = USRegionNameToRegionCode[region] ?? undefined 91 + } else { 92 + /* 93 + * Outside the US, we don't need regionCodes for now, so just drop it. 94 + */ 95 + regionCode = undefined 96 } 97 } 98 99 return { 100 countryCode: isoCountryCode ?? undefined, 101 + regionCode, 102 } 103 } 104
+5
src/logger/metrics.ts
··· 598 hasInitiatedPreviously: boolean 599 } 600 'ageAssurance:initDialogSubmit': {} 601 'ageAssurance:initDialogError': { 602 code: string 603 }
··· 598 hasInitiatedPreviously: boolean 599 } 600 'ageAssurance:initDialogSubmit': {} 601 + 'ageAssurance:api:begin': { 602 + platform: string 603 + countryCode: string 604 + regionCode?: string 605 + } 606 'ageAssurance:initDialogError': { 607 code: string 608 }