From e9a67f2dea1eced024d6c1dfd917865f46426095 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Tue, 4 Aug 2026 04:20:51 +0300 Subject: [PATCH] flip the remaining feature, env and test type imports Co-Authored-By: Claude Fable 5 --- __tests__/lib/string.test.ts | 2 +- src/env/common.ts | 3 +-- .../liveNow/components/EditLiveDialog.tsx | 10 ++++---- .../components/GoLiveDisabledDialog.tsx | 9 ++++---- .../liveNow/components/LiveStatusDialog.tsx | 14 +++++------ src/features/liveNow/index.tsx | 23 ++++++++----------- src/features/liveNow/utils.ts | 13 +++++------ src/locale/helpers.ts | 11 +++++---- 8 files changed, 39 insertions(+), 46 deletions(-) diff --git a/__tests__/lib/string.test.ts b/__tests__/lib/string.test.ts index 8a56423796..da34bd0dc6 100644 --- a/__tests__/lib/string.test.ts +++ b/__tests__/lib/string.test.ts @@ -1,4 +1,4 @@ -import {RichText} from '@atproto/api' +import {RichText} from '@bsky.app/sdk/richtext' import {i18n} from '@lingui/core' import {parseEmbedPlayerFromUrl} from '#/lib/strings/embed-player' diff --git a/src/env/common.ts b/src/env/common.ts index 5d8d89aace..f36f671695 100644 --- a/src/env/common.ts +++ b/src/env/common.ts @@ -1,5 +1,4 @@ -import {type Did} from '@atproto/api' - +import {type Did} from '@atproto/syntax' import packageJson from '#/../package.json' /** diff --git a/src/features/liveNow/components/EditLiveDialog.tsx b/src/features/liveNow/components/EditLiveDialog.tsx index cf913541a1..6c9dff3092 100644 --- a/src/features/liveNow/components/EditLiveDialog.tsx +++ b/src/features/liveNow/components/EditLiveDialog.tsx @@ -1,11 +1,11 @@ import {useMemo, useState} from 'react' import {View} from 'react-native' -import {type AppBskyActorDefs, type AppBskyEmbedExternal} from '@atproto/api' import {msg} from '@lingui/core/macro' import {useLingui} from '@lingui/react' import {Trans} from '@lingui/react/macro' import {differenceInMinutes} from 'date-fns' +import {app} from '#/lexicons' import {useDebouncedValue} from '#/lib/hooks/useDebouncedValue' import {cleanError} from '#/lib/strings/errors' import {definitelyUrl} from '#/lib/strings/url-helpers' @@ -33,8 +33,8 @@ export function EditLiveDialog({ embed, }: { control: Dialog.DialogControlProps - status: AppBskyActorDefs.StatusView - embed: AppBskyEmbedExternal.View + status: app.bsky.actor.defs.StatusView + embed: app.bsky.embed.external.View }) { return ( @@ -48,8 +48,8 @@ function DialogInner({ status, embed, }: { - status: AppBskyActorDefs.StatusView - embed: AppBskyEmbedExternal.View + status: app.bsky.actor.defs.StatusView + embed: app.bsky.embed.external.View }) { const control = Dialog.useDialogContext() const {_, i18n} = useLingui() diff --git a/src/features/liveNow/components/GoLiveDisabledDialog.tsx b/src/features/liveNow/components/GoLiveDisabledDialog.tsx index fda33a9067..24324817fc 100644 --- a/src/features/liveNow/components/GoLiveDisabledDialog.tsx +++ b/src/features/liveNow/components/GoLiveDisabledDialog.tsx @@ -1,6 +1,5 @@ import {useCallback, useState} from 'react' import {View} from 'react-native' -import {type AppBskyActorDefs, ToolsOzoneReportDefs} from '@atproto/api' import {type AtUriString} from '@atproto/syntax' import {msg} from '@lingui/core/macro' import {useLingui} from '@lingui/react' @@ -16,14 +15,14 @@ import * as Dialog from '#/components/Dialog' import {Loader} from '#/components/Loader' import * as Toast from '#/components/Toast' import {Text} from '#/components/Typography' -import {com} from '#/lexicons' +import {app, com, tools} from '#/lexicons' export function GoLiveDisabledDialog({ control, status, }: { control: Dialog.DialogControlProps - status: AppBskyActorDefs.StatusView + status: app.bsky.actor.defs.StatusView }) { return ( @@ -38,7 +37,7 @@ export function DialogInner({ status, }: { control: Dialog.DialogControlProps - status: AppBskyActorDefs.StatusView + status: app.bsky.actor.defs.StatusView }) { const {_} = useLingui() const client = useAppviewClient() @@ -61,7 +60,7 @@ export function DialogInner({ await client.call( com.atproto.moderation.createReport, { - reasonType: ToolsOzoneReportDefs.REASONAPPEAL, + reasonType: tools.ozone.report.defs.reasonAppeal, subject: { $type: 'com.atproto.repo.strongRef', // a status view's uri is an at-uri produced by the appview diff --git a/src/features/liveNow/components/LiveStatusDialog.tsx b/src/features/liveNow/components/LiveStatusDialog.tsx index ba69b35ff9..65b757bcf0 100644 --- a/src/features/liveNow/components/LiveStatusDialog.tsx +++ b/src/features/liveNow/components/LiveStatusDialog.tsx @@ -1,11 +1,11 @@ import {useCallback, useMemo} from 'react' import {View} from 'react-native' import {Image} from 'expo-image' -import {type AppBskyActorDefs, type AppBskyEmbedExternal} from '@atproto/api' import {Trans, useLingui} from '@lingui/react/macro' import {useNavigation} from '@react-navigation/native' import {useQueryClient} from '@tanstack/react-query' +import {app} from '#/lexicons' import {useOpenLink} from '#/lib/hooks/useOpenLink' import {moderateStatus} from '#/lib/moderation/subjects' import {type NavigationProp} from '#/lib/routes/types' @@ -37,8 +37,8 @@ export function LiveStatusDialog({ }: { control: Dialog.DialogControlProps profile: bsky.profile.AnyProfileView - status: AppBskyActorDefs.StatusView - embed: AppBskyEmbedExternal.View + status: app.bsky.actor.defs.StatusView + embed: app.bsky.embed.external.View }) { const navigation = useNavigation() return ( @@ -61,9 +61,9 @@ function DialogInner({ status, }: { profile: bsky.profile.AnyProfileView - embed: AppBskyEmbedExternal.View + embed: app.bsky.embed.external.View navigation: NavigationProp - status: AppBskyActorDefs.StatusView + status: app.bsky.actor.defs.StatusView }) { const {t: l} = useLingui() const control = Dialog.useDialogContext() @@ -99,9 +99,9 @@ export function LiveStatus({ padding = 'xl', onPressOpenProfile, }: { - status: AppBskyActorDefs.StatusView + status: app.bsky.actor.defs.StatusView profile: bsky.profile.AnyProfileView - embed: AppBskyEmbedExternal.View + embed: app.bsky.embed.external.View padding?: 'lg' | 'xl' onPressOpenProfile: () => void }) { diff --git a/src/features/liveNow/index.tsx b/src/features/liveNow/index.tsx index ec96777e85..9303e734f6 100644 --- a/src/features/liveNow/index.tsx +++ b/src/features/liveNow/index.tsx @@ -1,11 +1,6 @@ import {useMemo} from 'react' -import { - type $Typed, - type AppBskyActorDefs, - AppBskyEmbedExternal, -} from '@atproto/api' import {retry} from '@atproto/common-web' -import {type l} from '@atproto/lex' +import {type l, type $Typed} from '@atproto/lex' import {type AtIdentifierString, AtUri, toDatetimeString} from '@atproto/syntax' import {msg} from '@lingui/core/macro' import {useLingui} from '@lingui/react' @@ -30,7 +25,7 @@ import * as Toast from '#/components/Toast' import {useAnalytics} from '#/analytics' import {getLiveNowHost, getLiveServiceNames} from '#/features/liveNow/utils' import {app, com} from '#/lexicons' -import type * as bsky from '#/types/bsky' +import * as bsky from '#/types/bsky' export * from '#/features/liveNow/utils' @@ -48,7 +43,7 @@ const DEFAULT_STATE = { isDisabled: false, isActive: false, record: {}, -} satisfies AppBskyActorDefs.StatusView +} satisfies app.bsky.actor.defs.StatusView export type LiveNowConfig = { canGoLive: boolean @@ -135,10 +130,10 @@ export function useActorStatus(actor?: bsky.profile.AnyProfileView) { isDisabled: false, isActive: true, status: 'app.bsky.actor.status#live', - embed: shadowed.status.embed as $Typed, // temp_isStatusValid asserts this + embed: shadowed.status.embed as $Typed, // temp_isStatusValid asserts this expiresAt: shadowed.status.expiresAt!, // isStatusStillActive asserts this record: shadowed.status.record, - } satisfies AppBskyActorDefs.StatusView + } satisfies app.bsky.actor.defs.StatusView } return { uri: shadowed.status.uri, @@ -146,10 +141,10 @@ export function useActorStatus(actor?: bsky.profile.AnyProfileView) { isDisabled, isActive: false, status: 'app.bsky.actor.status#live', - embed: shadowed.status.embed as $Typed, // temp_isStatusValid asserts this + embed: shadowed.status.embed as $Typed, // temp_isStatusValid asserts this expiresAt: shadowed.status.expiresAt!, // isStatusStillActive asserts this record: shadowed.status.record, - } satisfies AppBskyActorDefs.StatusView + } satisfies app.bsky.actor.defs.StatusView } else { return DEFAULT_STATE } @@ -169,14 +164,14 @@ export function isStatusStillActive(timeStr: string | undefined) { * validate if the status is valid for the acting user e.g. as they go live. */ export function isStatusValidForViewers( - status: AppBskyActorDefs.StatusView, + status: app.bsky.actor.defs.StatusView, config: LiveNowConfig, ) { if (status.status !== 'app.bsky.actor.status#live') return false if (!status.uri) return false // should not happen, just backwards compat try { const {host: liveDid} = new AtUri(status.uri) - if (AppBskyEmbedExternal.isView(status.embed)) { + if (bsky.isType(app.bsky.embed.external.view, status.embed)) { const host = getLiveNowHost(status.embed.external.uri) const exception = config.allowedHostsExceptionsByDid.get(liveDid) const isValidException = exception ? exception.has(host) : false diff --git a/src/features/liveNow/utils.ts b/src/features/liveNow/utils.ts index a7326cd8e9..774b2c6760 100644 --- a/src/features/liveNow/utils.ts +++ b/src/features/liveNow/utils.ts @@ -1,7 +1,8 @@ -import {AppBskyActorStatus, AppBskyEmbedExternal} from '@atproto/api' import {type I18n} from '@lingui/core' import {plural} from '@lingui/core/macro' import psl from 'psl' +import * as bsky from '#/types/bsky' +import {app} from '#/lexicons' /** * Validates a raw status record and returns the typed record, or null if the @@ -9,11 +10,9 @@ import psl from 'psl' */ export function getValidLiveStatusRecord( statusRecord: unknown, -): AppBskyActorStatus.Record | null { - if (!AppBskyActorStatus.isRecord(statusRecord)) return null - const validation = AppBskyActorStatus.validateRecord(statusRecord) - if (!validation.success) return null - return validation.value +): app.bsky.actor.status.Main | null { + if (!bsky.matches(app.bsky.actor.status, statusRecord)) return null + return statusRecord } /** @@ -23,7 +22,7 @@ export function getValidLiveStatusRecord( export function getLiveLinkFromStatusRecord(statusRecord: unknown): string { const record = getValidLiveStatusRecord(statusRecord) if (!record) return '' - if (!AppBskyEmbedExternal.isMain(record.embed)) return '' + if (!bsky.isType(app.bsky.embed.external.main, record.embed)) return '' return record.embed.external.uri } diff --git a/src/locale/helpers.ts b/src/locale/helpers.ts index 63b09b3141..9db8e2fef6 100644 --- a/src/locale/helpers.ts +++ b/src/locale/helpers.ts @@ -1,7 +1,8 @@ -import {type AppBskyFeedDefs, AppBskyFeedPost} from '@atproto/api' import * as bcp47Match from 'bcp-47-match' import lande from 'lande' +import * as bsky from '#/types/bsky' +import {app} from '#/lexicons' import {hasProp} from '#/lib/type-guards' import { AppLanguage, @@ -61,8 +62,8 @@ function getLocalizedLanguage( } } -export function getPostLanguageTags(post: AppBskyFeedDefs.PostView) { - return AppBskyFeedPost.isRecord(post.record) && +export function getPostLanguageTags(post: app.bsky.feed.defs.PostView) { + return bsky.isType(app.bsky.feed.post, post.record) && hasProp(post.record, 'langs') && Array.isArray(post.record.langs) ? post.record.langs @@ -86,7 +87,7 @@ export function codeToLanguageName(lang2or3: string, appLang: string): string { } export function getPostLanguage( - post: AppBskyFeedDefs.PostView, + post: app.bsky.feed.defs.PostView, ): string | undefined { let candidates: string[] = getPostLanguageTags(post) let postText: string = '' @@ -121,7 +122,7 @@ export function getPostLanguage( } export function isPostInLanguage( - post: AppBskyFeedDefs.PostView, + post: app.bsky.feed.defs.PostView, targetLangs: string[], ): boolean { const lang = getPostLanguage(post)