From a55992c77636e655b2c806eb8ebf42ba233de4ef Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Thu, 3 Jul 2025 14:53:56 +0300 Subject: [PATCH] only check reserved handles for bsky.social, fix test --- __tests__/lib/strings/handles.test.ts | 10 +++++----- src/lib/constants.ts | 3 ++- src/screens/Signup/StepHandle.tsx | 8 ++++++-- src/state/queries/handle-availablility.ts | 6 +++++- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/__tests__/lib/strings/handles.test.ts b/__tests__/lib/strings/handles.test.ts index 4456fae946..1484535b60 100644 --- a/__tests__/lib/strings/handles.test.ts +++ b/__tests__/lib/strings/handles.test.ts @@ -1,4 +1,4 @@ -import {IsValidHandle, validateServiceHandle} from '#/lib/strings/handles' +import {type IsValidHandle, validateServiceHandle} from '#/lib/strings/handles' describe('handle validation', () => { const valid = [ @@ -18,17 +18,17 @@ describe('handle validation', () => { }) const invalid = [ - ['al', 'bsky.social', 'frontLength'], + ['al', 'bsky.social', 'frontLengthLongEnough'], ['-alice', 'bsky.social', 'hyphenStartOrEnd'], ['alice-', 'bsky.social', 'hyphenStartOrEnd'], ['%%%', 'bsky.social', 'handleChars'], - ['1234567890123456789', 'bsky.social', 'frontLength'], + ['1234567890123456789', 'bsky.social', 'frontLengthNotTooLong'], [ '1234567890123456789', 'my-custom-pds-with-long-name.social', - 'frontLength', + 'frontLengthNotTooLong', ], - ['al', 'my-custom-pds-with-long-name.social', 'frontLength'], + ['al', 'my-custom-pds-with-long-name.social', 'frontLengthLongEnough'], ['a'.repeat(300), 'toolong.com', 'totalLength'], ] satisfies [string, string, keyof IsValidHandle][] it.each(invalid)( diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 3f0d499894..b77c884fe3 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -5,6 +5,7 @@ export const LOCAL_DEV_SERVICE = Platform.OS === 'android' ? 'http://10.0.2.2:2583' : 'http://localhost:2583' export const STAGING_SERVICE = 'https://staging.bsky.dev' export const BSKY_SERVICE = 'https://bsky.social' +export const BSKY_SERVICE_HANDLE_ENDSWITH = '.bsky.social' export const PUBLIC_BSKY_SERVICE = 'https://public.api.bsky.app' export const DEFAULT_SERVICE = BSKY_SERVICE const HELP_DESK_LANG = 'en-us' @@ -31,7 +32,7 @@ export const DISCOVER_DEBUG_DIDS: Record = { 'did:plc:3jpt2mvvsumj2r7eqk4gzzjz': true, // esb.lol 'did:plc:vjug55kidv6sye7ykr5faxxn': true, // emilyliu.me 'did:plc:tgqseeot47ymot4zro244fj3': true, // iwsmith.bsky.social - 'did:plc:2dzyut5lxna5ljiaasgeuffz': true, // mrnuma.bsky.social + 'did:plc:2dzyut5lxna5ljiaasgeuffz': true, // darrin.bsky.team } const BASE_FEEDBACK_FORM_URL = `${HELP_DESK_URL}/requests/new` diff --git a/src/screens/Signup/StepHandle.tsx b/src/screens/Signup/StepHandle.tsx index 1790b3bc6f..5bf81ae20d 100644 --- a/src/screens/Signup/StepHandle.tsx +++ b/src/screens/Signup/StepHandle.tsx @@ -9,6 +9,7 @@ import Animated, { import {msg, Plural, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' +import {BSKY_SERVICE_HANDLE_ENDSWITH} from '#/lib/constants' import { createFullHandle, isHandleReserved, @@ -60,7 +61,10 @@ export function StepHandle() { return } - if (isHandleReserved(handle)) { + if ( + state.userDomain === BSKY_SERVICE_HANDLE_ENDSWITH && + isHandleReserved(handle) + ) { dispatch({ type: 'setError', value: _(msg`That username is not available`), @@ -147,7 +151,7 @@ export function StepHandle() { // replace em dash with double hyphen to fix iOS behaviour setDraftValue(val.replaceAll('—', '--')) }} - label="alice.bsky.social" + label={`alice${state.userDomain}`} defaultValue={draftValue} autoCapitalize="none" autoCorrect={false} diff --git a/src/state/queries/handle-availablility.ts b/src/state/queries/handle-availablility.ts index 152d686db5..e1056d45be 100644 --- a/src/state/queries/handle-availablility.ts +++ b/src/state/queries/handle-availablility.ts @@ -1,5 +1,6 @@ import {useQuery} from '@tanstack/react-query' +import {BSKY_SERVICE_HANDLE_ENDSWITH} from '#/lib/constants' import {createFullHandle, isHandleReserved} from '#/lib/strings/handles' import {logger} from '#/logger' import {useAgent} from '#/state/session' @@ -26,7 +27,10 @@ export function useHandleAvailabilityQuery( queryKey: RQKEY_handleAvailability(debouncedHandle), queryFn: async () => { const frontSegment = debouncedHandle.split('.')[0] - if (isHandleReserved(frontSegment)) { + if ( + domain === BSKY_SERVICE_HANDLE_ENDSWITH && + isHandleReserved(frontSegment) + ) { logger.metric( 'signup:handleReserved', {typeahead: true},