flip the legacy view type imports to the generated lexicons

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Samuel Newman
2026-08-04 04:20:43 +03:00
parent 94ed6c7f0f
commit 6792677be8
39 changed files with 466 additions and 289 deletions
+8 -13
View File
@@ -44,20 +44,15 @@ import {useSafeAreaInsets} from 'react-native-safe-area-context'
import {scheduleOnUI} from 'react-native-worklets'
import * as FileSystem from 'expo-file-system'
import {type ImagePickerAsset} from 'expo-image-picker'
import {
AppBskyDraftCreateDraft,
AppBskyUnspeccedDefs,
AtUri,
ChatBskyGroupDefs,
} from '@atproto/api'
import {type Client} from '@atproto/lex'
import {type AtUriString} from '@atproto/syntax'
import {type AtUriString, AtUri} from '@atproto/syntax'
import {type RichText} from '@bsky.app/sdk/richtext'
import {plural} from '@lingui/core/macro'
import {Trans, useLingui} from '@lingui/react/macro'
import {useNavigation} from '@react-navigation/native'
import {useQueries, useQueryClient} from '@tanstack/react-query'
import * as bsky from '#/types/bsky'
import * as apilib from '#/lib/api/index'
import {EmbeddingDisabledError} from '#/lib/api/resolve'
import {useAppState} from '#/lib/appState'
@@ -149,7 +144,7 @@ import {
IS_WEB_SAFARI,
} from '#/env'
import {type Gif} from '#/features/gifPicker/types'
import {app} from '#/lexicons'
import {app, chat} from '#/lexicons'
import {BottomSheetPortalProvider} from '../../../../modules/bottom-sheet'
import {
draftToComposerPosts,
@@ -771,7 +766,7 @@ export const ComposePost = ({
const getDraftSaveError = useCallback(
(e: unknown): string => {
if (e instanceof AppBskyDraftCreateDraft.DraftLimitReachedError) {
if (e instanceof app.bsky.draft.createDraft.DraftLimitReachedError) {
return l`You've reached the maximum number of drafts`
}
return l`Failed to save draft`
@@ -1010,7 +1005,7 @@ export const ComposePost = ({
const hasUnavailableChatInvite = linkQueries.some(
q =>
q.data?.type === 'chat-invite' &&
!ChatBskyGroupDefs.isJoinLinkPreviewView(q.data.view),
!bsky.isType(chat.bsky.group.defs.joinLinkPreviewView, q.data.view),
)
const canPost =
@@ -1140,7 +1135,7 @@ export const ComposePost = ({
}
if (
!res.thread.every(p =>
AppBskyUnspeccedDefs.isThreadItemPost(p.value),
bsky.isType(app.bsky.unspecced.defs.threadItemPost, p.value),
)
) {
throw new Error(`composer: app view returned non-post items`)
@@ -1212,7 +1207,7 @@ export const ComposePost = ({
const resolved = q.data
if (
resolved?.type === 'chat-invite' &&
ChatBskyGroupDefs.isJoinLinkPreviewView(resolved.view)
bsky.isType(chat.bsky.group.defs.joinLinkPreviewView, resolved.view)
) {
ax.metric('groupchat:inviteLink:shared', {
convoId: resolved.view.convoId,
@@ -1251,7 +1246,7 @@ export const ComposePost = ({
void whenAppViewReady(client, initQuote.uri, res => {
const anchor = res.thread.at(0)
if (
AppBskyUnspeccedDefs.isThreadItemPost(anchor?.value) &&
bsky.isType(app.bsky.unspecced.defs.threadItemPost, anchor?.value) &&
anchor.value.post.quoteCount !== initQuote.quoteCount
) {
onPost?.(postUri)
+17 -22
View File
@@ -1,17 +1,12 @@
import {useCallback, useMemo, useState} from 'react'
import {LayoutAnimation, Pressable, View} from 'react-native'
import {Image} from 'expo-image'
import {
AppBskyEmbedGallery,
AppBskyEmbedImages,
AppBskyEmbedRecord,
AppBskyEmbedRecordWithMedia,
AppBskyFeedPost,
} from '@atproto/api'
import {msg} from '@lingui/core/macro'
import {useLingui} from '@lingui/react'
import {Trans} from '@lingui/react/macro'
import * as bsky from '#/types/bsky'
import {app} from '#/lexicons'
import {sanitizeDisplayName} from '#/lib/strings/display-names'
import {sanitizeHandle} from '#/lib/strings/handles'
import {type ComposerOptsPostRef} from '#/state/shell/composer'
@@ -39,15 +34,15 @@ export function ComposerReplyTo({replyTo}: {replyTo: ComposerOptsPostRef}) {
const quoteEmbed = useMemo(() => {
if (
AppBskyEmbedRecord.isView(embed) &&
AppBskyEmbedRecord.isViewRecord(embed.record) &&
AppBskyFeedPost.isRecord(embed.record.value)
bsky.isType(app.bsky.embed.record.view, embed) &&
bsky.isType(app.bsky.embed.record.viewRecord, embed.record) &&
bsky.isType(app.bsky.feed.post, embed.record.value)
) {
return embed
} else if (
AppBskyEmbedRecordWithMedia.isView(embed) &&
AppBskyEmbedRecord.isViewRecord(embed.record.record) &&
AppBskyFeedPost.isRecord(embed.record.record.value)
bsky.isType(app.bsky.embed.recordWithMedia.view, embed) &&
bsky.isType(app.bsky.embed.record.viewRecord, embed.record.record) &&
bsky.isType(app.bsky.feed.post, embed.record.record.value)
) {
return embed.record
}
@@ -61,20 +56,20 @@ export function ComposerReplyTo({replyTo}: {replyTo: ComposerOptsPostRef}) {
: null
const {images, totalNumber} = useMemo(() => {
if (AppBskyEmbedImages.isView(embed)) {
if (bsky.isType(app.bsky.embed.images.view, embed)) {
return {images: embed.images, totalNumber: embed.images.length}
} else if (AppBskyEmbedGallery.isView(embed)) {
} else if (bsky.isType(app.bsky.embed.gallery.view, embed)) {
return {
images: galleryItemsToImages(embed.items),
totalNumber: embed.items.length,
}
} else if (AppBskyEmbedRecordWithMedia.isView(embed)) {
if (AppBskyEmbedImages.isView(embed.media)) {
} else if (bsky.isType(app.bsky.embed.recordWithMedia.view, embed)) {
if (bsky.isType(app.bsky.embed.images.view, embed.media)) {
return {
images: embed.media.images,
totalNumber: embed.media.images.length,
}
} else if (AppBskyEmbedGallery.isView(embed.media)) {
} else if (bsky.isType(app.bsky.embed.gallery.view, embed.media)) {
return {
images: galleryItemsToImages(embed.media.items),
totalNumber: embed.media.items.length,
@@ -145,12 +140,12 @@ export function ComposerReplyTo({replyTo}: {replyTo: ComposerOptsPostRef}) {
}
function galleryItemsToImages(
items: AppBskyEmbedGallery.View['items'],
): AppBskyEmbedImages.ViewImage[] {
items: app.bsky.embed.gallery.View['items'],
): app.bsky.embed.images.ViewImage[] {
// The reply-to thumbnail only renders up to 4 tiles; slicing here keeps
// the existing layout switch valid for galleries up to 10 items.
return items
.filter(AppBskyEmbedGallery.isViewImage)
.filter(item => bsky.isType(app.bsky.embed.gallery.viewImage, item))
.slice(0, 4)
.map(item => ({
thumb: item.thumbnail,
@@ -164,7 +159,7 @@ function ComposerReplyToImages({
images,
totalNumber,
}: {
images: AppBskyEmbedImages.ViewImage[]
images: app.bsky.embed.images.ViewImage[]
totalNumber: number
}) {
const t = useTheme()
+23 -19
View File
@@ -1,10 +1,12 @@
/**
* Type converters for Draft API - convert between ComposerState and server Draft types.
*/
import {AppBskyDraftDefs, AtUri} from '@atproto/api'
import {RichText} from '@bsky.app/sdk/richtext'
import {nanoid} from 'nanoid/non-secure'
import {AtUri} from '@atproto/syntax'
import * as bsky from '#/types/bsky'
import {app} from '#/lexicons'
import {type LinkResolvers, resolveLink} from '#/lib/api/resolve'
import {getDeviceName} from '#/lib/deviceName'
import {getImageDim} from '#/lib/media/manip'
@@ -63,18 +65,18 @@ export async function composerStateToDraft(
clients: LinkResolvers,
state: ComposerState,
): Promise<{
draft: AppBskyDraftDefs.Draft
draft: app.bsky.draft.defs.Draft
localRefPaths: Map<string, string>
}> {
const localRefPaths = new Map<string, string>()
const posts: AppBskyDraftDefs.DraftPost[] = await Promise.all(
const posts: app.bsky.draft.defs.DraftPost[] = await Promise.all(
state.thread.posts.map(post => {
return postDraftToServerPost(clients, post, localRefPaths)
}),
)
const draft: AppBskyDraftDefs.Draft = {
const draft: app.bsky.draft.defs.Draft = {
$type: 'app.bsky.draft.defs#draft',
deviceId: getDeviceId(),
deviceName: getDeviceName().slice(0, 100), // max length of 100 in lex
@@ -99,8 +101,8 @@ async function postDraftToServerPost(
clients: LinkResolvers,
post: PostDraft,
localRefPaths: Map<string, string>,
): Promise<AppBskyDraftDefs.DraftPost> {
const draftPost: AppBskyDraftDefs.DraftPost = {
): Promise<app.bsky.draft.defs.DraftPost> {
const draftPost: app.bsky.draft.defs.DraftPost = {
$type: 'app.bsky.draft.defs#draftPost',
text: post.richtext.text,
}
@@ -176,7 +178,7 @@ async function postDraftToServerPost(
function serializeImages(
images: ComposerImage[],
localRefPaths: Map<string, string>,
): AppBskyDraftDefs.DraftEmbedGalleryItems {
): app.bsky.draft.defs.DraftEmbedGalleryItems {
return images.map(image => {
const sourcePath = image.transformed?.path || image.source.path
// Reuse existing localRefPath if present (editing draft), otherwise generate new
@@ -208,7 +210,7 @@ function serializeImages(
async function serializeVideo(
videoState: VideoState,
localRefPaths: Map<string, string>,
): Promise<AppBskyDraftDefs.DraftEmbedVideo | undefined> {
): Promise<app.bsky.draft.defs.DraftEmbedVideo | undefined> {
// Only save videos that have been compressed (have a video file)
if (!videoState.video) {
return undefined
@@ -221,7 +223,7 @@ async function serializeVideo(
localRefPaths.set(localRefPath, videoState.video.uri)
// Read caption file contents as text
const captions: AppBskyDraftDefs.DraftEmbedCaption[] = []
const captions: app.bsky.draft.defs.DraftEmbedCaption[] = []
for (const caption of videoState.captions) {
if (caption.lang) {
const content = await caption.file.text()
@@ -252,7 +254,7 @@ function serializeGif(gifMedia: {
type: 'gif'
gif: Gif
alt: string
}): AppBskyDraftDefs.DraftEmbedExternal | undefined {
}): app.bsky.draft.defs.DraftEmbedExternal | undefined {
const gif = gifMedia.gif
const gifFormat = gif.media_formats.gif || gif.media_formats.tinygif
@@ -282,7 +284,7 @@ function serializeGif(gifMedia: {
* both the `embedImages` and `embedGallery` paths in draftToComposerPosts.
*/
async function restoreDraftImages(
draftImages: AppBskyDraftDefs.DraftEmbedImage[],
draftImages: app.bsky.draft.defs.DraftEmbedImage[],
loadedMedia: Map<string, string>,
): Promise<ComposerImage[]> {
const imagePromises = draftImages.map(async img => {
@@ -338,7 +340,7 @@ export function draftViewToSummary({
view,
analytics,
}: {
view: AppBskyDraftDefs.DraftView
view: app.bsky.draft.defs.DraftView
analytics: AnalyticsContextType
}): DraftSummary {
const meta = {
@@ -378,7 +380,7 @@ export function draftViewToSummary({
// Process gallery
if (post.embedGallery) {
for (const item of post.embedGallery.items) {
if (!AppBskyDraftDefs.isDraftEmbedImage(item)) continue
if (!bsky.isType(app.bsky.draft.defs.draftEmbedImage, item)) continue
meta.mediaCount++
meta.hasMedia = true
const exists = storage.mediaExists(item.localRef.path)
@@ -494,7 +496,7 @@ function parseGifFromUrl(
* by initiating video processing for each entry.
*/
export async function draftToComposerPosts(
draft: AppBskyDraftDefs.Draft,
draft: app.bsky.draft.defs.Draft,
loadedMedia: Map<string, string>,
): Promise<{posts: PostDraft[]; restoredVideos: Map<number, RestoredVideo>}> {
const restoredVideos = new Map<number, RestoredVideo>()
@@ -523,8 +525,8 @@ export async function draftToComposerPosts(
)
}
if (post.embedGallery && post.embedGallery.items.length > 0) {
const galleryImages = post.embedGallery.items.filter(
AppBskyDraftDefs.isDraftEmbedImage,
const galleryImages = post.embedGallery.items.filter(item =>
bsky.isType(app.bsky.draft.defs.draftEmbedImage, item),
)
restoredImages.push(
...(await restoreDraftImages(galleryImages, loadedMedia)),
@@ -644,7 +646,7 @@ export async function draftToComposerPosts(
* Convert server threadgate rules back to UI settings.
*/
export function threadgateToUISettings(
threadgateAllow?: AppBskyDraftDefs.Draft['threadgateAllow'],
threadgateAllow?: app.bsky.draft.defs.Draft['threadgateAllow'],
): Array<{type: string; list?: string}> {
if (!threadgateAllow) {
return []
@@ -678,7 +680,9 @@ export function threadgateToUISettings(
* Extract all localRef paths from a draft.
* Used to identify which media files belong to a draft for cleanup.
*/
export function extractLocalRefs(draft: AppBskyDraftDefs.Draft): Set<string> {
export function extractLocalRefs(
draft: app.bsky.draft.defs.Draft,
): Set<string> {
const refs = new Set<string>()
for (const post of draft.posts) {
if (post.embedImages) {
@@ -688,7 +692,7 @@ export function extractLocalRefs(draft: AppBskyDraftDefs.Draft): Set<string> {
}
if (post.embedGallery) {
for (const item of post.embedGallery.items) {
if (!AppBskyDraftDefs.isDraftEmbedImage(item)) continue
if (!bsky.isType(app.bsky.draft.defs.draftEmbedImage, item)) continue
refs.add(item.localRef.path)
}
}
@@ -1,10 +1,10 @@
import {AppBskyDraftDefs} from '@atproto/api'
import {
useInfiniteQuery,
useMutation,
useQueryClient,
} from '@tanstack/react-query'
import * as bsky from '#/types/bsky'
import {isNetworkError} from '#/lib/strings/errors'
import {matchXrpcError} from '#/lib/xrpc-error'
import {useAppviewClient, useChatClient} from '#/state/session'
@@ -52,7 +52,9 @@ export function useDraftsQuery() {
* Load a draft's local media for editing.
* Takes the full Draft object (from DraftSummary) to avoid re-fetching.
*/
export async function loadDraftMedia(draft: AppBskyDraftDefs.Draft): Promise<{
export async function loadDraftMedia(
draft: app.bsky.draft.defs.Draft,
): Promise<{
loadedMedia: Map<string, string>
}> {
// Load local media files
@@ -81,7 +83,7 @@ export async function loadDraftMedia(draft: AppBskyDraftDefs.Draft): Promise<{
// Load gallery
if (post.embedGallery) {
for (const item of post.embedGallery.items) {
if (!AppBskyDraftDefs.isDraftEmbedImage(item)) continue
if (!bsky.isType(app.bsky.draft.defs.draftEmbedImage, item)) continue
try {
const url = await storage.loadMediaFromLocal(item.localRef.path)
loadedMedia.set(item.localRef.path, url)
@@ -242,7 +244,7 @@ export function useDeleteDraftMutation() {
draftId,
}: {
draftId: string
draft: AppBskyDraftDefs.Draft
draft: app.bsky.draft.defs.Draft
}) => {
// Delete from server first - if this fails, we keep local media for retry
await client.call(app.bsky.draft.deleteDraft, {id: draftId})
@@ -257,7 +259,8 @@ export function useDeleteDraftMutation() {
}
if (post.embedGallery) {
for (const item of post.embedGallery.items) {
if (!AppBskyDraftDefs.isDraftEmbedImage(item)) continue
if (!bsky.isType(app.bsky.draft.defs.draftEmbedImage, item))
continue
await storage.deleteMediaFromLocal(item.localRef.path)
}
}
+2 -2
View File
@@ -1,8 +1,8 @@
import {app} from '#/lexicons'
/**
* Types for draft display and local media tracking.
* Server draft types come from @atproto/api.
*/
import {type AppBskyDraftDefs} from '@atproto/api'
/**
* Reference to locally cached media file for display
@@ -55,7 +55,7 @@ export type DraftSummary = {
/** ISO timestamp of last update */
updatedAt: string
/** The full draft data from the server */
draft: AppBskyDraftDefs.Draft
draft: app.bsky.draft.defs.Draft
/** All posts in the draft for full display */
posts: DraftPostDisplay[]
/** Metadata about the draft for display purposes */
+4 -5
View File
@@ -1,5 +1,4 @@
import {type ImagePickerAsset} from 'expo-image-picker'
import {type AppBskyActorDefs, type AppBskyDraftDefs} from '@atproto/api'
import {type AtUriString, toDatetimeString} from '@atproto/syntax'
import {RichText} from '@bsky.app/sdk/richtext'
import {nanoid} from 'nanoid/non-secure'
@@ -141,8 +140,8 @@ export type ComposerAction =
type: 'restore_from_draft'
draftId: string
posts: PostDraft[]
threadgateAllow: AppBskyDraftDefs.Draft['threadgateAllow']
postgateEmbeddingRules: AppBskyDraftDefs.Draft['postgateEmbeddingRules']
threadgateAllow: app.bsky.draft.defs.Draft['threadgateAllow']
postgateEmbeddingRules: app.bsky.draft.defs.Draft['postgateEmbeddingRules']
/** Map of localRefPath -> loaded media path/URL */
loadedMedia: Map<string, string>
@@ -152,7 +151,7 @@ export type ComposerAction =
| {
type: 'clear'
initInteractionSettings:
| AppBskyActorDefs.PostInteractionSettingsPref
| app.bsky.actor.defs.PostInteractionSettingsPref
| undefined
}
| {
@@ -632,7 +631,7 @@ export function createComposerState({
initImageUris: ComposerOpts['imageUris']
initQuoteUri: string | undefined
initInteractionSettings:
| AppBskyActorDefs.PostInteractionSettingsPref
| app.bsky.actor.defs.PostInteractionSettingsPref
| undefined
}): ComposerState {
let media: ImagesMedia | GalleryMedia | undefined
@@ -1,8 +1,8 @@
import {View} from 'react-native'
import Animated, {FadeInDown, FadeOut} from 'react-native-reanimated'
import {type AppBskyActorDefs} from '@atproto/api'
import {Trans} from '@lingui/react/macro'
import {app} from '#/lexicons'
import {PressableScale} from '#/lib/custom-animations/PressableScale'
import {sanitizeDisplayName} from '#/lib/strings/display-names'
import {sanitizeHandle} from '#/lib/strings/handles'
@@ -70,7 +70,7 @@ function AutocompleteProfileCard({
totalItems,
onPress,
}: {
profile: AppBskyActorDefs.ProfileViewBasic
profile: app.bsky.actor.defs.ProfileViewBasic
itemIndex: number
totalItems: number
onPress: () => void
@@ -1,6 +1,5 @@
import {forwardRef, useEffect, useImperativeHandle, useState} from 'react'
import {Pressable, View} from 'react-native'
import {type AppBskyActorDefs} from '@atproto/api'
import {type ModerationOpts} from '@bsky.app/sdk/moderation'
import {Trans} from '@lingui/react/macro'
import {ReactRenderer} from '@tiptap/react'
@@ -11,6 +10,7 @@ import {
} from '@tiptap/suggestion'
import tippy, {type Instance as TippyInstance} from 'tippy.js'
import {app} from '#/lexicons'
import {useModerationOpts} from '#/state/preferences/moderation-opts'
import {type ActorAutocompleteFn} from '#/state/queries/actor-autocomplete'
import {atoms as a, useTheme} from '#/alf'
@@ -205,7 +205,7 @@ function AutocompleteProfileCard({
onHover,
moderationOpts,
}: {
profile: AppBskyActorDefs.ProfileViewBasic
profile: app.bsky.actor.defs.ProfileViewBasic
isSelected: boolean
onPress: () => void
onHover: () => void
@@ -14,7 +14,7 @@
* the facet-set.
*/
import {URL_REGEX} from '@atproto/api'
import {URL_REGEX} from '@bsky.app/sdk/richtext'
import {Mark} from '@tiptap/core'
import {type Node as ProsemirrorNode} from '@tiptap/pm/model'
import {Plugin, PluginKey} from '@tiptap/pm/state'
@@ -18,7 +18,7 @@ import {
CASHTAG_REGEX,
TAG_REGEX,
TRAILING_PUNCTUATION_REGEX,
} from '@atproto/api'
} from '@bsky.app/sdk/richtext'
import {Mark} from '@tiptap/core'
import {type Node as ProsemirrorNode} from '@tiptap/pm/model'
import {Plugin, PluginKey} from '@tiptap/pm/state'