migrate runtime call sites to lex clients and sdk actions
Phase 3 tasks 3-7 (parallel wave): composer/post pipeline on pdsClient/appviewClient with structural+instance blob guards and a golden CID fixture test; chat Convo/EventBus/queries on the dedicated chat client; preferences sugar to SDK actions on the PDS client; remaining state/queries producers (usePostThread unspecced flip, video scoped-token clients, notifications, starter packs, lists) to client.call; UI runtime sweep (AtUri from @atproto/syntax, moderation fns from @bsky.app/sdk/moderation, SDK RichText, ozone reason tokens, guard rewrites via #/types/bsky). Intermediate checkpoint (hooks skipped): ~114 typecheck errors remain in cross-boundary consumer files, resolved by the type-only codemod next. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import {useCallback, useMemo} from 'react'
|
||||
import {moderateProfile, type ModerationOpts} from '@atproto/api'
|
||||
import {moderateProfile, type ModerationOpts} from '@bsky.app/sdk/moderation'
|
||||
import {keepPreviousData, useQuery} from '@tanstack/react-query'
|
||||
|
||||
import {isJustAMute, moduiContainsHideableOffense} from '#/lib/moderation'
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
type AutocompleteItemType,
|
||||
type AutocompleteProfile,
|
||||
} from '#/components/Autocomplete/types'
|
||||
import {toLex} from '#/types/bsky'
|
||||
import {useEmojiSearch} from './useEmojiSearch'
|
||||
|
||||
const DEFAULT_MOD_OPTS = {
|
||||
@@ -131,7 +132,10 @@ function moderateProfileItem({
|
||||
item: AutocompleteProfile
|
||||
moderationOpts: ModerationOpts
|
||||
}) {
|
||||
const modui = moderateProfile(item.profile, moderationOpts).ui('profileList')
|
||||
// TODO(phase4): drop toLex once searchActorsTypeahead emits #/lexicons views
|
||||
const modui = moderateProfile(toLex(item.profile), moderationOpts).ui(
|
||||
'profileList',
|
||||
)
|
||||
const isExactMatch = query && item.profile.handle.toLowerCase() === query
|
||||
|
||||
if (
|
||||
|
||||
@@ -8,7 +8,7 @@ import Animated, {
|
||||
withDelay,
|
||||
withTiming,
|
||||
} from 'react-native-reanimated'
|
||||
import {moderateProfile} from '@atproto/api'
|
||||
import {moderateProfile} from '@bsky.app/sdk/moderation'
|
||||
|
||||
import {useMaybeProfileShadow} from '#/state/cache/profile-shadow'
|
||||
import {useModerationOpts} from '#/state/preferences/moderation-opts'
|
||||
@@ -17,6 +17,7 @@ import {UserAvatar} from '#/view/com/util/UserAvatar'
|
||||
import {atoms as a, useTheme} from '#/alf'
|
||||
import {Person_Filled_Corner2_Rounded as PersonIcon} from '#/components/icons/Person'
|
||||
import type * as bsky from '#/types/bsky'
|
||||
import {toLex} from '#/types/bsky'
|
||||
|
||||
type Layout = {
|
||||
size: number
|
||||
@@ -162,7 +163,10 @@ function AvatarBubble({
|
||||
type="user"
|
||||
hideLiveBadge
|
||||
noBorder
|
||||
moderation={moderateProfile(profile, moderationOpts).ui('avatar')}
|
||||
// TODO(phase4): drop toLex once profile props emit #/lexicons views
|
||||
moderation={moderateProfile(toLex(profile), moderationOpts).ui(
|
||||
'avatar',
|
||||
)}
|
||||
/>
|
||||
) : (
|
||||
<AvatarPlaceholder size={size} />
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {View} from 'react-native'
|
||||
import {moderateProfile} from '@atproto/api'
|
||||
import {moderateProfile} from '@bsky.app/sdk/moderation'
|
||||
|
||||
import {logger} from '#/logger'
|
||||
import {useModerationOpts} from '#/state/preferences/moderation-opts'
|
||||
@@ -7,6 +7,7 @@ import {useProfilesQuery} from '#/state/queries/profile'
|
||||
import {UserAvatar} from '#/view/com/util/UserAvatar'
|
||||
import {atoms as a, useTheme} from '#/alf'
|
||||
import type * as bsky from '#/types/bsky'
|
||||
import {toLex} from '#/types/bsky'
|
||||
|
||||
export function AvatarStack({
|
||||
profiles,
|
||||
@@ -34,7 +35,8 @@ export function AvatarStack({
|
||||
: profiles.map(item => ({
|
||||
key: item.did,
|
||||
profile: item,
|
||||
moderation: moderateProfile(item, moderationOpts),
|
||||
// TODO(phase4): drop toLex once useProfilesQuery emits #/lexicons views
|
||||
moderation: moderateProfile(toLex(item), moderationOpts),
|
||||
}))
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import {useCallback, useEffect, useMemo} from 'react'
|
||||
import {type GestureResponderEvent, View} from 'react-native'
|
||||
import {
|
||||
type AppBskyFeedDefs,
|
||||
type AppBskyGraphDefs,
|
||||
AtUri,
|
||||
RichText as RichTextApi,
|
||||
} from '@atproto/api'
|
||||
import {type AppBskyFeedDefs, type AppBskyGraphDefs} from '@atproto/api'
|
||||
import {AtUri} from '@atproto/syntax'
|
||||
import {RichText as RichTextApi} from '@bsky.app/sdk/richtext'
|
||||
import {Plural, Trans, useLingui} from '@lingui/react/macro'
|
||||
import {useQueryClient} from '@tanstack/react-query'
|
||||
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import {useRef} from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {
|
||||
type AppBskyActorDefs,
|
||||
moderateProfile,
|
||||
type ModerationOpts,
|
||||
} from '@atproto/api'
|
||||
import {type AppBskyActorDefs} from '@atproto/api'
|
||||
import {moderateProfile, type ModerationOpts} from '@bsky.app/sdk/moderation'
|
||||
import {Plural, Trans, useLingui} from '@lingui/react/macro'
|
||||
|
||||
import {makeProfileLink} from '#/lib/routes/links'
|
||||
@@ -14,6 +11,7 @@ import {atoms as a, useTheme} from '#/alf'
|
||||
import {Link, type LinkProps} from '#/components/Link'
|
||||
import {Text} from '#/components/Typography'
|
||||
import type * as bsky from '#/types/bsky'
|
||||
import {toLex} from '#/types/bsky'
|
||||
|
||||
const AVI_SIZE = 30
|
||||
const AVI_SIZE_SMALL = 20
|
||||
@@ -96,7 +94,8 @@ function KnownFollowersInner({
|
||||
const textStyle = [a.text_sm, a.leading_snug, t.atoms.text_contrast_medium]
|
||||
|
||||
const slice = cachedKnownFollowers.followers.slice(0, 3).map(f => {
|
||||
const moderation = moderateProfile(f, moderationOpts)
|
||||
// TODO(phase4): drop toLex once KnownFollowers emits #/lexicons views
|
||||
const moderation = moderateProfile(toLex(f), moderationOpts)
|
||||
return {
|
||||
profile: {
|
||||
...f,
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import {useEffect, useMemo} from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {
|
||||
type AppBskyGraphDefs,
|
||||
AtUri,
|
||||
moderateUserList,
|
||||
type ModerationUI,
|
||||
} from '@atproto/api'
|
||||
import {type AppBskyGraphDefs} from '@atproto/api'
|
||||
import {AtUri} from '@atproto/syntax'
|
||||
import {moderateUserList, type ModerationUI} from '@bsky.app/sdk/moderation'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
@@ -27,6 +24,7 @@ import {Link as InternalLink, type LinkProps} from '#/components/Link'
|
||||
import * as Hider from '#/components/moderation/Hider'
|
||||
import {Text} from '#/components/Typography'
|
||||
import type * as bsky from '#/types/bsky'
|
||||
import {toLex} from '#/types/bsky'
|
||||
|
||||
/*
|
||||
* This component is based on `FeedCard` and is tightly coupled with that
|
||||
@@ -57,7 +55,8 @@ export function Default(
|
||||
const {view, showPinButton} = props
|
||||
const moderationOpts = useModerationOpts()
|
||||
const moderation = moderationOpts
|
||||
? moderateUserList(view, moderationOpts)
|
||||
? // TODO(phase4): drop toLex once ListView props emit #/lexicons views
|
||||
moderateUserList(toLex(view), moderationOpts)
|
||||
: undefined
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {useMemo, useState} from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {type AppBskyActorDefs, moderateProfile} from '@atproto/api'
|
||||
import {type AppBskyActorDefs} from '@atproto/api'
|
||||
import {moderateProfile} from '@bsky.app/sdk/moderation'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
@@ -19,6 +20,7 @@ import {Newskie} from '#/components/icons/Newskie'
|
||||
import * as StarterPackCard from '#/components/StarterPack/StarterPackCard'
|
||||
import {Text} from '#/components/Typography'
|
||||
import {IS_NATIVE} from '#/env'
|
||||
import {toLex} from '#/types/bsky'
|
||||
|
||||
export function NewskieDialog({
|
||||
profile,
|
||||
@@ -88,7 +90,8 @@ function DialogInner({
|
||||
|
||||
const profileName = useMemo(() => {
|
||||
if (!moderationOpts) return profile.displayName || profile.handle
|
||||
const moderation = moderateProfile(profile, moderationOpts)
|
||||
// TODO(phase4): drop toLex once ProfileViewDetailed prop emits #/lexicons views
|
||||
const moderation = moderateProfile(toLex(profile), moderationOpts)
|
||||
return sanitizeDisplayName(
|
||||
profile.displayName || profile.handle,
|
||||
moderation.ui('displayName'),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {useMemo} from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {BSKY_LABELER_DID, type ModerationCause} from '@atproto/api'
|
||||
import {api} from '@bsky.app/sdk'
|
||||
import {type ModerationCause} from '@bsky.app/sdk/moderation'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
|
||||
import {useModerationCauseDescription} from '#/lib/moderation/useModerationCauseDescription'
|
||||
@@ -65,7 +66,7 @@ export function Label({
|
||||
const desc = useModerationCauseDescription(cause)
|
||||
const isLabeler = Boolean(desc.sourceType && desc.sourceDid)
|
||||
const isBlueskyLabel =
|
||||
desc.sourceType === 'labeler' && desc.sourceDid === BSKY_LABELER_DID
|
||||
desc.sourceType === 'labeler' && desc.sourceDid === api.moderation.did
|
||||
const avi = size === 'lg' ? 16 : 12
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import {useMemo} from 'react'
|
||||
import {moderateFeedGenerator} from '@atproto/api'
|
||||
import {moderateFeedGenerator} from '@bsky.app/sdk/moderation'
|
||||
|
||||
import {useModerationOpts} from '#/state/preferences/moderation-opts'
|
||||
import {atoms as a, useTheme} from '#/alf'
|
||||
import * as FeedCard from '#/components/FeedCard'
|
||||
import {ContentHider} from '#/components/moderation/ContentHider'
|
||||
import {toLex} from '#/types/bsky'
|
||||
import {type EmbedType} from '#/types/bsky/post'
|
||||
import {type CommonProps} from './types'
|
||||
|
||||
@@ -40,7 +41,8 @@ export function ModeratedFeedEmbed({
|
||||
const moderationOpts = useModerationOpts()
|
||||
const moderation = useMemo(() => {
|
||||
return moderationOpts
|
||||
? moderateFeedGenerator(embed.view, moderationOpts)
|
||||
? // TODO(phase4): drop toLex once feed embed view emits #/lexicons views
|
||||
moderateFeedGenerator(toLex(embed.view), moderationOpts)
|
||||
: undefined
|
||||
}, [embed.view, moderationOpts])
|
||||
return (
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import {useMemo} from 'react'
|
||||
import {moderateUserList} from '@atproto/api'
|
||||
import {moderateUserList} from '@bsky.app/sdk/moderation'
|
||||
|
||||
import {useModerationOpts} from '#/state/preferences/moderation-opts'
|
||||
import {atoms as a, useTheme} from '#/alf'
|
||||
import * as ListCard from '#/components/ListCard'
|
||||
import {ContentHider} from '#/components/moderation/ContentHider'
|
||||
import {toLex} from '#/types/bsky'
|
||||
import {type EmbedType} from '#/types/bsky/post'
|
||||
import {type CommonProps} from './types'
|
||||
|
||||
@@ -30,7 +31,8 @@ export function ModeratedListEmbed({
|
||||
const moderationOpts = useModerationOpts()
|
||||
const moderation = useMemo(() => {
|
||||
return moderationOpts
|
||||
? moderateUserList(embed.view, moderationOpts)
|
||||
? // TODO(phase4): drop toLex once list embed view emits #/lexicons views
|
||||
moderateUserList(toLex(embed.view), moderationOpts)
|
||||
: undefined
|
||||
}, [embed.view, moderationOpts])
|
||||
return (
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {Fragment, type ReactNode} from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {AtUri} from '@atproto/api'
|
||||
import {AtUri} from '@atproto/syntax'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
|
||||
import {toNiceDomain} from '#/lib/strings/url-helpers'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {type StyleProp, View, type ViewStyle} from 'react-native'
|
||||
import {Image} from 'expo-image'
|
||||
import {AtUri} from '@atproto/api'
|
||||
import {AtUri} from '@atproto/syntax'
|
||||
import {plural} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react/macro'
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import {
|
||||
type AppBskyEmbedExternal,
|
||||
AtUri,
|
||||
type ComAtprotoRepoStrongRef,
|
||||
} from '@atproto/api'
|
||||
import {AtUri} from '@atproto/syntax'
|
||||
|
||||
export function isStandardSiteDocumentUri(ref: ComAtprotoRepoStrongRef.Main) {
|
||||
return new AtUri(ref.uri).collection.startsWith('site.standard.document')
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
import {useCallback, useMemo} from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {
|
||||
type $Typed,
|
||||
type AppBskyFeedDefs,
|
||||
AppBskyFeedPost,
|
||||
AtUri,
|
||||
moderatePost,
|
||||
RichText as RichTextAPI,
|
||||
} from '@atproto/api'
|
||||
import {type AppBskyFeedDefs} from '@atproto/api'
|
||||
import {type $Typed} from '@atproto/lex'
|
||||
import {AtUri} from '@atproto/syntax'
|
||||
import {moderatePost} from '@bsky.app/sdk/moderation'
|
||||
import {RichText as RichTextAPI} from '@bsky.app/sdk/richtext'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
import {useQueryClient} from '@tanstack/react-query'
|
||||
|
||||
@@ -28,6 +25,7 @@ import {isStandardSiteEmbed} from '#/components/Post/Embed/StandardSiteEmbed/uti
|
||||
import {RichText} from '#/components/RichText'
|
||||
import {Embed as StarterPackCard} from '#/components/StarterPack/StarterPackCard'
|
||||
import {SubtleHover} from '#/components/SubtleHover'
|
||||
import {app} from '#/lexicons'
|
||||
import * as bsky from '#/types/bsky'
|
||||
import {
|
||||
type Embed as TEmbed,
|
||||
@@ -271,7 +269,9 @@ export function QuoteEmbed({
|
||||
[embed],
|
||||
)
|
||||
const moderation = useMemo(() => {
|
||||
return moderationOpts ? moderatePost(quote, moderationOpts) : undefined
|
||||
return moderationOpts
|
||||
? moderatePost(bsky.toLex(quote), moderationOpts)
|
||||
: undefined
|
||||
}, [quote, moderationOpts])
|
||||
|
||||
const t = useTheme()
|
||||
@@ -281,13 +281,7 @@ export function QuoteEmbed({
|
||||
const itemTitle = `Post by ${quote.author.handle}`
|
||||
|
||||
const richText = useMemo(() => {
|
||||
if (
|
||||
!bsky.dangerousIsType<AppBskyFeedPost.Record>(
|
||||
quote.record,
|
||||
AppBskyFeedPost.isRecord,
|
||||
)
|
||||
)
|
||||
return undefined
|
||||
if (!bsky.isType(app.bsky.feed.post, quote.record)) return undefined
|
||||
const {text, facets} = quote.record
|
||||
return text.trim()
|
||||
? new RichTextAPI({text: text, facets: facets})
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {type StyleProp, type ViewStyle} from 'react-native'
|
||||
import {type AppBskyFeedDefs, type ModerationDecision} from '@atproto/api'
|
||||
import {type AppBskyFeedDefs} from '@atproto/api'
|
||||
import {type ModerationDecision} from '@bsky.app/sdk/moderation'
|
||||
|
||||
export enum PostEmbedViewContext {
|
||||
ThreadHighlighted = 'ThreadHighlighted',
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {useCallback, useMemo} from 'react'
|
||||
import {Platform, type StyleProp, type TextStyle, View} from 'react-native'
|
||||
import {type AppBskyFeedDefs, AppBskyFeedPost} from '@atproto/api'
|
||||
import {type AppBskyFeedDefs, type AppBskyFeedPost} from '@atproto/api'
|
||||
import {Trans, useLingui} from '@lingui/react/macro'
|
||||
|
||||
import {HITSLOP_30} from '#/lib/constants'
|
||||
@@ -28,6 +28,7 @@ import * as Select from '#/components/Select'
|
||||
import {Text} from '#/components/Typography'
|
||||
import {useAnalytics} from '#/analytics'
|
||||
import {IS_WEB} from '#/env'
|
||||
import {app} from '#/lexicons'
|
||||
import * as bsky from '#/types/bsky'
|
||||
|
||||
const X_ICON_OFFSET = 16
|
||||
@@ -47,10 +48,7 @@ export function TranslatedPost({
|
||||
})
|
||||
|
||||
const record = useMemo<AppBskyFeedPost.Record | undefined>(() => {
|
||||
return bsky.dangerousIsType<AppBskyFeedPost.Record>(
|
||||
post.record,
|
||||
AppBskyFeedPost.isRecord,
|
||||
)
|
||||
return bsky.isType(app.bsky.feed.post, post.record)
|
||||
? post.record
|
||||
: undefined
|
||||
}, [post])
|
||||
|
||||
@@ -10,9 +10,9 @@ import {
|
||||
type AppBskyFeedDefs,
|
||||
type AppBskyFeedPost,
|
||||
type AppBskyFeedThreadgate,
|
||||
AtUri,
|
||||
type RichText as RichTextAPI,
|
||||
} from '@atproto/api'
|
||||
import {AtUri} from '@atproto/syntax'
|
||||
import {type RichText as RichTextAPI} from '@bsky.app/sdk/richtext'
|
||||
import {plural} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react/macro'
|
||||
import {useNavigation} from '@react-navigation/native'
|
||||
|
||||
@@ -4,8 +4,8 @@ import {
|
||||
type AppBskyFeedDefs,
|
||||
type AppBskyFeedPost,
|
||||
type AppBskyFeedThreadgate,
|
||||
type RichText as RichTextAPI,
|
||||
} from '@atproto/api'
|
||||
import {type RichText as RichTextAPI} from '@bsky.app/sdk/richtext'
|
||||
import {useLingui} from '@lingui/react/macro'
|
||||
|
||||
import {type Shadow} from '#/state/cache/post-shadow'
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import {ScrollView, View} from 'react-native'
|
||||
import {
|
||||
type ChatBskyActorDefs,
|
||||
moderateProfile,
|
||||
type ModerationOpts,
|
||||
} from '@atproto/api'
|
||||
import {type ChatBskyActorDefs} from '@atproto/api'
|
||||
import {moderateProfile, type ModerationOpts} from '@bsky.app/sdk/moderation'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
@@ -25,6 +22,7 @@ import {type ConvoWithDetails, parseConvoView} from '#/components/dms/util'
|
||||
import {ProfileBadges} from '#/components/ProfileBadges'
|
||||
import {Text} from '#/components/Typography'
|
||||
import {useAnalytics} from '#/analytics'
|
||||
import {toLex} from '#/types/bsky'
|
||||
|
||||
export function RecentChats({
|
||||
postUri,
|
||||
@@ -123,7 +121,8 @@ function RecentChatItem({
|
||||
|
||||
const primaryProfile = useProfileShadow(primaryMember)
|
||||
|
||||
const moderation = moderateProfile(primaryProfile, moderationOpts)
|
||||
// TODO(phase4): drop toLex once useProfileShadow emits #/lexicons views
|
||||
const moderation = moderateProfile(toLex(primaryProfile), moderationOpts)
|
||||
const name =
|
||||
convo.kind === 'group'
|
||||
? convo.details.name
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {memo, useMemo} from 'react'
|
||||
import * as ExpoClipboard from 'expo-clipboard'
|
||||
import {AtUri} from '@atproto/api'
|
||||
import {AtUri} from '@atproto/syntax'
|
||||
import {Trans, useLingui} from '@lingui/react/macro'
|
||||
import {useNavigation} from '@react-navigation/native'
|
||||
import {useQueryClient} from '@tanstack/react-query'
|
||||
|
||||
@@ -3,8 +3,8 @@ import {
|
||||
type AppBskyFeedDefs,
|
||||
type AppBskyFeedPost,
|
||||
type AppBskyFeedThreadgate,
|
||||
type RichText as RichTextAPI,
|
||||
} from '@atproto/api'
|
||||
import {type RichText as RichTextAPI} from '@bsky.app/sdk/richtext'
|
||||
|
||||
import {type Shadow} from '#/state/cache/post-shadow'
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {memo, useMemo} from 'react'
|
||||
import {AtUri} from '@atproto/api'
|
||||
import {AtUri} from '@atproto/syntax'
|
||||
import {Trans, useLingui} from '@lingui/react/macro'
|
||||
import {useNavigation} from '@react-navigation/native'
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@ import {
|
||||
type AppBskyFeedDefs,
|
||||
type AppBskyFeedPost,
|
||||
type AppBskyFeedThreadgate,
|
||||
AtUri,
|
||||
type RichText as RichTextAPI,
|
||||
} from '@atproto/api'
|
||||
import {AtUri} from '@atproto/syntax'
|
||||
import {type RichText as RichTextAPI} from '@bsky.app/sdk/richtext'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import {
|
||||
type AppBskyFeedDefs,
|
||||
type AppBskyFeedPost,
|
||||
type AppBskyFeedThreadgate,
|
||||
type RichText as RichTextAPI,
|
||||
} from '@atproto/api'
|
||||
import {type RichText as RichTextAPI} from '@bsky.app/sdk/richtext'
|
||||
import {plural} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react/macro'
|
||||
|
||||
|
||||
@@ -6,11 +6,8 @@ import {
|
||||
View,
|
||||
type ViewStyle,
|
||||
} from 'react-native'
|
||||
import {
|
||||
moderateProfile,
|
||||
type ModerationOpts,
|
||||
RichText as RichTextApi,
|
||||
} from '@atproto/api'
|
||||
import {moderateProfile, type ModerationOpts} from '@bsky.app/sdk/moderation'
|
||||
import {RichText as RichTextApi} from '@bsky.app/sdk/richtext'
|
||||
import {useLingui} from '@lingui/react/macro'
|
||||
|
||||
import {getModerationCauseKey} from '#/lib/moderation'
|
||||
@@ -47,7 +44,7 @@ import * as Toast from '#/components/Toast'
|
||||
import {Text} from '#/components/Typography'
|
||||
import {type Metrics} from '#/analytics'
|
||||
import {useActorStatus} from '#/features/liveNow'
|
||||
import type * as bsky from '#/types/bsky'
|
||||
import * as bsky from '#/types/bsky'
|
||||
|
||||
export function Default({
|
||||
profile,
|
||||
@@ -173,7 +170,7 @@ export function Avatar({
|
||||
liveOverride?: boolean
|
||||
size?: number
|
||||
}) {
|
||||
const moderation = moderateProfile(profile, moderationOpts)
|
||||
const moderation = moderateProfile(bsky.toLex(profile), moderationOpts)
|
||||
|
||||
const {isActive: live} = useActorStatus(profile)
|
||||
|
||||
@@ -243,7 +240,7 @@ function InlineNameAndHandle({
|
||||
moderationOpts: ModerationOpts
|
||||
}) {
|
||||
const t = useTheme()
|
||||
const moderation = moderateProfile(profile, moderationOpts)
|
||||
const moderation = moderateProfile(bsky.toLex(profile), moderationOpts)
|
||||
const name = sanitizeDisplayName(
|
||||
profile.displayName || sanitizeHandle(profile.handle),
|
||||
moderation.ui('displayName'),
|
||||
@@ -297,7 +294,7 @@ export function Name({
|
||||
style?: StyleProp<ViewStyle>
|
||||
textStyle?: StyleProp<TextStyle>
|
||||
}) {
|
||||
const moderation = moderateProfile(profile, moderationOpts)
|
||||
const moderation = moderateProfile(bsky.toLex(profile), moderationOpts)
|
||||
const name = sanitizeDisplayName(
|
||||
profile.displayName || sanitizeHandle(profile.handle),
|
||||
moderation.ui('displayName'),
|
||||
@@ -482,7 +479,7 @@ export function FollowButtonInner({
|
||||
}: FollowButtonProps) {
|
||||
const {t: l} = useLingui()
|
||||
const profile = useProfileShadow(profileUnshadowed)
|
||||
const moderation = moderateProfile(profile, moderationOpts)
|
||||
const moderation = moderateProfile(bsky.toLex(profile), moderationOpts)
|
||||
const [queueFollow, queueUnfollow] = useProfileFollowMutationQueue(
|
||||
profile,
|
||||
logContext,
|
||||
@@ -620,7 +617,7 @@ export function Labels({
|
||||
profile: bsky.profile.AnyProfileView
|
||||
moderationOpts: ModerationOpts
|
||||
}) {
|
||||
const moderation = moderateProfile(profile, moderationOpts)
|
||||
const moderation = moderateProfile(bsky.toLex(profile), moderationOpts)
|
||||
const modui = moderation.ui('profileList')
|
||||
const followedBy = profile.viewer?.followedBy
|
||||
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import {memo, useCallback, useEffect, useMemo, useReducer, useRef} from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {
|
||||
type AppBskyActorDefs,
|
||||
moderateProfile,
|
||||
type ModerationOpts,
|
||||
} from '@atproto/api'
|
||||
import {type AppBskyActorDefs} from '@atproto/api'
|
||||
import {moderateProfile, type ModerationOpts} from '@bsky.app/sdk/moderation'
|
||||
import {flip, offset, shift, size, useFloating} from '@floating-ui/react-dom'
|
||||
import {msg, plural} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
@@ -42,6 +39,7 @@ import {Text} from '#/components/Typography'
|
||||
import {IS_WEB_TOUCH_DEVICE} from '#/env'
|
||||
import {useActorStatus} from '#/features/liveNow'
|
||||
import {LiveStatus} from '#/features/liveNow/components/LiveStatusDialog'
|
||||
import {toLex} from '#/types/bsky'
|
||||
import {type ProfileHoverCardProps} from './types'
|
||||
|
||||
const floatingMiddlewares = [
|
||||
@@ -426,7 +424,8 @@ function Inner({
|
||||
const {_, i18n} = useLingui()
|
||||
const {currentAccount} = useSession()
|
||||
const moderation = useMemo(
|
||||
() => moderateProfile(profile, moderationOpts),
|
||||
// TODO(phase4): drop toLex once ProfileViewDetailed prop emits #/lexicons views
|
||||
() => moderateProfile(toLex(profile), moderationOpts),
|
||||
[profile, moderationOpts],
|
||||
)
|
||||
const [descriptionRT] = useRichText(profile.description ?? '')
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {memo, useCallback, useEffect, useMemo, useRef, useState} from 'react'
|
||||
import {TextInput, View, type ViewToken} from 'react-native'
|
||||
import {type ModerationOpts} from '@atproto/api'
|
||||
import {type ModerationOpts} from '@bsky.app/sdk/moderation'
|
||||
import {Trans, useLingui} from '@lingui/react/macro'
|
||||
|
||||
import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback'
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import {forwardRef, useCallback, useImperativeHandle, useState} from 'react'
|
||||
import {type ListRenderItemInfo, View} from 'react-native'
|
||||
import {
|
||||
type AppBskyActorDefs,
|
||||
type AppBskyGraphGetList,
|
||||
AtUri,
|
||||
type ModerationOpts,
|
||||
} from '@atproto/api'
|
||||
import {type AppBskyActorDefs, type AppBskyGraphGetList} from '@atproto/api'
|
||||
import {AtUri} from '@atproto/syntax'
|
||||
import {type ModerationOpts} from '@bsky.app/sdk/moderation'
|
||||
import {
|
||||
type InfiniteData,
|
||||
type UseInfiniteQueryResult,
|
||||
|
||||
@@ -3,7 +3,7 @@ import {View} from 'react-native'
|
||||
// @ts-expect-error missing types
|
||||
import QRCode from 'react-native-qrcode-styled'
|
||||
import type ViewShot from 'react-native-view-shot'
|
||||
import {type AppBskyGraphDefs, AppBskyGraphStarterpack} from '@atproto/api'
|
||||
import {type AppBskyGraphDefs} from '@atproto/api'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
|
||||
import {Logo} from '#/view/icons/Logo'
|
||||
@@ -12,6 +12,7 @@ import {atoms as a, useTheme} from '#/alf'
|
||||
import {LinearGradientBackground} from '#/components/LinearGradientBackground'
|
||||
import {Text} from '#/components/Typography'
|
||||
import {IS_WEB} from '#/env'
|
||||
import {app} from '#/lexicons'
|
||||
import * as bsky from '#/types/bsky'
|
||||
|
||||
const LazyViewShot = lazy(
|
||||
@@ -30,12 +31,7 @@ export function QrCode({
|
||||
}) {
|
||||
const {record} = starterPack
|
||||
|
||||
if (
|
||||
!bsky.dangerousIsType<AppBskyGraphStarterpack.Record>(
|
||||
record,
|
||||
AppBskyGraphStarterpack.isRecord,
|
||||
)
|
||||
) {
|
||||
if (!bsky.isType(app.bsky.graph.starterpack, record)) {
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import {View} from 'react-native'
|
||||
import type ViewShot from 'react-native-view-shot'
|
||||
import {requestPermissionsAsync, saveToLibraryAsync} from 'expo-media-library'
|
||||
import * as Sharing from 'expo-sharing'
|
||||
import {type AppBskyGraphDefs, AppBskyGraphStarterpack} from '@atproto/api'
|
||||
import {type AppBskyGraphDefs} from '@atproto/api'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
@@ -21,6 +21,7 @@ import {QrCode} from '#/components/StarterPack/QrCode'
|
||||
import * as Toast from '#/components/Toast'
|
||||
import {useAnalytics} from '#/analytics'
|
||||
import {IS_NATIVE, IS_WEB} from '#/env'
|
||||
import {app} from '#/lexicons'
|
||||
import * as bsky from '#/types/bsky'
|
||||
|
||||
export function QrCodeDialog({
|
||||
@@ -87,12 +88,7 @@ export function QrCodeDialog({
|
||||
} else {
|
||||
setIsSaveProcessing(true)
|
||||
|
||||
if (
|
||||
!bsky.validate(
|
||||
starterPack.record,
|
||||
AppBskyGraphStarterpack.validateRecord,
|
||||
)
|
||||
) {
|
||||
if (!bsky.matches(app.bsky.graph.starterpack, starterPack.record)) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {useMemo} from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {Image} from 'expo-image'
|
||||
import {AppBskyGraphStarterpack, AtUri} from '@atproto/api'
|
||||
import {AtUri} from '@atproto/syntax'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Plural, Trans} from '@lingui/react/macro'
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
type LinkProps as BaseLinkProps,
|
||||
} from '#/components/Link'
|
||||
import {Text} from '#/components/Typography'
|
||||
import {app} from '#/lexicons'
|
||||
import * as bsky from '#/types/bsky'
|
||||
|
||||
export function Default({
|
||||
@@ -62,12 +63,7 @@ export function Card({
|
||||
const t = useTheme()
|
||||
const {currentAccount} = useSession()
|
||||
|
||||
if (
|
||||
!bsky.dangerousIsType<AppBskyGraphStarterpack.Record>(
|
||||
record,
|
||||
AppBskyGraphStarterpack.isRecord,
|
||||
)
|
||||
) {
|
||||
if (!bsky.isType(app.bsky.graph.starterpack, record)) {
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -127,10 +123,7 @@ export function useStarterPackLink({
|
||||
|
||||
return {
|
||||
to: `/starter-pack/${handleOrDid}/${rkey}`,
|
||||
label: bsky.dangerousIsType<AppBskyGraphStarterpack.Record>(
|
||||
view.record,
|
||||
AppBskyGraphStarterpack.isRecord,
|
||||
)
|
||||
label: bsky.isType(app.bsky.graph.starterpack, view.record)
|
||||
? _(msg`Navigate to ${view.record.name}`)
|
||||
: _(msg`Navigate to starter pack`),
|
||||
precache,
|
||||
@@ -154,12 +147,7 @@ export function Link({
|
||||
return {rkey, handleOrDid: creator.handle || creator.did}
|
||||
}, [starterPack])
|
||||
|
||||
if (
|
||||
!bsky.dangerousIsType<AppBskyGraphStarterpack.Record>(
|
||||
record,
|
||||
AppBskyGraphStarterpack.isRecord,
|
||||
)
|
||||
) {
|
||||
if (!bsky.isType(app.bsky.graph.starterpack, record)) {
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import {useRef} from 'react'
|
||||
import {type ListRenderItemInfo} from 'react-native'
|
||||
import {View} from 'react-native'
|
||||
import {
|
||||
type AppBskyActorDefs,
|
||||
type AppBskyFeedDefs,
|
||||
type ModerationOpts,
|
||||
} from '@atproto/api'
|
||||
import {type AppBskyActorDefs, type AppBskyFeedDefs} from '@atproto/api'
|
||||
import {type ModerationOpts} from '@bsky.app/sdk/moderation'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import {Keyboard, View} from 'react-native'
|
||||
import {type AppBskyActorDefs, type AppBskyFeedDefs} from '@atproto/api'
|
||||
import {
|
||||
type AppBskyActorDefs,
|
||||
type AppBskyFeedDefs,
|
||||
moderateFeedGenerator,
|
||||
moderateProfile,
|
||||
type ModerationOpts,
|
||||
type ModerationUI,
|
||||
} from '@atproto/api'
|
||||
} from '@bsky.app/sdk/moderation'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
@@ -27,6 +26,7 @@ import {Checkbox} from '#/components/forms/Toggle'
|
||||
import {Text} from '#/components/Typography'
|
||||
import {useAnalytics} from '#/analytics'
|
||||
import type * as bsky from '#/types/bsky'
|
||||
import {toLex} from '#/types/bsky'
|
||||
|
||||
function WizardListCard({
|
||||
type,
|
||||
@@ -140,7 +140,10 @@ export function WizardProfileCard({
|
||||
const included = isTarget || state.profiles.some(p => p.did === profile.did)
|
||||
const disabled =
|
||||
isTarget || (!included && state.profiles.length >= STARTER_PACK_MAX_SIZE)
|
||||
const moderationUi = moderateProfile(profile, moderationOpts).ui('avatar')
|
||||
// TODO(phase4): drop toLex once profile prop emits #/lexicons views
|
||||
const moderationUi = moderateProfile(toLex(profile), moderationOpts).ui(
|
||||
'avatar',
|
||||
)
|
||||
const displayName = profile.displayName
|
||||
? sanitizeDisplayName(profile.displayName)
|
||||
: `@${sanitizeHandle(profile.handle)}`
|
||||
@@ -191,9 +194,11 @@ export function WizardFeedCard({
|
||||
const isDiscover = generator.uri === DISCOVER_FEED_URI
|
||||
const included = isDiscover || state.feeds.some(f => f.uri === generator.uri)
|
||||
const disabled = isDiscover || (!included && state.feeds.length >= 3)
|
||||
const moderationUi = moderateFeedGenerator(generator, moderationOpts).ui(
|
||||
'avatar',
|
||||
)
|
||||
// TODO(phase4): drop toLex once GeneratorView prop emits #/lexicons views
|
||||
const moderationUi = moderateFeedGenerator(
|
||||
toLex(generator),
|
||||
moderationOpts,
|
||||
).ui('avatar')
|
||||
|
||||
const onPress = () => {
|
||||
if (disabled) return
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {useEffect, useMemo} from 'react'
|
||||
import {type AppBskyUnspeccedDefs, type AtUri} from '@atproto/api'
|
||||
import {type AtUri} from '@atproto/syntax'
|
||||
import {useLingui} from '@lingui/react/macro'
|
||||
|
||||
import {PressableScale} from '#/lib/custom-animations/PressableScale'
|
||||
@@ -9,6 +9,7 @@ import {useCallOnce} from '#/lib/once'
|
||||
import {native} from '#/alf'
|
||||
import {Link as InternalLink, type LinkProps} from '#/components/Link'
|
||||
import {type Metrics, useAnalytics} from '#/analytics'
|
||||
import {type app} from '#/lexicons'
|
||||
|
||||
export function TrendingTopicLink({
|
||||
topic: raw,
|
||||
@@ -18,7 +19,7 @@ export function TrendingTopicLink({
|
||||
children,
|
||||
...rest
|
||||
}: {
|
||||
topic: AppBskyUnspeccedDefs.TrendView
|
||||
topic: app.bsky.unspecced.defs.TrendView
|
||||
metricContext: Metrics['trendingTopic:seen']['context']
|
||||
rank: number
|
||||
recId?: string
|
||||
@@ -75,7 +76,7 @@ type ParsedTrendingTopic =
|
||||
}
|
||||
|
||||
export function useTopic(
|
||||
raw: AppBskyUnspeccedDefs.TrendView,
|
||||
raw: app.bsky.unspecced.defs.TrendView,
|
||||
): ParsedTrendingTopic {
|
||||
const {t: l} = useLingui()
|
||||
return useMemo(() => {
|
||||
|
||||
@@ -6,9 +6,8 @@ import {
|
||||
type AppBskyActorDefs,
|
||||
AppBskyEmbedVideo,
|
||||
type AppBskyFeedDefs,
|
||||
AppBskyFeedPost,
|
||||
type ModerationDecision,
|
||||
} from '@atproto/api'
|
||||
import {type ModerationDecision} from '@bsky.app/sdk/moderation'
|
||||
import {useLingui} from '@lingui/react/macro'
|
||||
|
||||
import {sanitizeHandle} from '#/lib/strings/handles'
|
||||
@@ -26,6 +25,7 @@ import {Link} from '#/components/Link'
|
||||
import {MediaInsetBorder} from '#/components/MediaInsetBorder'
|
||||
import * as Hider from '#/components/moderation/Hider'
|
||||
import {Text} from '#/components/Typography'
|
||||
import {app} from '#/lexicons'
|
||||
import * as bsky from '#/types/bsky'
|
||||
|
||||
function getBlackColor(t: ReturnType<typeof useTheme>) {
|
||||
@@ -78,10 +78,7 @@ export function VideoPostCard({
|
||||
if (!AppBskyEmbedVideo.isView(embed)) return null
|
||||
|
||||
const author = post.author
|
||||
const text = bsky.dangerousIsType<AppBskyFeedPost.Record>(
|
||||
post.record,
|
||||
AppBskyFeedPost.isRecord,
|
||||
)
|
||||
const text = bsky.isType(app.bsky.feed.post, post.record)
|
||||
? post.record?.text
|
||||
: ''
|
||||
const likeCount = post?.likeCount ?? 0
|
||||
|
||||
@@ -6,12 +6,8 @@ import {
|
||||
View,
|
||||
type ViewStyle,
|
||||
} from 'react-native'
|
||||
import {
|
||||
type AppBskyFeedDefs,
|
||||
AppBskyFeedPost,
|
||||
type AppBskyGraphDefs,
|
||||
AtUri,
|
||||
} from '@atproto/api'
|
||||
import {type AppBskyFeedDefs, type AppBskyGraphDefs} from '@atproto/api'
|
||||
import {AtUri} from '@atproto/syntax'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
@@ -38,6 +34,7 @@ import {InlineLinkText} from '#/components/Link'
|
||||
import {Text} from '#/components/Typography'
|
||||
import {useAnalytics} from '#/analytics'
|
||||
import {IS_NATIVE} from '#/env'
|
||||
import {app} from '#/lexicons'
|
||||
import * as bsky from '#/types/bsky'
|
||||
|
||||
interface WhoCanReplyProps {
|
||||
@@ -58,10 +55,7 @@ export function WhoCanReply({post, isThreadAuthor, style}: WhoCanReplyProps) {
|
||||
* unexpectedly, we should check to make sure it's for sure the root URI.
|
||||
*/
|
||||
const rootUri =
|
||||
bsky.dangerousIsType<AppBskyFeedPost.Record>(
|
||||
post.record,
|
||||
AppBskyFeedPost.isRecord,
|
||||
) && post.record.reply?.root
|
||||
bsky.isType(app.bsky.feed.post, post.record) && post.record.reply?.root
|
||||
? post.record.reply.root.uri
|
||||
: post.uri
|
||||
const settings = useMemo(() => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {useCallback, useEffect, useState} from 'react'
|
||||
import {type ModerationOpts} from '@atproto/api'
|
||||
import {type ModerationOpts} from '@bsky.app/sdk/moderation'
|
||||
import {Trans, useLingui} from '@lingui/react/macro'
|
||||
|
||||
import {useRequireEmailVerification} from '#/lib/hooks/useRequireEmailVerification'
|
||||
|
||||
@@ -3,9 +3,9 @@ import {View} from 'react-native'
|
||||
import {
|
||||
type AppBskyNotificationDefs,
|
||||
type AppBskyNotificationListActivitySubscriptions,
|
||||
type ModerationOpts,
|
||||
type Un$Typed,
|
||||
} from '@atproto/api'
|
||||
import {type ModerationOpts} from '@bsky.app/sdk/moderation'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import {useState} from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {ToolsOzoneReportDefs} from '@atproto/api'
|
||||
import {api} from '@bsky.app/sdk'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
import {useMutation} from '@tanstack/react-query'
|
||||
|
||||
import {BLUESKY_MOD_SERVICE_HEADERS} from '#/lib/constants'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
import {usePdsClient, useSession} from '#/state/session'
|
||||
import {atoms as a, useBreakpoints, web} from '#/alf'
|
||||
import {AgeAssuranceBadge} from '#/components/ageAssurance/AgeAssuranceBadge'
|
||||
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
|
||||
@@ -17,6 +16,8 @@ import * as Toast from '#/components/Toast'
|
||||
import {Text} from '#/components/Typography'
|
||||
import {logger} from '#/ageAssurance'
|
||||
import {useAnalytics} from '#/analytics'
|
||||
import {com, tools} from '#/lexicons'
|
||||
import {toLex} from '#/types/bsky'
|
||||
|
||||
export function AgeAssuranceAppealDialog({
|
||||
control,
|
||||
@@ -42,7 +43,7 @@ function Inner({control}: {control: Dialog.DialogControlProps}) {
|
||||
const ax = useAnalytics()
|
||||
const {currentAccount} = useSession()
|
||||
const {gtPhone} = useBreakpoints()
|
||||
const agent = useAgent()
|
||||
const pdsClient = usePdsClient()
|
||||
|
||||
const [details, setDetails] = useState('')
|
||||
const isInvalid = details.length > 1000
|
||||
@@ -51,18 +52,18 @@ function Inner({control}: {control: Dialog.DialogControlProps}) {
|
||||
mutationFn: async () => {
|
||||
ax.metric('ageAssurance:appealDialogSubmit', {})
|
||||
|
||||
await agent.createModerationReport(
|
||||
{
|
||||
reasonType: ToolsOzoneReportDefs.REASONAPPEAL,
|
||||
await pdsClient.call(
|
||||
com.atproto.moderation.createReport,
|
||||
toLex<com.atproto.moderation.createReport.$InputBody>({
|
||||
reasonType: tools.ozone.report.defs.reasonAppeal.value,
|
||||
subject: {
|
||||
$type: 'com.atproto.admin.defs#repoRef',
|
||||
did: currentAccount?.did,
|
||||
},
|
||||
reason: `AGE_ASSURANCE_INQUIRY: ` + details,
|
||||
},
|
||||
}),
|
||||
{
|
||||
encoding: 'application/json',
|
||||
headers: BLUESKY_MOD_SERVICE_HEADERS,
|
||||
service: api.moderation.service,
|
||||
},
|
||||
)
|
||||
},
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {useState} from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {XRPCError} from '@atproto/api'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
@@ -14,6 +13,7 @@ import {
|
||||
import {useGetTimeAgo} from '#/lib/hooks/useTimeAgo'
|
||||
import {useTLDs} from '#/lib/hooks/useTLDs'
|
||||
import {isEmailMaybeInvalid} from '#/lib/strings/email'
|
||||
import {getErrorName, isXrpcError} from '#/lib/xrpc-error'
|
||||
import {type AppLanguage} from '#/locale/languages'
|
||||
import {useLanguagePrefs} from '#/state/preferences'
|
||||
import {useSession} from '#/state/session'
|
||||
@@ -139,13 +139,14 @@ function Inner() {
|
||||
msg`Something went wrong, please try again`,
|
||||
)
|
||||
|
||||
if (e instanceof XRPCError) {
|
||||
if (e.error === 'InvalidEmail') {
|
||||
if (isXrpcError(e)) {
|
||||
const errorName = getErrorName(e)
|
||||
if (errorName === 'InvalidEmail') {
|
||||
error = _(
|
||||
msg`Please enter a valid, non-temporary email address. You may need to access this email in the future.`,
|
||||
)
|
||||
ax.metric('ageAssurance:initDialogError', {code: 'InvalidEmail'})
|
||||
} else if (e.error === 'DidTooLong') {
|
||||
} else if (errorName === 'DidTooLong') {
|
||||
error = (
|
||||
<>
|
||||
<Trans>
|
||||
|
||||
@@ -2,7 +2,7 @@ import {useCallback, useMemo, useRef, useState} from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {useSafeAreaInsets} from 'react-native-safe-area-context'
|
||||
import * as SMS from 'expo-sms'
|
||||
import {type ModerationOpts} from '@atproto/api'
|
||||
import {type ModerationOpts} from '@bsky.app/sdk/moderation'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Plural, Trans} from '@lingui/react/macro'
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {memo, useEffect, useMemo, useState} from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {type AppBskyActorDefs, type AppBskyFeedPost, AtUri} from '@atproto/api'
|
||||
import {type AppBskyActorDefs, type AppBskyFeedPost} from '@atproto/api'
|
||||
import {AtUri} from '@atproto/syntax'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import {useCallback, useMemo, useState} from 'react'
|
||||
import {LayoutAnimation, Text as NestedText, View} from 'react-native'
|
||||
import {
|
||||
type AppBskyFeedDefs,
|
||||
type AppBskyFeedPostgate,
|
||||
AtUri,
|
||||
} from '@atproto/api'
|
||||
import {type AppBskyFeedDefs, type AppBskyFeedPostgate} from '@atproto/api'
|
||||
import {AtUri} from '@atproto/syntax'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Plural, Trans} from '@lingui/react/macro'
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
useState,
|
||||
} from 'react'
|
||||
import {TextInput, View} from 'react-native'
|
||||
import {moderateProfile, type ModerationOpts} from '@atproto/api'
|
||||
import {moderateProfile, type ModerationOpts} from '@bsky.app/sdk/moderation'
|
||||
import {Plural, Trans, useLingui} from '@lingui/react/macro'
|
||||
|
||||
import {createSanitizedDisplayName} from '#/lib/moderation/create-sanitized-display-name'
|
||||
@@ -33,6 +33,7 @@ import * as ProfileCard from '#/components/ProfileCard'
|
||||
import {Text} from '#/components/Typography'
|
||||
import {IS_WEB} from '#/env'
|
||||
import type * as bsky from '#/types/bsky'
|
||||
import {toLex} from '#/types/bsky'
|
||||
import {AvatarBubbles} from '../AvatarBubbles'
|
||||
import {Error} from '../Error'
|
||||
import {ProfileBadges} from '../ProfileBadges'
|
||||
@@ -410,7 +411,8 @@ function DefaultProfileCard({
|
||||
const t = useTheme()
|
||||
const {t: l} = useLingui()
|
||||
const enabled = canBeMessaged(profile)
|
||||
const moderation = moderateProfile(profile, moderationOpts)
|
||||
// TODO(phase4): drop toLex once profile prop emits #/lexicons views
|
||||
const moderation = moderateProfile(toLex(profile), moderationOpts)
|
||||
const handle = sanitizeHandle(profile.handle, '@')
|
||||
const displayName = createSanitizedDisplayName(
|
||||
profile,
|
||||
@@ -486,7 +488,8 @@ function ExistingChatCard({
|
||||
: createSanitizedDisplayName(
|
||||
convo.primaryMember,
|
||||
true,
|
||||
moderateProfile(convo.primaryMember, moderationOpts).ui(
|
||||
// TODO(phase4): drop toLex once convo primaryMember emits #/lexicons views
|
||||
moderateProfile(toLex(convo.primaryMember), moderationOpts).ui(
|
||||
'displayName',
|
||||
),
|
||||
)
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import {useCallback} from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {
|
||||
type AppBskyGraphGetStarterPacksWithMembership,
|
||||
AppBskyGraphStarterpack,
|
||||
} from '@atproto/api'
|
||||
import {type AppBskyGraphGetStarterPacksWithMembership} from '@atproto/api'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Plural, Trans} from '@lingui/react/macro'
|
||||
@@ -33,6 +30,7 @@ import * as Toast from '#/components/Toast'
|
||||
import {Text} from '#/components/Typography'
|
||||
import {useAnalytics} from '#/analytics'
|
||||
import {IS_WEB} from '#/env'
|
||||
import {app} from '#/lexicons'
|
||||
import * as bsky from '#/types/bsky'
|
||||
|
||||
type StarterPackWithMembership =
|
||||
@@ -324,12 +322,7 @@ function StarterPackItem({
|
||||
|
||||
const {record} = starterPack
|
||||
|
||||
if (
|
||||
!bsky.dangerousIsType<AppBskyGraphStarterpack.Record>(
|
||||
record,
|
||||
AppBskyGraphStarterpack.isRecord,
|
||||
)
|
||||
) {
|
||||
if (!bsky.isType(app.bsky.graph.starterpack, record)) {
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@ import {
|
||||
type AppBskyGraphDefs,
|
||||
type AppBskyGraphListitem,
|
||||
type AppBskyGraphStarterpack,
|
||||
AtUri,
|
||||
type ComAtprotoRepoApplyWrites,
|
||||
} from '@atproto/api'
|
||||
import {TID} from '@atproto/common-web'
|
||||
import {AtUri} from '@atproto/syntax'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {useCallback, useEffect, useMemo, useState} from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {type AppBskyGraphDefs, RichText as RichTextAPI} from '@atproto/api'
|
||||
import {type AppBskyGraphDefs} from '@atproto/api'
|
||||
import {RichText as RichTextAPI} from '@bsky.app/sdk/richtext'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Plural, Trans} from '@lingui/react/macro'
|
||||
@@ -15,7 +16,7 @@ import {
|
||||
useListCreateMutation,
|
||||
useListMetadataMutation,
|
||||
} from '#/state/queries/list'
|
||||
import {useAgent} from '#/state/session'
|
||||
import {usePdsClient} from '#/state/session'
|
||||
import {ErrorMessage} from '#/view/com/util/error/ErrorMessage'
|
||||
import {EditableUserAvatar} from '#/view/com/util/UserAvatar'
|
||||
import {atoms as a, useTheme, web} from '#/alf'
|
||||
@@ -27,6 +28,7 @@ import * as Prompt from '#/components/Prompt'
|
||||
import * as Toast from '#/components/Toast'
|
||||
import {Text} from '#/components/Typography'
|
||||
import {IS_WEB} from '#/env'
|
||||
import {toLex} from '#/types/bsky'
|
||||
|
||||
const DISPLAY_NAME_MAX_GRAPHEMES = 64
|
||||
const DESCRIPTION_MAX_GRAPHEMES = 300
|
||||
@@ -133,7 +135,7 @@ function DialogInner({
|
||||
|
||||
const {_} = useLingui()
|
||||
const t = useTheme()
|
||||
const agent = useAgent()
|
||||
const pdsClient = usePdsClient()
|
||||
const control = Dialog.useDialogContext()
|
||||
const {
|
||||
mutateAsync: createListMutation,
|
||||
@@ -163,7 +165,11 @@ function DialogInner({
|
||||
|
||||
// We want to be working with a blank state here, so let's get the
|
||||
// serialized version and turn it back into a RichText
|
||||
const serialized = richTextToString(new RichTextAPI({text, facets}), false)
|
||||
// TODO(phase4): drop toLex once the list view producer emits #/lexicons facets
|
||||
const serialized = richTextToString(
|
||||
new RichTextAPI({text, facets: toLex(facets)}),
|
||||
false,
|
||||
)
|
||||
|
||||
const richText = new RichTextAPI({text: serialized})
|
||||
richText.detectFacetsWithoutResolution()
|
||||
@@ -224,7 +230,7 @@ function DialogInner({
|
||||
{cleanNewlines: true},
|
||||
)
|
||||
|
||||
await richText.detectFacets(agent)
|
||||
await richText.detectFacets(pdsClient)
|
||||
richText = shortenLinks(richText)
|
||||
richText = stripInvalidMentions(richText)
|
||||
|
||||
@@ -272,7 +278,7 @@ function DialogInner({
|
||||
setImageError,
|
||||
activePurpose,
|
||||
isCurateList,
|
||||
agent,
|
||||
pdsClient,
|
||||
_,
|
||||
])
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {useCallback, useMemo} from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {type AppBskyGraphDefs, type ModerationOpts} from '@atproto/api'
|
||||
import {type AppBskyGraphDefs} from '@atproto/api'
|
||||
import {type ModerationOpts} from '@bsky.app/sdk/moderation'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {View} from 'react-native'
|
||||
import {type ChatBskyConvoDefs, type ModerationOpts} from '@atproto/api'
|
||||
import {type ChatBskyConvoDefs} from '@atproto/api'
|
||||
import {type ModerationOpts} from '@bsky.app/sdk/moderation'
|
||||
import {useLingui} from '@lingui/react/macro'
|
||||
|
||||
import {MessageContextMenu} from '#/components/dms/MessageContextMenu'
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {useCallback, useRef, useState} from 'react'
|
||||
import {Pressable, View} from 'react-native'
|
||||
import {type ChatBskyConvoDefs, type ModerationOpts} from '@atproto/api'
|
||||
import {type ChatBskyConvoDefs} from '@atproto/api'
|
||||
import {type ModerationOpts} from '@bsky.app/sdk/moderation'
|
||||
import {plural} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react/macro'
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {Fragment} from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {type ModerationCause} from '@atproto/api'
|
||||
import {type ModerationCause} from '@bsky.app/sdk/moderation'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {useCallback, useEffect} from 'react'
|
||||
import {type ScrollView, View} from 'react-native'
|
||||
import Animated, {useAnimatedRef, useSharedValue} from 'react-native-reanimated'
|
||||
import {moderateProfile} from '@atproto/api'
|
||||
import {moderateProfile} from '@bsky.app/sdk/moderation'
|
||||
import {useLingui} from '@lingui/react/macro'
|
||||
|
||||
import {HITSLOP_10} from '#/lib/constants'
|
||||
@@ -15,6 +15,7 @@ import {TimesLarge_Stroke2_Corner0_Rounded as XIcon} from '#/components/icons/Ti
|
||||
import * as ProfileCard from '#/components/ProfileCard'
|
||||
import {Text} from '#/components/Typography'
|
||||
import type * as bsky from '#/types/bsky'
|
||||
import {toLex} from '#/types/bsky'
|
||||
|
||||
type Props = {
|
||||
testID?: string
|
||||
@@ -89,7 +90,8 @@ function Tab({
|
||||
const {t: l} = useLingui()
|
||||
const moderationOpts = useModerationOpts()
|
||||
|
||||
const moderation = moderateProfile(profile, moderationOpts!)
|
||||
// TODO(phase4): drop toLex once profile prop emits #/lexicons views
|
||||
const moderation = moderateProfile(toLex(profile), moderationOpts!)
|
||||
const displayName = sanitizeDisplayName(
|
||||
profile.displayName || sanitizeHandle(profile.handle),
|
||||
moderation.ui('displayName'),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {memo, useCallback} from 'react'
|
||||
import {Keyboard, View} from 'react-native'
|
||||
import {type ModerationCause} from '@atproto/api'
|
||||
import {type ModerationCause} from '@bsky.app/sdk/moderation'
|
||||
import {Trans, useLingui} from '@lingui/react/macro'
|
||||
import {useNavigation} from '@react-navigation/native'
|
||||
import {useQueryClient} from '@tanstack/react-query'
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
useState,
|
||||
} from 'react'
|
||||
import {LayoutAnimation, type TextInput, View} from 'react-native'
|
||||
import {moderateProfile, type ModerationOpts} from '@atproto/api'
|
||||
import {moderateProfile, type ModerationOpts} from '@bsky.app/sdk/moderation'
|
||||
import {Plural, Trans, useLingui} from '@lingui/react/macro'
|
||||
|
||||
import {MAX_GROUP_NAME_GRAPHEME_LENGTH} from '#/lib/constants'
|
||||
@@ -54,6 +54,7 @@ import {Text} from '#/components/Typography'
|
||||
import {useAgeAssurance} from '#/ageAssurance'
|
||||
import {IS_NATIVE, IS_WEB} from '#/env'
|
||||
import type * as bsky from '#/types/bsky'
|
||||
import {toLex} from '#/types/bsky'
|
||||
|
||||
type NewGroupChatItem = {
|
||||
type: 'newGroupChat'
|
||||
@@ -1070,7 +1071,8 @@ function DefaultProfileCard({
|
||||
const t = useTheme()
|
||||
const {t: l} = useLingui()
|
||||
const enabled = canBeMessaged(profile)
|
||||
const moderation = moderateProfile(profile, moderationOpts)
|
||||
// TODO(phase4): drop toLex once profile prop emits #/lexicons views
|
||||
const moderation = moderateProfile(toLex(profile), moderationOpts)
|
||||
const handle = sanitizeHandle(profile.handle, '@')
|
||||
const displayName = sanitizeDisplayName(
|
||||
profile.displayName || sanitizeHandle(profile.handle),
|
||||
|
||||
@@ -2,11 +2,9 @@ import {memo, useCallback} from 'react'
|
||||
import {Platform} from 'react-native'
|
||||
import {type GestureType} from 'react-native-gesture-handler'
|
||||
import * as Clipboard from 'expo-clipboard'
|
||||
import {
|
||||
type ChatBskyConvoDefs,
|
||||
type ModerationOpts,
|
||||
RichText,
|
||||
} from '@atproto/api'
|
||||
import {type ChatBskyConvoDefs} from '@atproto/api'
|
||||
import {type ModerationOpts} from '@bsky.app/sdk/moderation'
|
||||
import {RichText} from '@bsky.app/sdk/richtext'
|
||||
import {plural} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react/macro'
|
||||
|
||||
@@ -31,6 +29,7 @@ import * as Toast from '#/components/Toast'
|
||||
import {useAnalytics} from '#/analytics'
|
||||
import {IS_NATIVE} from '#/env'
|
||||
import type * as bsky from '#/types/bsky'
|
||||
import {toLex} from '#/types/bsky'
|
||||
import {EmojiReactionPicker} from './EmojiReactionPicker'
|
||||
import {canReact, hasReachedReactionLimit} from './util'
|
||||
|
||||
@@ -88,7 +87,8 @@ export let MessageContextMenu = ({
|
||||
const str = richTextToString(
|
||||
new RichText({
|
||||
text: message.text,
|
||||
facets: message.facets,
|
||||
// TODO(phase4): drop toLex once the message producer emits #/lexicons facets
|
||||
facets: toLex(message.facets),
|
||||
}),
|
||||
true,
|
||||
)
|
||||
|
||||
@@ -27,9 +27,9 @@ import {
|
||||
type ChatBskyActorDefs,
|
||||
ChatBskyConvoDefs,
|
||||
ChatBskyEmbedJoinLink,
|
||||
moderateProfile,
|
||||
RichText as RichTextAPI,
|
||||
} from '@atproto/api'
|
||||
import {moderateProfile} from '@bsky.app/sdk/moderation'
|
||||
import {RichText as RichTextAPI} from '@bsky.app/sdk/richtext'
|
||||
import {plural} from '@lingui/core/macro'
|
||||
import {Trans, useLingui} from '@lingui/react/macro'
|
||||
import {useQueryClient} from '@tanstack/react-query'
|
||||
@@ -58,6 +58,7 @@ import * as ProfileCard from '#/components/ProfileCard'
|
||||
import * as Prompt from '#/components/Prompt'
|
||||
import {RichText} from '#/components/RichText'
|
||||
import {Text} from '#/components/Typography'
|
||||
import {toLex} from '#/types/bsky'
|
||||
import {DateDivider} from './DateDivider'
|
||||
import {MessageItemEmbed} from './MessageItemEmbed'
|
||||
import {MessageItemInviteEmbed} from './MessageItemInviteEmbed'
|
||||
@@ -335,7 +336,9 @@ let MessageItem = ({
|
||||
size={AVATAR_SIZE}
|
||||
type={profile.associated?.labeler ? 'labeler' : 'user'}
|
||||
onBeforePress={() => unstableCacheProfileView(queryClient, profile)}
|
||||
moderation={moderateProfile(profile, moderationOpts).ui('avatar')}
|
||||
moderation={moderateProfile(toLex(profile), moderationOpts).ui(
|
||||
'avatar',
|
||||
)}
|
||||
/>
|
||||
) : (
|
||||
<ProfileCard.AvatarPlaceholder size={AVATAR_SIZE} />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {useCallback, useMemo} from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {type ModerationDecision} from '@atproto/api'
|
||||
import {type ModerationDecision} from '@bsky.app/sdk/moderation'
|
||||
import {Trans, useLingui} from '@lingui/react/macro'
|
||||
|
||||
import {useProfileShadow} from '#/state/cache/profile-shadow'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {useMemo} from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {moderateProfile, type ModerationOpts} from '@atproto/api'
|
||||
import {moderateProfile, type ModerationOpts} from '@bsky.app/sdk/moderation'
|
||||
import {useLingui} from '@lingui/react/macro'
|
||||
|
||||
import {createSanitizedDisplayName} from '#/lib/moderation/create-sanitized-display-name'
|
||||
@@ -21,6 +21,7 @@ import {Link} from '#/components/Link'
|
||||
import {ProfileBadges} from '#/components/ProfileBadges'
|
||||
import {Text} from '#/components/Typography'
|
||||
import {IS_LIQUID_GLASS} from '#/env'
|
||||
import {toLex} from '#/types/bsky'
|
||||
import {type ConvoWithDetails} from './util'
|
||||
|
||||
const PFP_SIZE = 40
|
||||
@@ -85,7 +86,8 @@ function ProfileHeaderReady({
|
||||
const {t: l} = useLingui()
|
||||
const profile = useProfileShadow(convo.primaryMember)
|
||||
|
||||
const moderation = moderateProfile(profile, moderationOpts)
|
||||
// TODO(phase4): drop toLex once useProfileShadow emits #/lexicons views
|
||||
const moderation = moderateProfile(toLex(profile), moderationOpts)
|
||||
|
||||
const blockInfo = useMemo(() => {
|
||||
const modui = moderation.ui('profileView')
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {View} from 'react-native'
|
||||
import {moderateProfile, type ModerationOpts} from '@atproto/api'
|
||||
import {moderateProfile, type ModerationOpts} from '@bsky.app/sdk/moderation'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
|
||||
import {sanitizeDisplayName} from '#/lib/strings/display-names'
|
||||
@@ -10,6 +10,7 @@ import * as Toggle from '#/components/forms/Toggle'
|
||||
import * as ProfileCard from '#/components/ProfileCard'
|
||||
import {Text} from '#/components/Typography'
|
||||
import type * as bsky from '#/types/bsky'
|
||||
import {toLex} from '#/types/bsky'
|
||||
|
||||
export function GroupChatProfileCard({
|
||||
profile,
|
||||
@@ -20,7 +21,8 @@ export function GroupChatProfileCard({
|
||||
}) {
|
||||
const t = useTheme()
|
||||
const enabled = canBeAddedToGroup(profile)
|
||||
const moderation = moderateProfile(profile, moderationOpts)
|
||||
// TODO(phase4): drop toLex once profile prop emits #/lexicons views
|
||||
const moderation = moderateProfile(toLex(profile), moderationOpts)
|
||||
const handle = sanitizeHandle(profile.handle, '@')
|
||||
const displayName = sanitizeDisplayName(
|
||||
profile.displayName || sanitizeHandle(profile.handle),
|
||||
|
||||
+12
-27
@@ -1,10 +1,6 @@
|
||||
import {
|
||||
type $Typed,
|
||||
ChatBskyActorDefs,
|
||||
ChatBskyConvoDefs,
|
||||
moderateProfile,
|
||||
type ModerationOpts,
|
||||
} from '@atproto/api'
|
||||
import {type ChatBskyActorDefs, type ChatBskyConvoDefs} from '@atproto/api'
|
||||
import {type $Typed} from '@atproto/lex'
|
||||
import {moderateProfile, type ModerationOpts} from '@bsky.app/sdk/moderation'
|
||||
|
||||
import {EMOJI_REACTION_LIMIT} from '#/lib/constants'
|
||||
import {isBlockedOrBlocking} from '#/lib/moderation/blocked-and-muted'
|
||||
@@ -13,6 +9,7 @@ import {type Shadow} from '#/state/cache/profile-shadow'
|
||||
import {type ConvoState, ConvoStatus} from '#/state/messages/convo/types'
|
||||
import {platform} from '#/alf'
|
||||
import {type ReportSubject} from '#/components/moderation/ReportDialog/types'
|
||||
import {chat} from '#/lexicons'
|
||||
import * as bsky from '#/types/bsky'
|
||||
|
||||
export const MESSAGE_GAP_THRESHOLD_MS = 60 * 60 * 1000
|
||||
@@ -158,7 +155,10 @@ export function canReact({
|
||||
}
|
||||
|
||||
if (primaryMember && moderationOpts) {
|
||||
const moderation = moderateProfile(primaryMember, moderationOpts)
|
||||
const moderation = moderateProfile(
|
||||
bsky.toLex(primaryMember),
|
||||
moderationOpts,
|
||||
)
|
||||
if (convoState.convo.kind === 'direct') {
|
||||
// Either direction (blocking or blocked-by) hides reactions in 1-1s
|
||||
if (moderation.blocked) return false
|
||||
@@ -206,21 +206,11 @@ export function parseConvoView(
|
||||
convoView: ChatBskyConvoDefs.ConvoView,
|
||||
ownDid: string | undefined,
|
||||
): ConvoWithDetails | null {
|
||||
if (
|
||||
bsky.dangerousIsType<ChatBskyConvoDefs.GroupConvo>(
|
||||
convoView.kind,
|
||||
ChatBskyConvoDefs.isGroupConvo,
|
||||
)
|
||||
) {
|
||||
if (bsky.isType(chat.bsky.convo.defs.groupConvo, convoView.kind)) {
|
||||
let owner: GroupConvoMember | undefined = undefined
|
||||
|
||||
for (const member of convoView.members) {
|
||||
if (
|
||||
bsky.dangerousIsType<ChatBskyActorDefs.GroupConvoMember>(
|
||||
member.kind,
|
||||
ChatBskyActorDefs.isGroupConvoMember,
|
||||
)
|
||||
) {
|
||||
if (bsky.isType(chat.bsky.actor.defs.groupConvoMember, member.kind)) {
|
||||
if (member.kind.role === 'owner') {
|
||||
// have to do a type assertion here
|
||||
// this works: {...member, kind: member.kind}
|
||||
@@ -242,12 +232,7 @@ export function parseConvoView(
|
||||
primaryMember: owner,
|
||||
members: convoView.members as Array<GroupConvoMember>,
|
||||
}
|
||||
} else if (
|
||||
bsky.dangerousIsType<ChatBskyConvoDefs.DirectConvo>(
|
||||
convoView.kind,
|
||||
ChatBskyConvoDefs.isDirectConvo,
|
||||
)
|
||||
) {
|
||||
} else if (bsky.isType(chat.bsky.convo.defs.directConvo, convoView.kind)) {
|
||||
const otherUser = convoView.members.find(m => m.did !== ownDid)
|
||||
|
||||
if (!otherUser) {
|
||||
@@ -290,7 +275,7 @@ export function getConvoReportSubject(
|
||||
|
||||
const lastMessage = convo.view.lastMessage
|
||||
const reportableMessage =
|
||||
ChatBskyConvoDefs.isMessageView(lastMessage) &&
|
||||
bsky.isType(chat.bsky.convo.defs.messageView, lastMessage) &&
|
||||
lastMessage.sender?.did !== ownDid
|
||||
? lastMessage
|
||||
: null
|
||||
|
||||
@@ -1,16 +1,10 @@
|
||||
import {
|
||||
AppBskyEmbedGallery,
|
||||
AppBskyEmbedImages,
|
||||
AppBskyEmbedRecordWithMedia,
|
||||
type AppBskyFeedDefs,
|
||||
AppBskyFeedPost,
|
||||
type ModerationCause,
|
||||
type ModerationUI,
|
||||
} from '@atproto/api'
|
||||
import {type AppBskyFeedDefs} from '@atproto/api'
|
||||
import {type ModerationCause, type ModerationUI} from '@bsky.app/sdk/moderation'
|
||||
|
||||
import {unique} from '#/lib/moderation'
|
||||
import {type AppModerationCause} from '#/components/Pills'
|
||||
import {Features, features} from '#/analytics/features'
|
||||
import {app} from '#/lexicons'
|
||||
import * as bsky from '#/types/bsky'
|
||||
|
||||
export const POST_META_NO_CONTENT_OFFSET = {paddingTop: 10}
|
||||
@@ -28,12 +22,7 @@ export function maybeApplyGalleryOffsetStyles(
|
||||
additionalCauses?: ModerationCause[] | AppModerationCause[]
|
||||
},
|
||||
) {
|
||||
if (
|
||||
!bsky.dangerousIsType<AppBskyFeedPost.Record>(
|
||||
post.record,
|
||||
AppBskyFeedPost.isRecord,
|
||||
)
|
||||
) {
|
||||
if (!bsky.isType(app.bsky.feed.post, post.record)) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -48,24 +37,10 @@ export function maybeApplyGalleryOffsetStyles(
|
||||
* First check if we even have images
|
||||
*/
|
||||
const embed = post.record.embed
|
||||
const isImageEmbed =
|
||||
embed &&
|
||||
bsky.dangerousIsType<AppBskyEmbedImages.Main>(
|
||||
embed,
|
||||
AppBskyEmbedImages.isMain,
|
||||
)
|
||||
const isGalleryEmbed =
|
||||
embed &&
|
||||
bsky.dangerousIsType<AppBskyEmbedGallery.Main>(
|
||||
embed,
|
||||
AppBskyEmbedGallery.isMain,
|
||||
)
|
||||
const isImageEmbed = embed && bsky.isType(app.bsky.embed.images, embed)
|
||||
const isGalleryEmbed = embed && bsky.isType(app.bsky.embed.gallery, embed)
|
||||
const isRecordWithMedia =
|
||||
embed &&
|
||||
bsky.dangerousIsType<AppBskyEmbedRecordWithMedia.Main>(
|
||||
embed,
|
||||
AppBskyEmbedRecordWithMedia.isMain,
|
||||
)
|
||||
embed && bsky.isType(app.bsky.embed.recordWithMedia, embed)
|
||||
let hasImages = false
|
||||
if (isImageEmbed) {
|
||||
if (!isPostGalleryEmbedEnabled) return
|
||||
@@ -79,22 +54,12 @@ export function maybeApplyGalleryOffsetStyles(
|
||||
hasImages = true
|
||||
}
|
||||
if (isRecordWithMedia) {
|
||||
if (
|
||||
bsky.dangerousIsType<AppBskyEmbedImages.Main>(
|
||||
embed.media,
|
||||
AppBskyEmbedImages.isMain,
|
||||
)
|
||||
) {
|
||||
if (bsky.isType(app.bsky.embed.images, embed.media)) {
|
||||
if (!isPostGalleryEmbedEnabled) return
|
||||
// one image, not a gallery
|
||||
if (embed.media.images.length === 1) return
|
||||
}
|
||||
if (
|
||||
bsky.dangerousIsType<AppBskyEmbedGallery.Main>(
|
||||
embed.media,
|
||||
AppBskyEmbedGallery.isMain,
|
||||
)
|
||||
) {
|
||||
if (bsky.isType(app.bsky.embed.gallery, embed.media)) {
|
||||
// single (or empty) gallery - no offset needed
|
||||
if (embed.media.items.length <= 1) return
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import {
|
||||
ChatBskyGroupDefs,
|
||||
ChatBskyGroupRequestJoin,
|
||||
ChatBskyGroupWithdrawJoinRequest,
|
||||
moderateProfile,
|
||||
} from '@atproto/api'
|
||||
import {moderateProfile} from '@bsky.app/sdk/moderation'
|
||||
import {Plural, Trans, useLingui} from '@lingui/react/macro'
|
||||
import {useNavigation} from '@react-navigation/native'
|
||||
import {useQueryClient} from '@tanstack/react-query'
|
||||
@@ -49,6 +49,7 @@ import {Loader} from '#/components/Loader'
|
||||
import * as Toast from '#/components/Toast'
|
||||
import {Text} from '#/components/Typography'
|
||||
import {useAnalytics} from '#/analytics'
|
||||
import {toLex} from '#/types/bsky'
|
||||
import {ProfileBadges} from '../ProfileBadges'
|
||||
|
||||
export function GroupChatJoinDialog() {
|
||||
@@ -406,9 +407,11 @@ function GroupChatJoinDialogContent({code}: {code?: string}) {
|
||||
{createSanitizedDisplayName(
|
||||
joinLinkPreview.owner,
|
||||
true,
|
||||
moderateProfile(joinLinkPreview.owner, moderationOpts).ui(
|
||||
'displayName',
|
||||
),
|
||||
// TODO(phase4): drop toLex once join link preview emits #/lexicons views
|
||||
moderateProfile(
|
||||
toLex(joinLinkPreview.owner),
|
||||
moderationOpts,
|
||||
).ui('displayName'),
|
||||
)}
|
||||
</InlineLinkText>
|
||||
</Trans>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {useCallback, useEffect, useMemo} from 'react'
|
||||
import {ScrollView, View} from 'react-native'
|
||||
import {AppBskyEmbedVideo, AtUri} from '@atproto/api'
|
||||
import {AppBskyEmbedVideo} from '@atproto/api'
|
||||
import {AtUri} from '@atproto/syntax'
|
||||
import {Trans, useLingui} from '@lingui/react/macro'
|
||||
import {useQueryClient} from '@tanstack/react-query'
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import {useState} from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {type ComAtprotoLabelDefs, ToolsOzoneReportDefs} from '@atproto/api'
|
||||
import {XRPCError} from '@atproto/api'
|
||||
import {type Service} from '@atproto/lex-client'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
@@ -11,8 +10,9 @@ import {useLabelSubject} from '#/lib/moderation'
|
||||
import {useLabelInfo} from '#/lib/moderation/useLabelInfo'
|
||||
import {makeProfileLink} from '#/lib/routes/links'
|
||||
import {sanitizeHandle} from '#/lib/strings/handles'
|
||||
import {getErrorName, isXrpcError} from '#/lib/xrpc-error'
|
||||
import {logger} from '#/logger'
|
||||
import {useAgent} from '#/state/session'
|
||||
import {usePdsClient} from '#/state/session'
|
||||
import {atoms as a, useBreakpoints} from '#/alf'
|
||||
import {Admonition} from '#/components/Admonition'
|
||||
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
|
||||
@@ -22,13 +22,15 @@ import {Loader} from '#/components/Loader'
|
||||
import * as Toast from '#/components/Toast'
|
||||
import {Text} from '#/components/Typography'
|
||||
import {IS_ANDROID} from '#/env'
|
||||
import {com, tools} from '#/lexicons'
|
||||
import {toLex} from '#/types/bsky'
|
||||
|
||||
export function AppealForm({
|
||||
label,
|
||||
control,
|
||||
onPressBack,
|
||||
}: {
|
||||
label: ComAtprotoLabelDefs.Label
|
||||
label: com.atproto.label.defs.Label
|
||||
control: Dialog.DialogOuterProps['control']
|
||||
onPressBack: () => void
|
||||
}) {
|
||||
@@ -38,7 +40,7 @@ export function AppealForm({
|
||||
const [details, setDetails] = useState('')
|
||||
const {subject} = useLabelSubject({label})
|
||||
const isAccountReport = 'did' in subject
|
||||
const agent = useAgent()
|
||||
const pdsClient = usePdsClient()
|
||||
const sourceName = labeler
|
||||
? sanitizeHandle(labeler.creator.handle, '@')
|
||||
: label.src
|
||||
@@ -49,25 +51,23 @@ export function AppealForm({
|
||||
const $type = !isAccountReport
|
||||
? 'com.atproto.repo.strongRef'
|
||||
: 'com.atproto.admin.defs#repoRef'
|
||||
await agent.createModerationReport(
|
||||
{
|
||||
reasonType: ToolsOzoneReportDefs.REASONAPPEAL,
|
||||
await pdsClient.call(
|
||||
com.atproto.moderation.createReport,
|
||||
toLex<com.atproto.moderation.createReport.$InputBody>({
|
||||
reasonType: tools.ozone.report.defs.reasonAppeal.value,
|
||||
subject: {
|
||||
$type,
|
||||
...subject,
|
||||
},
|
||||
reason: details,
|
||||
},
|
||||
}),
|
||||
{
|
||||
encoding: 'application/json',
|
||||
headers: {
|
||||
'atproto-proxy': `${label.src}#atproto_labeler`,
|
||||
},
|
||||
service: `${label.src}#atproto_labeler` as Service,
|
||||
},
|
||||
)
|
||||
},
|
||||
onError: err => {
|
||||
if (err instanceof XRPCError && err.error === 'AlreadyAppealed') {
|
||||
if (isXrpcError(err) && getErrorName(err) === 'AlreadyAppealed') {
|
||||
setError(
|
||||
_(
|
||||
msg`You've already appealed this label and it's being reviewed by our moderation team.`,
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
View,
|
||||
type ViewStyle,
|
||||
} from 'react-native'
|
||||
import {type ModerationUI} from '@atproto/api'
|
||||
import {type ModerationUI} from '@bsky.app/sdk/moderation'
|
||||
import {Trans, useLingui} from '@lingui/react/macro'
|
||||
|
||||
import {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {createContext, useContext, useState} from 'react'
|
||||
import {type ModerationUI} from '@atproto/api'
|
||||
import {type ModerationUI} from '@bsky.app/sdk/moderation'
|
||||
|
||||
import {
|
||||
type ModerationCauseDescription,
|
||||
|
||||
@@ -2,7 +2,7 @@ import {View} from 'react-native'
|
||||
import {
|
||||
type InterpretedLabelValueDefinition,
|
||||
type LabelPreference,
|
||||
} from '@atproto/api'
|
||||
} from '@bsky.app/sdk/moderation'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {useState} from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {type ModerationCause} from '@atproto/api'
|
||||
import {type ModerationCause} from '@bsky.app/sdk/moderation'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import {type StyleProp, View, type ViewStyle} from 'react-native'
|
||||
import {
|
||||
type AppBskyFeedDefs,
|
||||
type ComAtprotoLabelDefs,
|
||||
type ModerationCause,
|
||||
type ModerationUI,
|
||||
} from '@atproto/api'
|
||||
import {type AppBskyFeedDefs, type ComAtprotoLabelDefs} from '@atproto/api'
|
||||
import {type ModerationCause, type ModerationUI} from '@bsky.app/sdk/moderation'
|
||||
import {plural} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react/macro'
|
||||
|
||||
@@ -20,6 +16,7 @@ import {
|
||||
useLabelsOnMeDialogControl,
|
||||
} from '#/components/moderation/LabelsOnMeDialog'
|
||||
import * as Pills from '#/components/Pills'
|
||||
import {toLex} from '#/types/bsky'
|
||||
|
||||
export function PostAlerts({
|
||||
post,
|
||||
@@ -71,7 +68,8 @@ export function PostAlerts({
|
||||
*/
|
||||
const shownCauses = [...alerts, ...informs, ...modui.blurs]
|
||||
const additionalLabels = filterUserFacingLabels(
|
||||
allLabels,
|
||||
// TODO(phase4): drop toLex once PostView labels are #/lexicons-typed
|
||||
toLex(allLabels),
|
||||
currentAccount?.did,
|
||||
).filter(label =>
|
||||
shownCauses.every(
|
||||
|
||||
@@ -7,11 +7,8 @@ import {
|
||||
View,
|
||||
type ViewStyle,
|
||||
} from 'react-native'
|
||||
import {
|
||||
type AppBskyActorDefs,
|
||||
type ModerationCause,
|
||||
type ModerationUI,
|
||||
} from '@atproto/api'
|
||||
import {type AppBskyActorDefs} from '@atproto/api'
|
||||
import {type ModerationCause, type ModerationUI} from '@bsky.app/sdk/moderation'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {type StyleProp, type ViewStyle} from 'react-native'
|
||||
import {type ModerationDecision} from '@atproto/api'
|
||||
import {type ModerationDecision} from '@bsky.app/sdk/moderation'
|
||||
|
||||
import {getModerationCauseKey, unique} from '#/lib/moderation'
|
||||
import * as Pills from '#/components/Pills'
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
import {
|
||||
type $Typed,
|
||||
type ChatBskyConvoDefs,
|
||||
type ComAtprotoModerationCreateReport,
|
||||
} from '@atproto/api'
|
||||
import {type Service} from '@atproto/lex-client'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {useMutation} from '@tanstack/react-query'
|
||||
|
||||
import {logger} from '#/logger'
|
||||
import {useAgent} from '#/state/session'
|
||||
import {usePdsClient} from '#/state/session'
|
||||
import {com} from '#/lexicons'
|
||||
import {toLex} from '#/types/bsky'
|
||||
import {NEW_TO_OLD_REASONS_MAP} from './const'
|
||||
import {type ReportState} from './state'
|
||||
import {type ParsedReportSubject} from './types'
|
||||
|
||||
type CreateReportBody = com.atproto.moderation.createReport.$InputBody
|
||||
|
||||
export function useSubmitReportMutation() {
|
||||
const {_} = useLingui()
|
||||
const agent = useAgent()
|
||||
const pdsClient = usePdsClient()
|
||||
|
||||
return useMutation({
|
||||
async mutationFn({
|
||||
@@ -52,13 +52,17 @@ export function useSubmitReportMutation() {
|
||||
reasonType = backwardsCompatibleReasonType
|
||||
}
|
||||
|
||||
let report:
|
||||
| ComAtprotoModerationCreateReport.InputSchema
|
||||
| (Omit<ComAtprotoModerationCreateReport.InputSchema, 'subject'> & {
|
||||
subject:
|
||||
| $Typed<ChatBskyConvoDefs.MessageRef>
|
||||
| $Typed<ChatBskyConvoDefs.ConvoRef>
|
||||
})
|
||||
/*
|
||||
* The generated `createReport` subject union only declares repoRef and
|
||||
* strongRef with branded did/uri strings; chat subjects (message/convo
|
||||
* refs) are accepted on the wire but not in the lexicon, and the subject
|
||||
* ids we hold here are plain strings. We build the body against a loose
|
||||
* subject shape and `toLex` it to the schema body at the call boundary
|
||||
* (matching the old widened-InputSchema shape).
|
||||
*/
|
||||
let report: Omit<CreateReportBody, 'subject'> & {
|
||||
subject: {$type: string} & Record<string, unknown>
|
||||
}
|
||||
|
||||
switch (subject.type) {
|
||||
case 'account': {
|
||||
@@ -123,12 +127,19 @@ export function useSubmitReportMutation() {
|
||||
report,
|
||||
})
|
||||
} else {
|
||||
await agent.createModerationReport(report, {
|
||||
encoding: 'application/json',
|
||||
headers: {
|
||||
'atproto-proxy': `${labeler.creator.did}#atproto_labeler`,
|
||||
/*
|
||||
* Route the report through the selected labeler's moderation service
|
||||
* via the `atproto-proxy` header, which lex-client sets from the
|
||||
* per-call `service` option (previously an explicit header on the
|
||||
* bridge agent).
|
||||
*/
|
||||
await pdsClient.call(
|
||||
com.atproto.moderation.createReport,
|
||||
toLex<CreateReportBody>(report),
|
||||
{
|
||||
service: `${labeler.creator.did}#atproto_labeler` as Service,
|
||||
},
|
||||
})
|
||||
)
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import {
|
||||
ComAtprotoModerationDefs as RootReportDefs,
|
||||
ToolsOzoneReportDefs as OzoneReportDefs,
|
||||
} from '@atproto/api'
|
||||
|
||||
import {type ParsedReportSubject} from '#/components/moderation/ReportDialog/types'
|
||||
import {com, tools} from '#/lexicons'
|
||||
|
||||
const OzoneReportDefs = tools.ozone.report.defs
|
||||
const RootReportDefs = com.atproto.moderation.defs
|
||||
|
||||
type OzoneReasonType = tools.ozone.report.defs.ReasonType
|
||||
type RootReasonType = com.atproto.moderation.defs.ReasonType
|
||||
|
||||
export const DMCA_LINK = 'https://bsky.social/about/support/copyright'
|
||||
export const SUPPORT_PAGE = 'https://bsky.social/about/support'
|
||||
@@ -17,60 +19,87 @@ export const NEW_TO_OLD_REASON_MAPPING: Record<string, string> = {}
|
||||
* Matches the mapping defined in the Ozone codebase:
|
||||
* @see https://github.com/bluesky-social/atproto/blob/4c15fb47cec26060bff2e710e95869a90c9d7fdd/packages/ozone/src/mod-service/profile.ts#L16-L64
|
||||
*/
|
||||
export const NEW_TO_OLD_REASONS_MAP: Record<
|
||||
OzoneReportDefs.ReasonType,
|
||||
RootReportDefs.ReasonType
|
||||
> = {
|
||||
[OzoneReportDefs.REASONAPPEAL]: RootReportDefs.REASONAPPEAL,
|
||||
[OzoneReportDefs.REASONOTHER]: RootReportDefs.REASONOTHER,
|
||||
export const NEW_TO_OLD_REASONS_MAP: Record<OzoneReasonType, RootReasonType> = {
|
||||
[OzoneReportDefs.reasonAppeal.value]: RootReportDefs.reasonAppeal.value,
|
||||
[OzoneReportDefs.reasonOther.value]: RootReportDefs.reasonOther.value,
|
||||
|
||||
[OzoneReportDefs.REASONVIOLENCEANIMAL]: RootReportDefs.REASONVIOLATION,
|
||||
[OzoneReportDefs.REASONVIOLENCETHREATS]: RootReportDefs.REASONVIOLATION,
|
||||
[OzoneReportDefs.REASONVIOLENCEGRAPHICCONTENT]:
|
||||
RootReportDefs.REASONVIOLATION,
|
||||
[OzoneReportDefs.REASONVIOLENCEGLORIFICATION]: RootReportDefs.REASONVIOLATION,
|
||||
[OzoneReportDefs.REASONVIOLENCEEXTREMISTCONTENT]:
|
||||
RootReportDefs.REASONVIOLATION,
|
||||
[OzoneReportDefs.REASONVIOLENCETRAFFICKING]: RootReportDefs.REASONVIOLATION,
|
||||
[OzoneReportDefs.REASONVIOLENCEOTHER]: RootReportDefs.REASONVIOLATION,
|
||||
[OzoneReportDefs.reasonViolenceAnimal.value]:
|
||||
RootReportDefs.reasonViolation.value,
|
||||
[OzoneReportDefs.reasonViolenceThreats.value]:
|
||||
RootReportDefs.reasonViolation.value,
|
||||
[OzoneReportDefs.reasonViolenceGraphicContent.value]:
|
||||
RootReportDefs.reasonViolation.value,
|
||||
[OzoneReportDefs.reasonViolenceGlorification.value]:
|
||||
RootReportDefs.reasonViolation.value,
|
||||
[OzoneReportDefs.reasonViolenceExtremistContent.value]:
|
||||
RootReportDefs.reasonViolation.value,
|
||||
[OzoneReportDefs.reasonViolenceTrafficking.value]:
|
||||
RootReportDefs.reasonViolation.value,
|
||||
[OzoneReportDefs.reasonViolenceOther.value]:
|
||||
RootReportDefs.reasonViolation.value,
|
||||
|
||||
[OzoneReportDefs.REASONSEXUALABUSECONTENT]: RootReportDefs.REASONSEXUAL,
|
||||
[OzoneReportDefs.REASONSEXUALNCII]: RootReportDefs.REASONSEXUAL,
|
||||
[OzoneReportDefs.REASONSEXUALDEEPFAKE]: RootReportDefs.REASONSEXUAL,
|
||||
[OzoneReportDefs.REASONSEXUALANIMAL]: RootReportDefs.REASONSEXUAL,
|
||||
[OzoneReportDefs.REASONSEXUALUNLABELED]: RootReportDefs.REASONSEXUAL,
|
||||
[OzoneReportDefs.REASONSEXUALOTHER]: RootReportDefs.REASONSEXUAL,
|
||||
[OzoneReportDefs.reasonSexualAbuseContent.value]:
|
||||
RootReportDefs.reasonSexual.value,
|
||||
[OzoneReportDefs.reasonSexualNCII.value]: RootReportDefs.reasonSexual.value,
|
||||
[OzoneReportDefs.reasonSexualDeepfake.value]:
|
||||
RootReportDefs.reasonSexual.value,
|
||||
[OzoneReportDefs.reasonSexualAnimal.value]: RootReportDefs.reasonSexual.value,
|
||||
[OzoneReportDefs.reasonSexualUnlabeled.value]:
|
||||
RootReportDefs.reasonSexual.value,
|
||||
[OzoneReportDefs.reasonSexualOther.value]: RootReportDefs.reasonSexual.value,
|
||||
|
||||
[OzoneReportDefs.REASONCHILDSAFETYCSAM]: RootReportDefs.REASONVIOLATION,
|
||||
[OzoneReportDefs.REASONCHILDSAFETYGROOM]: RootReportDefs.REASONVIOLATION,
|
||||
[OzoneReportDefs.REASONCHILDSAFETYPRIVACY]: RootReportDefs.REASONVIOLATION,
|
||||
[OzoneReportDefs.REASONCHILDSAFETYHARASSMENT]: RootReportDefs.REASONVIOLATION,
|
||||
[OzoneReportDefs.REASONCHILDSAFETYOTHER]: RootReportDefs.REASONVIOLATION,
|
||||
[OzoneReportDefs.reasonChildSafetyCSAM.value]:
|
||||
RootReportDefs.reasonViolation.value,
|
||||
[OzoneReportDefs.reasonChildSafetyGroom.value]:
|
||||
RootReportDefs.reasonViolation.value,
|
||||
[OzoneReportDefs.reasonChildSafetyPrivacy.value]:
|
||||
RootReportDefs.reasonViolation.value,
|
||||
[OzoneReportDefs.reasonChildSafetyHarassment.value]:
|
||||
RootReportDefs.reasonViolation.value,
|
||||
[OzoneReportDefs.reasonChildSafetyOther.value]:
|
||||
RootReportDefs.reasonViolation.value,
|
||||
|
||||
[OzoneReportDefs.REASONHARASSMENTTROLL]: RootReportDefs.REASONRUDE,
|
||||
[OzoneReportDefs.REASONHARASSMENTTARGETED]: RootReportDefs.REASONRUDE,
|
||||
[OzoneReportDefs.REASONHARASSMENTHATESPEECH]: RootReportDefs.REASONRUDE,
|
||||
[OzoneReportDefs.REASONHARASSMENTDOXXING]: RootReportDefs.REASONRUDE,
|
||||
[OzoneReportDefs.REASONHARASSMENTOTHER]: RootReportDefs.REASONRUDE,
|
||||
[OzoneReportDefs.reasonHarassmentTroll.value]:
|
||||
RootReportDefs.reasonRude.value,
|
||||
[OzoneReportDefs.reasonHarassmentTargeted.value]:
|
||||
RootReportDefs.reasonRude.value,
|
||||
[OzoneReportDefs.reasonHarassmentHateSpeech.value]:
|
||||
RootReportDefs.reasonRude.value,
|
||||
[OzoneReportDefs.reasonHarassmentDoxxing.value]:
|
||||
RootReportDefs.reasonRude.value,
|
||||
[OzoneReportDefs.reasonHarassmentOther.value]:
|
||||
RootReportDefs.reasonRude.value,
|
||||
|
||||
[OzoneReportDefs.REASONMISLEADINGBOT]: RootReportDefs.REASONMISLEADING,
|
||||
[OzoneReportDefs.REASONMISLEADINGIMPERSONATION]:
|
||||
RootReportDefs.REASONMISLEADING,
|
||||
[OzoneReportDefs.REASONMISLEADINGSPAM]: RootReportDefs.REASONSPAM,
|
||||
[OzoneReportDefs.REASONMISLEADINGSCAM]: RootReportDefs.REASONMISLEADING,
|
||||
[OzoneReportDefs.REASONMISLEADINGELECTIONS]: RootReportDefs.REASONMISLEADING,
|
||||
[OzoneReportDefs.REASONMISLEADINGOTHER]: RootReportDefs.REASONMISLEADING,
|
||||
[OzoneReportDefs.reasonMisleadingBot.value]:
|
||||
RootReportDefs.reasonMisleading.value,
|
||||
[OzoneReportDefs.reasonMisleadingImpersonation.value]:
|
||||
RootReportDefs.reasonMisleading.value,
|
||||
[OzoneReportDefs.reasonMisleadingSpam.value]: RootReportDefs.reasonSpam.value,
|
||||
[OzoneReportDefs.reasonMisleadingScam.value]:
|
||||
RootReportDefs.reasonMisleading.value,
|
||||
[OzoneReportDefs.reasonMisleadingElections.value]:
|
||||
RootReportDefs.reasonMisleading.value,
|
||||
[OzoneReportDefs.reasonMisleadingOther.value]:
|
||||
RootReportDefs.reasonMisleading.value,
|
||||
|
||||
[OzoneReportDefs.REASONRULESITESECURITY]: RootReportDefs.REASONVIOLATION,
|
||||
[OzoneReportDefs.REASONRULEPROHIBITEDSALES]: RootReportDefs.REASONVIOLATION,
|
||||
[OzoneReportDefs.REASONRULEBANEVASION]: RootReportDefs.REASONVIOLATION,
|
||||
[OzoneReportDefs.REASONRULEOTHER]: RootReportDefs.REASONVIOLATION,
|
||||
[OzoneReportDefs.reasonRuleSiteSecurity.value]:
|
||||
RootReportDefs.reasonViolation.value,
|
||||
[OzoneReportDefs.reasonRuleProhibitedSales.value]:
|
||||
RootReportDefs.reasonViolation.value,
|
||||
[OzoneReportDefs.reasonRuleBanEvasion.value]:
|
||||
RootReportDefs.reasonViolation.value,
|
||||
[OzoneReportDefs.reasonRuleOther.value]: RootReportDefs.reasonViolation.value,
|
||||
|
||||
[OzoneReportDefs.REASONSELFHARMCONTENT]: RootReportDefs.REASONVIOLATION,
|
||||
[OzoneReportDefs.REASONSELFHARMED]: RootReportDefs.REASONVIOLATION,
|
||||
[OzoneReportDefs.REASONSELFHARMSTUNTS]: RootReportDefs.REASONVIOLATION,
|
||||
[OzoneReportDefs.REASONSELFHARMSUBSTANCES]: RootReportDefs.REASONVIOLATION,
|
||||
[OzoneReportDefs.REASONSELFHARMOTHER]: RootReportDefs.REASONVIOLATION,
|
||||
[OzoneReportDefs.reasonSelfHarmContent.value]:
|
||||
RootReportDefs.reasonViolation.value,
|
||||
[OzoneReportDefs.reasonSelfHarmED.value]:
|
||||
RootReportDefs.reasonViolation.value,
|
||||
[OzoneReportDefs.reasonSelfHarmStunts.value]:
|
||||
RootReportDefs.reasonViolation.value,
|
||||
[OzoneReportDefs.reasonSelfHarmSubstances.value]:
|
||||
RootReportDefs.reasonViolation.value,
|
||||
[OzoneReportDefs.reasonSelfHarmOther.value]:
|
||||
RootReportDefs.reasonViolation.value,
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,43 +107,45 @@ export const NEW_TO_OLD_REASONS_MAP: Record<
|
||||
* @see https://github.com/bluesky-social/proposals/tree/main/0009-mod-report-granularity#backwards-compatibility
|
||||
*/
|
||||
export const OLD_TO_NEW_REASONS_MAP: Record<
|
||||
Exclude<RootReportDefs.ReasonType, OzoneReportDefs.ReasonType>,
|
||||
OzoneReportDefs.ReasonType
|
||||
Exclude<RootReasonType, OzoneReasonType>,
|
||||
OzoneReasonType
|
||||
> = {
|
||||
[RootReportDefs.REASONSPAM]: [OzoneReportDefs.REASONMISLEADINGSPAM],
|
||||
[RootReportDefs.REASONVIOLATION]: [OzoneReportDefs.REASONRULEOTHER],
|
||||
[RootReportDefs.REASONMISLEADING]: [OzoneReportDefs.REASONMISLEADINGOTHER],
|
||||
[RootReportDefs.REASONSEXUAL]: [OzoneReportDefs.REASONSEXUALUNLABELED],
|
||||
[RootReportDefs.REASONRUDE]: [OzoneReportDefs.REASONHARASSMENTOTHER],
|
||||
[RootReportDefs.REASONOTHER]: [OzoneReportDefs.REASONOTHER],
|
||||
[RootReportDefs.REASONAPPEAL]: [OzoneReportDefs.REASONAPPEAL],
|
||||
[RootReportDefs.reasonSpam.value]: OzoneReportDefs.reasonMisleadingSpam.value,
|
||||
[RootReportDefs.reasonViolation.value]: OzoneReportDefs.reasonRuleOther.value,
|
||||
[RootReportDefs.reasonMisleading.value]:
|
||||
OzoneReportDefs.reasonMisleadingOther.value,
|
||||
[RootReportDefs.reasonSexual.value]:
|
||||
OzoneReportDefs.reasonSexualUnlabeled.value,
|
||||
[RootReportDefs.reasonRude.value]:
|
||||
OzoneReportDefs.reasonHarassmentOther.value,
|
||||
[RootReportDefs.reasonOther.value]: OzoneReportDefs.reasonOther.value,
|
||||
[RootReportDefs.reasonAppeal.value]: OzoneReportDefs.reasonAppeal.value,
|
||||
}
|
||||
|
||||
/**
|
||||
* Set of report reasons that should optionally include additional details from
|
||||
* the reporter.
|
||||
*/
|
||||
export const OTHER_REPORT_REASONS: Set<OzoneReportDefs.ReasonType> = new Set([
|
||||
OzoneReportDefs.REASONVIOLENCEOTHER,
|
||||
OzoneReportDefs.REASONSEXUALOTHER,
|
||||
OzoneReportDefs.REASONCHILDSAFETYOTHER,
|
||||
OzoneReportDefs.REASONHARASSMENTOTHER,
|
||||
OzoneReportDefs.REASONMISLEADINGOTHER,
|
||||
OzoneReportDefs.REASONRULEOTHER,
|
||||
OzoneReportDefs.REASONSELFHARMOTHER,
|
||||
OzoneReportDefs.REASONOTHER,
|
||||
export const OTHER_REPORT_REASONS: Set<OzoneReasonType> = new Set([
|
||||
OzoneReportDefs.reasonViolenceOther.value,
|
||||
OzoneReportDefs.reasonSexualOther.value,
|
||||
OzoneReportDefs.reasonChildSafetyOther.value,
|
||||
OzoneReportDefs.reasonHarassmentOther.value,
|
||||
OzoneReportDefs.reasonMisleadingOther.value,
|
||||
OzoneReportDefs.reasonRuleOther.value,
|
||||
OzoneReportDefs.reasonSelfHarmOther.value,
|
||||
OzoneReportDefs.reasonOther.value,
|
||||
])
|
||||
|
||||
/**
|
||||
* Set of report reasons that should only be sent to Bluesky's moderation service.
|
||||
*/
|
||||
export const BSKY_LABELER_ONLY_REPORT_REASONS: Set<OzoneReportDefs.ReasonType> =
|
||||
new Set([
|
||||
OzoneReportDefs.REASONCHILDSAFETYCSAM,
|
||||
OzoneReportDefs.REASONCHILDSAFETYGROOM,
|
||||
OzoneReportDefs.REASONCHILDSAFETYOTHER,
|
||||
OzoneReportDefs.REASONVIOLENCEEXTREMISTCONTENT,
|
||||
])
|
||||
export const BSKY_LABELER_ONLY_REPORT_REASONS: Set<OzoneReasonType> = new Set([
|
||||
OzoneReportDefs.reasonChildSafetyCSAM.value,
|
||||
OzoneReportDefs.reasonChildSafetyGroom.value,
|
||||
OzoneReportDefs.reasonChildSafetyOther.value,
|
||||
OzoneReportDefs.reasonViolenceExtremistContent.value,
|
||||
])
|
||||
|
||||
/**
|
||||
* Set of _parsed_ subject types that should only be sent to Bluesky's
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
useState,
|
||||
} from 'react'
|
||||
import {Pressable, type ScrollView, View} from 'react-native'
|
||||
import {type AppBskyLabelerDefs, BSKY_LABELER_DID} from '@atproto/api'
|
||||
import {api} from '@bsky.app/sdk'
|
||||
import {Trans, useLingui} from '@lingui/react/macro'
|
||||
|
||||
import {wait} from '#/lib/async/wait'
|
||||
@@ -36,6 +36,7 @@ import {Loader} from '#/components/Loader'
|
||||
import {Text} from '#/components/Typography'
|
||||
import {useAnalytics} from '#/analytics'
|
||||
import {IS_NATIVE} from '#/env'
|
||||
import {type app} from '#/lexicons'
|
||||
import {useSubmitReportMutation} from './action'
|
||||
import {
|
||||
BSKY_LABELER_ONLY_REPORT_REASONS,
|
||||
@@ -184,7 +185,7 @@ function Inner(props: ReportDialogProps) {
|
||||
.filter(l => {
|
||||
if (!state.selectedOption) return false
|
||||
if (isBskyOnlyReason || isBskyOnlySubject) {
|
||||
return l.creator.did === BSKY_LABELER_DID
|
||||
return l.creator.did === api.moderation.did
|
||||
}
|
||||
const supportedReasonTypes: string[] | undefined = l.reasonTypes
|
||||
if (supportedReasonTypes === undefined) return true
|
||||
@@ -932,8 +933,8 @@ function LabelerCard({
|
||||
labeler,
|
||||
onSelect,
|
||||
}: {
|
||||
labeler: AppBskyLabelerDefs.LabelerViewDetailed
|
||||
onSelect?: (option: AppBskyLabelerDefs.LabelerViewDetailed) => void
|
||||
labeler: app.bsky.labeler.defs.LabelerViewDetailed
|
||||
onSelect?: (option: app.bsky.labeler.defs.LabelerViewDetailed) => void
|
||||
}) {
|
||||
const t = useTheme()
|
||||
const {t: l} = useLingui()
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import {
|
||||
type AppBskyLabelerDefs,
|
||||
ToolsOzoneReportDefs as OzoneReportDefs,
|
||||
} from '@atproto/api'
|
||||
|
||||
import {OTHER_REPORT_REASONS} from '#/components/moderation/ReportDialog/const'
|
||||
import {
|
||||
type ReportCategoryConfig,
|
||||
type ReportOption,
|
||||
} from '#/components/moderation/ReportDialog/utils/useReportOptions'
|
||||
import {type app, tools} from '#/lexicons'
|
||||
|
||||
const OzoneReportDefs = tools.ozone.report.defs
|
||||
|
||||
export type NciiQualification = {
|
||||
isDepicted?: boolean
|
||||
@@ -16,7 +14,7 @@ export type NciiQualification = {
|
||||
export type ReportState = {
|
||||
selectedCategory?: ReportCategoryConfig
|
||||
selectedOption?: ReportOption
|
||||
selectedLabeler?: AppBskyLabelerDefs.LabelerViewDetailed
|
||||
selectedLabeler?: app.bsky.labeler.defs.LabelerViewDetailed
|
||||
details?: string
|
||||
detailsOpen: boolean
|
||||
activeStepIndex1: number
|
||||
@@ -66,7 +64,7 @@ export type ReportAction =
|
||||
}
|
||||
| {
|
||||
type: 'selectLabeler'
|
||||
labeler: AppBskyLabelerDefs.LabelerViewDetailed
|
||||
labeler: app.bsky.labeler.defs.LabelerViewDetailed
|
||||
}
|
||||
| {
|
||||
type: 'clearLabeler'
|
||||
@@ -116,7 +114,8 @@ export function reducer(state: ReportState, action: ReportAction): ReportState {
|
||||
ncii: undefined,
|
||||
}
|
||||
case 'selectOption': {
|
||||
const isNcii = action.option.reason === OzoneReportDefs.REASONSEXUALNCII
|
||||
const isNcii =
|
||||
action.option.reason === OzoneReportDefs.reasonSexualNCII.value
|
||||
return {
|
||||
...state,
|
||||
selectedOption: action.option,
|
||||
|
||||
@@ -1,46 +1,56 @@
|
||||
import {
|
||||
AppBskyActorDefs,
|
||||
AppBskyFeedDefs,
|
||||
AppBskyFeedPost,
|
||||
AppBskyGraphDefs,
|
||||
} from '@atproto/api'
|
||||
|
||||
import {
|
||||
type ParsedReportSubject,
|
||||
type ReportSubject,
|
||||
} from '#/components/moderation/ReportDialog/types'
|
||||
import {app} from '#/lexicons'
|
||||
import * as bsky from '#/types/bsky'
|
||||
|
||||
export function parseReportSubject(
|
||||
subject: ReportSubject,
|
||||
rawSubject: ReportSubject,
|
||||
): ParsedReportSubject | undefined {
|
||||
if (!subject) return
|
||||
if (!rawSubject) return
|
||||
|
||||
if ('convoId' in subject) {
|
||||
if ('message' in subject) {
|
||||
if ('convoId' in rawSubject) {
|
||||
if ('message' in rawSubject) {
|
||||
return {
|
||||
type: 'convoMessage',
|
||||
...subject,
|
||||
...rawSubject,
|
||||
}
|
||||
}
|
||||
return {
|
||||
type: 'convo',
|
||||
convoId: subject.convoId,
|
||||
did: subject.did,
|
||||
convoId: rawSubject.convoId,
|
||||
did: rawSubject.did,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO(phase4): drop toLex once ReportSubject is a #/lexicons union. The view
|
||||
* subjects are structurally the #/lexicons shapes; we bridge here so the
|
||||
* `isType` schema guards below narrow against the lexicon `$type`s.
|
||||
*/
|
||||
const subject = bsky.toLex<
|
||||
| app.bsky.actor.defs.ProfileViewBasic
|
||||
| app.bsky.actor.defs.ProfileView
|
||||
| app.bsky.actor.defs.ProfileViewDetailed
|
||||
| app.bsky.actor.defs.StatusView
|
||||
| app.bsky.graph.defs.ListView
|
||||
| app.bsky.feed.defs.GeneratorView
|
||||
| app.bsky.graph.defs.StarterPackView
|
||||
| app.bsky.feed.defs.PostView
|
||||
>(rawSubject)
|
||||
|
||||
if (
|
||||
AppBskyActorDefs.isProfileViewBasic(subject) ||
|
||||
AppBskyActorDefs.isProfileView(subject) ||
|
||||
AppBskyActorDefs.isProfileViewDetailed(subject)
|
||||
bsky.isType(app.bsky.actor.defs.profileViewBasic, subject) ||
|
||||
bsky.isType(app.bsky.actor.defs.profileView, subject) ||
|
||||
bsky.isType(app.bsky.actor.defs.profileViewDetailed, subject)
|
||||
) {
|
||||
return {
|
||||
type: 'account',
|
||||
did: subject.did,
|
||||
nsid: 'app.bsky.actor.profile',
|
||||
}
|
||||
} else if (AppBskyActorDefs.isStatusView(subject)) {
|
||||
} else if (bsky.isType(app.bsky.actor.defs.statusView, subject)) {
|
||||
if (!subject.uri || !subject.cid) return
|
||||
return {
|
||||
type: 'status',
|
||||
@@ -48,36 +58,31 @@ export function parseReportSubject(
|
||||
cid: subject.cid,
|
||||
nsid: 'app.bsky.actor.status',
|
||||
}
|
||||
} else if (AppBskyGraphDefs.isListView(subject)) {
|
||||
} else if (bsky.isType(app.bsky.graph.defs.listView, subject)) {
|
||||
return {
|
||||
type: 'list',
|
||||
uri: subject.uri,
|
||||
cid: subject.cid,
|
||||
nsid: 'app.bsky.graph.list',
|
||||
}
|
||||
} else if (AppBskyFeedDefs.isGeneratorView(subject)) {
|
||||
} else if (bsky.isType(app.bsky.feed.defs.generatorView, subject)) {
|
||||
return {
|
||||
type: 'feed',
|
||||
uri: subject.uri,
|
||||
cid: subject.cid,
|
||||
nsid: 'app.bsky.feed.generator',
|
||||
}
|
||||
} else if (AppBskyGraphDefs.isStarterPackView(subject)) {
|
||||
} else if (bsky.isType(app.bsky.graph.defs.starterPackView, subject)) {
|
||||
return {
|
||||
type: 'starterPack',
|
||||
uri: subject.uri,
|
||||
cid: subject.cid,
|
||||
nsid: 'app.bsky.graph.starterPack',
|
||||
}
|
||||
} else if (AppBskyFeedDefs.isPostView(subject)) {
|
||||
} else if (bsky.isType(app.bsky.feed.defs.postView, subject)) {
|
||||
const record = subject.record
|
||||
const embed = bsky.post.parseEmbed(subject.embed)
|
||||
if (
|
||||
bsky.dangerousIsType<AppBskyFeedPost.Record>(
|
||||
record,
|
||||
AppBskyFeedPost.isRecord,
|
||||
)
|
||||
) {
|
||||
if (bsky.isType(app.bsky.feed.post, record)) {
|
||||
return {
|
||||
type: 'post',
|
||||
uri: subject.uri,
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import {useMemo} from 'react'
|
||||
import {ToolsOzoneReportDefs as OzoneReportDefs} from '@atproto/api'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
|
||||
import {tools} from '#/lexicons'
|
||||
|
||||
const OzoneReportDefs = tools.ozone.report.defs
|
||||
|
||||
export type ReportCategory =
|
||||
| 'childSafety'
|
||||
| 'violencePhysicalHarm'
|
||||
@@ -22,7 +25,7 @@ export type ReportCategoryConfig = {
|
||||
|
||||
export type ReportOption = {
|
||||
title: string
|
||||
reason: OzoneReportDefs.ReasonType
|
||||
reason: tools.ozone.report.defs.ReasonType
|
||||
}
|
||||
|
||||
export function useReportOptions() {
|
||||
@@ -37,27 +40,27 @@ export function useReportOptions() {
|
||||
options: [
|
||||
{
|
||||
title: _(msg`Spam`),
|
||||
reason: OzoneReportDefs.REASONMISLEADINGSPAM,
|
||||
reason: OzoneReportDefs.reasonMisleadingSpam.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Scam`),
|
||||
reason: OzoneReportDefs.REASONMISLEADINGSCAM,
|
||||
reason: OzoneReportDefs.reasonMisleadingScam.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Fake account or bot`),
|
||||
reason: OzoneReportDefs.REASONMISLEADINGBOT,
|
||||
reason: OzoneReportDefs.reasonMisleadingBot.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Impersonation`),
|
||||
reason: OzoneReportDefs.REASONMISLEADINGIMPERSONATION,
|
||||
reason: OzoneReportDefs.reasonMisleadingImpersonation.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`False information about elections`),
|
||||
reason: OzoneReportDefs.REASONMISLEADINGELECTIONS,
|
||||
reason: OzoneReportDefs.reasonMisleadingElections.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Other misleading content`),
|
||||
reason: OzoneReportDefs.REASONMISLEADINGOTHER,
|
||||
reason: OzoneReportDefs.reasonMisleadingOther.value,
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -70,27 +73,27 @@ export function useReportOptions() {
|
||||
options: [
|
||||
{
|
||||
title: _(msg`Unlabeled adult content`),
|
||||
reason: OzoneReportDefs.REASONSEXUALUNLABELED,
|
||||
reason: OzoneReportDefs.reasonSexualUnlabeled.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Adult sexual abuse content`),
|
||||
reason: OzoneReportDefs.REASONSEXUALABUSECONTENT,
|
||||
reason: OzoneReportDefs.reasonSexualAbuseContent.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Non-consensual intimate imagery`),
|
||||
reason: OzoneReportDefs.REASONSEXUALNCII,
|
||||
reason: OzoneReportDefs.reasonSexualNCII.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Deepfake adult content`),
|
||||
reason: OzoneReportDefs.REASONSEXUALDEEPFAKE,
|
||||
reason: OzoneReportDefs.reasonSexualDeepfake.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Animal sexual abuse`),
|
||||
reason: OzoneReportDefs.REASONSEXUALANIMAL,
|
||||
reason: OzoneReportDefs.reasonSexualAnimal.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Other sexual violence content`),
|
||||
reason: OzoneReportDefs.REASONSEXUALOTHER,
|
||||
reason: OzoneReportDefs.reasonSexualOther.value,
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -101,23 +104,23 @@ export function useReportOptions() {
|
||||
options: [
|
||||
{
|
||||
title: _(msg`Trolling`),
|
||||
reason: OzoneReportDefs.REASONHARASSMENTTROLL,
|
||||
reason: OzoneReportDefs.reasonHarassmentTroll.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Targeted harassment`),
|
||||
reason: OzoneReportDefs.REASONHARASSMENTTARGETED,
|
||||
reason: OzoneReportDefs.reasonHarassmentTargeted.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Hate speech`),
|
||||
reason: OzoneReportDefs.REASONHARASSMENTHATESPEECH,
|
||||
reason: OzoneReportDefs.reasonHarassmentHateSpeech.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Doxxing`),
|
||||
reason: OzoneReportDefs.REASONHARASSMENTDOXXING,
|
||||
reason: OzoneReportDefs.reasonHarassmentDoxxing.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Other harassing or hateful content`),
|
||||
reason: OzoneReportDefs.REASONHARASSMENTOTHER,
|
||||
reason: OzoneReportDefs.reasonHarassmentOther.value,
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -128,31 +131,31 @@ export function useReportOptions() {
|
||||
options: [
|
||||
{
|
||||
title: _(msg`Animal welfare`),
|
||||
reason: OzoneReportDefs.REASONVIOLENCEANIMAL,
|
||||
reason: OzoneReportDefs.reasonViolenceAnimal.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Threats or incitement`),
|
||||
reason: OzoneReportDefs.REASONVIOLENCETHREATS,
|
||||
reason: OzoneReportDefs.reasonViolenceThreats.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Graphic violent content`),
|
||||
reason: OzoneReportDefs.REASONVIOLENCEGRAPHICCONTENT,
|
||||
reason: OzoneReportDefs.reasonViolenceGraphicContent.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Glorification of violence`),
|
||||
reason: OzoneReportDefs.REASONVIOLENCEGLORIFICATION,
|
||||
reason: OzoneReportDefs.reasonViolenceGlorification.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Extremist content`),
|
||||
reason: OzoneReportDefs.REASONVIOLENCEEXTREMISTCONTENT,
|
||||
reason: OzoneReportDefs.reasonViolenceExtremistContent.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Human trafficking`),
|
||||
reason: OzoneReportDefs.REASONVIOLENCETRAFFICKING,
|
||||
reason: OzoneReportDefs.reasonViolenceTrafficking.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Other violent content`),
|
||||
reason: OzoneReportDefs.REASONVIOLENCEOTHER,
|
||||
reason: OzoneReportDefs.reasonViolenceOther.value,
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -163,23 +166,23 @@ export function useReportOptions() {
|
||||
options: [
|
||||
{
|
||||
title: _(msg`Child Sexual Abuse Material (CSAM)`),
|
||||
reason: OzoneReportDefs.REASONCHILDSAFETYCSAM,
|
||||
reason: OzoneReportDefs.reasonChildSafetyCSAM.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Grooming or predatory behavior`),
|
||||
reason: OzoneReportDefs.REASONCHILDSAFETYGROOM,
|
||||
reason: OzoneReportDefs.reasonChildSafetyGroom.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Privacy violation of a minor`),
|
||||
reason: OzoneReportDefs.REASONCHILDSAFETYPRIVACY,
|
||||
reason: OzoneReportDefs.reasonChildSafetyPrivacy.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Minor harassment or bullying`),
|
||||
reason: OzoneReportDefs.REASONCHILDSAFETYHARASSMENT,
|
||||
reason: OzoneReportDefs.reasonChildSafetyHarassment.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Other child safety issue`),
|
||||
reason: OzoneReportDefs.REASONCHILDSAFETYOTHER,
|
||||
reason: OzoneReportDefs.reasonChildSafetyOther.value,
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -190,23 +193,23 @@ export function useReportOptions() {
|
||||
options: [
|
||||
{
|
||||
title: _(msg`Content promoting or depicting self-harm`),
|
||||
reason: OzoneReportDefs.REASONSELFHARMCONTENT,
|
||||
reason: OzoneReportDefs.reasonSelfHarmContent.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Eating disorders`),
|
||||
reason: OzoneReportDefs.REASONSELFHARMED,
|
||||
reason: OzoneReportDefs.reasonSelfHarmED.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Dangerous challenges or activities`),
|
||||
reason: OzoneReportDefs.REASONSELFHARMSTUNTS,
|
||||
reason: OzoneReportDefs.reasonSelfHarmStunts.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Dangerous substances or drug abuse`),
|
||||
reason: OzoneReportDefs.REASONSELFHARMSUBSTANCES,
|
||||
reason: OzoneReportDefs.reasonSelfHarmSubstances.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Other dangerous content`),
|
||||
reason: OzoneReportDefs.REASONSELFHARMOTHER,
|
||||
reason: OzoneReportDefs.reasonSelfHarmOther.value,
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -217,19 +220,19 @@ export function useReportOptions() {
|
||||
options: [
|
||||
{
|
||||
title: _(msg`Hacking or system attacks`),
|
||||
reason: OzoneReportDefs.REASONRULESITESECURITY,
|
||||
reason: OzoneReportDefs.reasonRuleSiteSecurity.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Promoting or selling prohibited items or services`),
|
||||
reason: OzoneReportDefs.REASONRULEPROHIBITEDSALES,
|
||||
reason: OzoneReportDefs.reasonRuleProhibitedSales.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Banned user returning`),
|
||||
reason: OzoneReportDefs.REASONRULEBANEVASION,
|
||||
reason: OzoneReportDefs.reasonRuleBanEvasion.value,
|
||||
},
|
||||
{
|
||||
title: _(msg`Other network rule-breaking`),
|
||||
reason: OzoneReportDefs.REASONRULEOTHER,
|
||||
reason: OzoneReportDefs.reasonRuleOther.value,
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -240,7 +243,7 @@ export function useReportOptions() {
|
||||
options: [
|
||||
{
|
||||
title: _(msg`Other`),
|
||||
reason: OzoneReportDefs.REASONOTHER,
|
||||
reason: OzoneReportDefs.reasonOther.value,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
View,
|
||||
type ViewStyle,
|
||||
} from 'react-native'
|
||||
import {type ModerationUI} from '@atproto/api'
|
||||
import {type ModerationUI} from '@bsky.app/sdk/moderation'
|
||||
import {Trans, useLingui} from '@lingui/react/macro'
|
||||
import {useNavigation} from '@react-navigation/native'
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {createContext, useContext, useMemo} from 'react'
|
||||
import {hasMutedWord} from '@atproto/api'
|
||||
import {hasMutedWord} from '@bsky.app/sdk/moderation'
|
||||
import {QueryClient, useQuery} from '@tanstack/react-query'
|
||||
|
||||
import {useOnAppStateChange} from '#/lib/appState'
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import {useEffect} from 'react'
|
||||
import {type Agent, AppBskyActorDefs, asPredicate} from '@atproto/api'
|
||||
import {getPreferences, updateLiveEventPreferences} from '@bsky.app/sdk'
|
||||
import {useMutation, useQueryClient} from '@tanstack/react-query'
|
||||
|
||||
import {
|
||||
preferencesQueryKey,
|
||||
usePreferencesQuery,
|
||||
} from '#/state/queries/preferences'
|
||||
import {useAgent} from '#/state/session'
|
||||
import {usePdsClient} from '#/state/session'
|
||||
import {useAnalytics} from '#/analytics'
|
||||
import * as env from '#/env'
|
||||
import {IS_WEB} from '#/env'
|
||||
@@ -14,10 +14,11 @@ import {
|
||||
type LiveEventFeed,
|
||||
type LiveEventFeedMetricContext,
|
||||
} from '#/features/liveEvents/types'
|
||||
import {app} from '#/lexicons'
|
||||
|
||||
export type LiveEventPreferencesAction = Parameters<
|
||||
Agent['updateLiveEventPreferences']
|
||||
>[0] & {
|
||||
typeof updateLiveEventPreferences
|
||||
>[1] & {
|
||||
/**
|
||||
* Flag that is internal to this hook, do not set when updating prefs
|
||||
*/
|
||||
@@ -38,7 +39,7 @@ export function useLiveEventPreferences() {
|
||||
|
||||
function useWebOnlyDebugLiveEventPreferences() {
|
||||
const queryClient = useQueryClient()
|
||||
const agent = useAgent()
|
||||
const pdsClient = usePdsClient()
|
||||
|
||||
useEffect(() => {
|
||||
if (env.IS_DEV && IS_WEB && typeof window !== 'undefined') {
|
||||
@@ -46,14 +47,14 @@ function useWebOnlyDebugLiveEventPreferences() {
|
||||
window.__updateLiveEventPreferences = async (
|
||||
action: LiveEventPreferencesAction,
|
||||
) => {
|
||||
await agent.updateLiveEventPreferences(action)
|
||||
await pdsClient.call(updateLiveEventPreferences, action)
|
||||
// triggers a refetch
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: preferencesQueryKey,
|
||||
})
|
||||
}
|
||||
}
|
||||
}, [agent, queryClient])
|
||||
}, [pdsClient, queryClient])
|
||||
}
|
||||
|
||||
export function useUpdateLiveEventPreferences(props: {
|
||||
@@ -65,10 +66,10 @@ export function useUpdateLiveEventPreferences(props: {
|
||||
}) {
|
||||
const ax = useAnalytics()
|
||||
const queryClient = useQueryClient()
|
||||
const agent = useAgent()
|
||||
const pdsClient = usePdsClient()
|
||||
|
||||
return useMutation<
|
||||
AppBskyActorDefs.LiveEventPreferences,
|
||||
app.bsky.actor.defs.LiveEventPreferences,
|
||||
Error,
|
||||
LiveEventPreferencesAction,
|
||||
{undoAction: LiveEventPreferencesAction | null}
|
||||
@@ -108,10 +109,14 @@ export function useUpdateLiveEventPreferences(props: {
|
||||
}
|
||||
},
|
||||
mutationFn: async action => {
|
||||
const updated = await agent.updateLiveEventPreferences(action)
|
||||
const prefs = updated.find(p =>
|
||||
asPredicate(AppBskyActorDefs.validateLiveEventPreferences)(p),
|
||||
)
|
||||
/*
|
||||
* The SDK action returns void, so after applying the update we read the
|
||||
* fresh, interpreted preferences back to obtain the updated
|
||||
* `liveEventPreferences` (the SDK extracts it from the raw prefs array for
|
||||
* us, replacing the old `asPredicate(...).find(...)` lookup).
|
||||
*/
|
||||
await pdsClient.call(updateLiveEventPreferences, action)
|
||||
const {liveEventPreferences: prefs} = await pdsClient.call(getPreferences)
|
||||
|
||||
switch (action.type) {
|
||||
case 'hideFeed':
|
||||
@@ -138,7 +143,7 @@ export function useUpdateLiveEventPreferences(props: {
|
||||
break
|
||||
}
|
||||
case 'toggleHideAllFeeds': {
|
||||
if (prefs!.hideAllFeeds) {
|
||||
if (prefs.hideAllFeeds) {
|
||||
ax.metric('liveEvents:hideAllFeedBanners', {
|
||||
context: props.metricContext,
|
||||
})
|
||||
@@ -156,7 +161,7 @@ export function useUpdateLiveEventPreferences(props: {
|
||||
queryKey: preferencesQueryKey,
|
||||
})
|
||||
|
||||
return prefs!
|
||||
return prefs
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
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'
|
||||
@@ -26,6 +25,7 @@ import {
|
||||
useUpsertLiveStatusMutation,
|
||||
} from '#/features/liveNow'
|
||||
import {LinkPreview} from '#/features/liveNow/components/LinkPreview'
|
||||
import {type app} from '#/lexicons'
|
||||
|
||||
export function EditLiveDialog({
|
||||
control,
|
||||
@@ -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 (
|
||||
<Dialog.Outer control={control} nativeOptions={{preventExpansion: true}}>
|
||||
@@ -48,14 +48,14 @@ 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()
|
||||
const t = useTheme()
|
||||
|
||||
const [liveLink, setLiveLink] = useState(embed.external.uri)
|
||||
const [liveLink, setLiveLink] = useState<string>(embed.external.uri)
|
||||
const [liveLinkError, setLiveLinkError] = useState('')
|
||||
const tick = useTickEveryMinute()
|
||||
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
import {useCallback, useState} from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {type AppBskyActorDefs, ToolsOzoneReportDefs} from '@atproto/api'
|
||||
import {type AppBskyActorDefs} from '@atproto/api'
|
||||
import {api} from '@bsky.app/sdk'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
import {useMutation} from '@tanstack/react-query'
|
||||
|
||||
import {BLUESKY_MOD_SERVICE_HEADERS} from '#/lib/constants'
|
||||
import {logger} from '#/logger'
|
||||
import {useAgent} from '#/state/session'
|
||||
import {useMaybePdsClient, useSession} from '#/state/session'
|
||||
import {atoms as a, web} from '#/alf'
|
||||
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
|
||||
import * as Dialog from '#/components/Dialog'
|
||||
import {Loader} from '#/components/Loader'
|
||||
import * as Toast from '#/components/Toast'
|
||||
import {Text} from '#/components/Typography'
|
||||
import {com, tools} from '#/lexicons'
|
||||
import {toLex} from '#/types/bsky'
|
||||
|
||||
export function GoLiveDisabledDialog({
|
||||
control,
|
||||
@@ -39,12 +41,13 @@ export function DialogInner({
|
||||
status: AppBskyActorDefs.StatusView
|
||||
}) {
|
||||
const {_} = useLingui()
|
||||
const agent = useAgent()
|
||||
const {currentAccount} = useSession()
|
||||
const pdsClient = useMaybePdsClient()
|
||||
const [details, setDetails] = useState('')
|
||||
|
||||
const {mutate, isPending} = useMutation({
|
||||
mutationFn: async () => {
|
||||
if (!agent.session?.did) {
|
||||
if (!currentAccount?.did || !pdsClient) {
|
||||
throw new Error('Not logged in')
|
||||
}
|
||||
if (!status.uri || !status.cid) {
|
||||
@@ -56,19 +59,19 @@ export function DialogInner({
|
||||
details,
|
||||
})
|
||||
} else {
|
||||
await agent.createModerationReport(
|
||||
{
|
||||
reasonType: ToolsOzoneReportDefs.REASONAPPEAL,
|
||||
await pdsClient.call(
|
||||
com.atproto.moderation.createReport,
|
||||
toLex<com.atproto.moderation.createReport.$InputBody>({
|
||||
reasonType: tools.ozone.report.defs.reasonAppeal.value,
|
||||
subject: {
|
||||
$type: 'com.atproto.repo.strongRef',
|
||||
uri: status.uri,
|
||||
cid: status.cid,
|
||||
},
|
||||
reason: details,
|
||||
},
|
||||
}),
|
||||
{
|
||||
encoding: 'application/json',
|
||||
headers: BLUESKY_MOD_SERVICE_HEADERS,
|
||||
service: api.moderation.service,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import {useCallback, useMemo} from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {Image} from 'expo-image'
|
||||
import {
|
||||
type AppBskyActorDefs,
|
||||
type AppBskyEmbedExternal,
|
||||
moderateStatus,
|
||||
} from '@atproto/api'
|
||||
import {moderateStatus} from '@bsky.app/sdk/moderation'
|
||||
import {Trans, useLingui} from '@lingui/react/macro'
|
||||
import {useNavigation} from '@react-navigation/native'
|
||||
import {useQueryClient} from '@tanstack/react-query'
|
||||
@@ -30,7 +26,8 @@ import * as ProfileCard from '#/components/ProfileCard'
|
||||
import {Text} from '#/components/Typography'
|
||||
import {useAnalytics} from '#/analytics'
|
||||
import {LiveIndicator} from '#/features/liveNow/components/LiveIndicator'
|
||||
import type * as bsky from '#/types/bsky'
|
||||
import {type app} from '#/lexicons'
|
||||
import * as bsky from '#/types/bsky'
|
||||
|
||||
export function LiveStatusDialog({
|
||||
control,
|
||||
@@ -40,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<NavigationProp>()
|
||||
return (
|
||||
@@ -64,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()
|
||||
@@ -102,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
|
||||
}) {
|
||||
@@ -118,7 +115,8 @@ export function LiveStatus({
|
||||
const dialogContext = Dialog.useDialogContext()
|
||||
const moderation = useMemo(() => {
|
||||
if (!moderationOpts) return undefined
|
||||
return moderateStatus(profile, moderationOpts)
|
||||
// TODO(phase4): drop toLex once profile producers emit #/lexicons views
|
||||
return moderateStatus(bsky.toLex(profile), moderationOpts)
|
||||
}, [profile, moderationOpts])
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import {useMemo} from 'react'
|
||||
import {
|
||||
type $Typed,
|
||||
type AppBskyActorDefs,
|
||||
type AppBskyActorStatus,
|
||||
AppBskyEmbedExternal,
|
||||
AtUri,
|
||||
ComAtprotoRepoPutRecord,
|
||||
moderateStatus,
|
||||
} from '@atproto/api'
|
||||
import {retry} from '@atproto/common-web'
|
||||
import {type $Typed} from '@atproto/lex'
|
||||
import {
|
||||
type AtIdentifierString,
|
||||
AtUri,
|
||||
type DatetimeString,
|
||||
type UriString,
|
||||
} from '@atproto/syntax'
|
||||
import {moderateStatus} from '@bsky.app/sdk/moderation'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
|
||||
@@ -17,19 +16,21 @@ import {isAfter, parseISO} from 'date-fns'
|
||||
import {uploadBlob} from '#/lib/api'
|
||||
import {imageToThumb} from '#/lib/api/resolve'
|
||||
import {getLinkMeta, type LinkMeta} from '#/lib/link-meta/link-meta'
|
||||
import {getErrorName} from '#/lib/xrpc-error'
|
||||
import {useAppConfig} from '#/state/appConfig'
|
||||
import {
|
||||
updateProfileShadow,
|
||||
useMaybeProfileShadow,
|
||||
} from '#/state/cache/profile-shadow'
|
||||
import {useModerationOpts} from '#/state/preferences/moderation-opts'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
import {useAgent, usePdsClient, useSession} from '#/state/session'
|
||||
import {useTickEveryMinute} from '#/state/shell'
|
||||
import {useDialogContext} from '#/components/Dialog'
|
||||
import * as Toast from '#/components/Toast'
|
||||
import {useAnalytics} from '#/analytics'
|
||||
import {getLiveNowHost, getLiveServiceNames} from '#/features/liveNow/utils'
|
||||
import type * as bsky from '#/types/bsky'
|
||||
import {app, com} from '#/lexicons'
|
||||
import * as bsky from '#/types/bsky'
|
||||
|
||||
export * from '#/features/liveNow/utils'
|
||||
|
||||
@@ -47,7 +48,7 @@ const DEFAULT_STATE = {
|
||||
isDisabled: false,
|
||||
isActive: false,
|
||||
record: {},
|
||||
} satisfies AppBskyActorDefs.StatusView
|
||||
} satisfies app.bsky.actor.defs.StatusView
|
||||
|
||||
export type LiveNowConfig = {
|
||||
canGoLive: boolean
|
||||
@@ -104,7 +105,8 @@ export function useActorStatus(actor?: bsky.profile.AnyProfileView) {
|
||||
const moderation = useMemo(() => {
|
||||
if (!actor || !('status' in actor && actor.status)) return undefined
|
||||
if (!moderationOpts) return undefined
|
||||
return moderateStatus(actor, moderationOpts)
|
||||
// TODO(phase4): drop toLex once profile producers emit #/lexicons views
|
||||
return moderateStatus(bsky.toLex(actor), moderationOpts)
|
||||
}, [actor, moderationOpts])
|
||||
|
||||
return useMemo(() => {
|
||||
@@ -118,31 +120,37 @@ export function useActorStatus(actor?: bsky.profile.AnyProfileView) {
|
||||
}
|
||||
|
||||
if (shadowed && 'status' in shadowed && shadowed.status) {
|
||||
const isValid = isStatusValidForViewers(shadowed.status, config)
|
||||
const isDisabled = shadowed.status.isDisabled || false
|
||||
const isActive = isStatusStillActive(shadowed.status.expiresAt)
|
||||
/*
|
||||
* TODO(phase4): drop toLex once profile-shadow emits #/lexicons views.
|
||||
* The shadow store still holds old `@atproto/api` StatusViews, so brand
|
||||
* it once here to feed the new-world validation and returned view.
|
||||
*/
|
||||
const status = bsky.toLex<app.bsky.actor.defs.StatusView>(shadowed.status)
|
||||
const isValid = isStatusValidForViewers(status, config)
|
||||
const isDisabled = status.isDisabled || false
|
||||
const isActive = isStatusStillActive(status.expiresAt)
|
||||
if (isValid && !isDisabled && isActive) {
|
||||
return {
|
||||
uri: shadowed.status.uri,
|
||||
cid: shadowed.status.cid,
|
||||
uri: status.uri,
|
||||
cid: status.cid,
|
||||
isDisabled: false,
|
||||
isActive: true,
|
||||
status: 'app.bsky.actor.status#live',
|
||||
embed: shadowed.status.embed as $Typed<AppBskyEmbedExternal.View>, // temp_isStatusValid asserts this
|
||||
expiresAt: shadowed.status.expiresAt!, // isStatusStillActive asserts this
|
||||
record: shadowed.status.record,
|
||||
} satisfies AppBskyActorDefs.StatusView
|
||||
embed: status.embed as $Typed<app.bsky.embed.external.View>, // temp_isStatusValid asserts this
|
||||
expiresAt: status.expiresAt!, // isStatusStillActive asserts this
|
||||
record: status.record,
|
||||
} satisfies app.bsky.actor.defs.StatusView
|
||||
}
|
||||
return {
|
||||
uri: shadowed.status.uri,
|
||||
cid: shadowed.status.cid,
|
||||
uri: status.uri,
|
||||
cid: status.cid,
|
||||
isDisabled,
|
||||
isActive: false,
|
||||
status: 'app.bsky.actor.status#live',
|
||||
embed: shadowed.status.embed as $Typed<AppBskyEmbedExternal.View>, // temp_isStatusValid asserts this
|
||||
expiresAt: shadowed.status.expiresAt!, // isStatusStillActive asserts this
|
||||
record: shadowed.status.record,
|
||||
} satisfies AppBskyActorDefs.StatusView
|
||||
embed: status.embed as $Typed<app.bsky.embed.external.View>, // temp_isStatusValid asserts this
|
||||
expiresAt: status.expiresAt!, // isStatusStillActive asserts this
|
||||
record: status.record,
|
||||
} satisfies app.bsky.actor.defs.StatusView
|
||||
} else {
|
||||
return DEFAULT_STATE
|
||||
}
|
||||
@@ -162,14 +170,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
|
||||
@@ -217,7 +225,7 @@ export function useUpsertLiveStatusMutation(
|
||||
) {
|
||||
const ax = useAnalytics()
|
||||
const {currentAccount} = useSession()
|
||||
const agent = useAgent()
|
||||
const pdsClient = usePdsClient()
|
||||
const queryClient = useQueryClient()
|
||||
const control = useDialogContext()
|
||||
const {_} = useLingui()
|
||||
@@ -226,7 +234,7 @@ export function useUpsertLiveStatusMutation(
|
||||
mutationFn: async () => {
|
||||
if (!currentAccount) throw new Error('Not logged in')
|
||||
|
||||
let embed: $Typed<AppBskyEmbedExternal.Main> | undefined
|
||||
let embed: $Typed<app.bsky.embed.external.Main> | undefined
|
||||
|
||||
if (linkMeta) {
|
||||
let thumb
|
||||
@@ -236,11 +244,11 @@ export function useUpsertLiveStatusMutation(
|
||||
const img = await imageToThumb(linkMeta.image)
|
||||
if (img) {
|
||||
const blob = await uploadBlob(
|
||||
agent,
|
||||
pdsClient,
|
||||
img.source.path,
|
||||
img.source.mime,
|
||||
)
|
||||
thumb = blob.data.blob
|
||||
thumb = blob.blob
|
||||
}
|
||||
} catch (e: any) {
|
||||
ax.logger.error(`Failed to upload thumbnail for live status`, {
|
||||
@@ -257,7 +265,7 @@ export function useUpsertLiveStatusMutation(
|
||||
$type: 'app.bsky.embed.external#external',
|
||||
title: linkMeta.title ?? '',
|
||||
description: linkMeta.description ?? '',
|
||||
uri: linkMeta.url,
|
||||
uri: linkMeta.url as UriString,
|
||||
thumb,
|
||||
},
|
||||
}
|
||||
@@ -265,32 +273,32 @@ export function useUpsertLiveStatusMutation(
|
||||
|
||||
const record = {
|
||||
$type: 'app.bsky.actor.status',
|
||||
createdAt: createdAt ?? new Date().toISOString(),
|
||||
createdAt: (createdAt ?? new Date().toISOString()) as DatetimeString,
|
||||
status: 'app.bsky.actor.status#live',
|
||||
durationMinutes: duration,
|
||||
embed,
|
||||
} satisfies AppBskyActorStatus.Record
|
||||
} satisfies app.bsky.actor.status.Main
|
||||
|
||||
const upsert = async () => {
|
||||
const repo = currentAccount.did
|
||||
const repo = currentAccount.did as AtIdentifierString
|
||||
const collection = 'app.bsky.actor.status'
|
||||
|
||||
const existing = await agent.com.atproto.repo
|
||||
.getRecord({repo, collection, rkey: 'self'})
|
||||
const existing = await pdsClient
|
||||
.call(com.atproto.repo.getRecord, {repo, collection, rkey: 'self'})
|
||||
.catch(_e => undefined)
|
||||
|
||||
await agent.com.atproto.repo.putRecord({
|
||||
await pdsClient.call(com.atproto.repo.putRecord, {
|
||||
repo,
|
||||
collection,
|
||||
rkey: 'self',
|
||||
record,
|
||||
swapRecord: existing?.data.cid || null,
|
||||
swapRecord: existing?.cid || null,
|
||||
})
|
||||
}
|
||||
|
||||
await retry(upsert, {
|
||||
maxRetries: 5,
|
||||
retryable: e => e instanceof ComAtprotoRepoPutRecord.InvalidSwapError,
|
||||
retryable: e => getErrorName(e) === 'InvalidSwap',
|
||||
})
|
||||
|
||||
return {
|
||||
@@ -347,7 +355,7 @@ export function useUpsertLiveStatusMutation(
|
||||
export function useRemoveLiveStatusMutation() {
|
||||
const ax = useAnalytics()
|
||||
const {currentAccount} = useSession()
|
||||
const agent = useAgent()
|
||||
const pdsClient = usePdsClient()
|
||||
const queryClient = useQueryClient()
|
||||
const control = useDialogContext()
|
||||
const {_} = useLingui()
|
||||
@@ -356,8 +364,8 @@ export function useRemoveLiveStatusMutation() {
|
||||
mutationFn: async () => {
|
||||
if (!currentAccount) throw new Error('Not logged in')
|
||||
|
||||
await agent.app.bsky.actor.status.delete({
|
||||
repo: currentAccount.did,
|
||||
await pdsClient.delete(app.bsky.actor.status, {
|
||||
repo: currentAccount.did as AtIdentifierString,
|
||||
rkey: 'self',
|
||||
})
|
||||
},
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import {AppBskyActorStatus, AppBskyEmbedExternal} from '@atproto/api'
|
||||
import {type I18n} from '@lingui/core'
|
||||
import {plural} from '@lingui/core/macro'
|
||||
import psl from 'psl'
|
||||
|
||||
import {app} from '#/lexicons'
|
||||
import * as bsky from '#/types/bsky'
|
||||
|
||||
/**
|
||||
* Validates a raw status record and returns the typed record, or null if the
|
||||
* value is not a valid `app.bsky.actor.status` record.
|
||||
*/
|
||||
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 +23,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, record.embed)) return ''
|
||||
return record.embed.external.uri
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* The jest suite ships global manual mocks for `multiformats/cid` and
|
||||
* `multiformats/hashes/hasher` (in root `__mocks__/`) so unrelated tests don't
|
||||
* pull in real crypto. This test is precisely about the real CID hashing, so we
|
||||
* opt back into the actual implementations here.
|
||||
*/
|
||||
jest.unmock('multiformats/cid')
|
||||
jest.unmock('multiformats/hashes/hasher')
|
||||
|
||||
import {BlobRef} from '@atproto/api'
|
||||
import {CID} from 'multiformats/cid'
|
||||
|
||||
import {computeCid} from '#/lib/api/computeCid'
|
||||
import {type app, type com} from '#/lexicons'
|
||||
|
||||
/*
|
||||
* Golden-CID regression test for the composer post pipeline (design section F).
|
||||
*
|
||||
* `computeCid` hashes a post record in the client so a thread's later posts can
|
||||
* reference earlier posts by CID before the server assigns them. The hash is
|
||||
* byte-sensitive: any drift in how records (especially blobs) are serialized to
|
||||
* DAG-CBOR silently produces the wrong CID and breaks reply chains with NO type
|
||||
* error. These golden values were captured from the PRE-migration `computeCid`
|
||||
* (the `instanceof BlobRef` path) and MUST remain byte-identical after the guard
|
||||
* is changed to the structural `isBlobRef` shape check.
|
||||
*
|
||||
* The blob CID below is a fixed, deterministic CIDv1/raw/sha256 used purely as a
|
||||
* stable fixture - it is not derived from any real upload.
|
||||
*/
|
||||
const BLOB_CID = 'bafkreieq5jui4j25lacwomsqgjeswwl3y5zcdrresptwgmfylxo2depppq'
|
||||
|
||||
/**
|
||||
* Build a post record with an image embed whose blob is the given value. Used to
|
||||
* prove that a `@atproto/api` `BlobRef` class instance (the shape the not-yet
|
||||
* -migrated video path still yields) and a plain-JSON lex blob (the shape lex
|
||||
* `uploadBlob` returns) hash to the SAME CID.
|
||||
*/
|
||||
function postWithImageBlob(blob: unknown): app.bsky.feed.post.Main {
|
||||
return {
|
||||
$type: 'app.bsky.feed.post',
|
||||
createdAt: '2024-01-01T00:00:00.001Z',
|
||||
text: 'post with image',
|
||||
embed: {
|
||||
$type: 'app.bsky.embed.images',
|
||||
images: [
|
||||
{
|
||||
image: blob,
|
||||
alt: 'alt text',
|
||||
aspectRatio: {width: 100, height: 200},
|
||||
},
|
||||
],
|
||||
},
|
||||
} as app.bsky.feed.post.Main
|
||||
}
|
||||
|
||||
describe('computeCid', () => {
|
||||
it('case 1: plain post record with no blob', async () => {
|
||||
const record: app.bsky.feed.post.Main = {
|
||||
$type: 'app.bsky.feed.post',
|
||||
createdAt: '2024-01-01T00:00:00.000Z',
|
||||
text: 'hello world',
|
||||
}
|
||||
expect(await computeCid(record)).toBe(
|
||||
'bafyreieawtmh7hwfrqpamqkodza5r62bbfhsepe2iyustgxhgbhi6b2lfi',
|
||||
)
|
||||
})
|
||||
|
||||
it('case 2: record whose embed carries a BlobRef class instance', async () => {
|
||||
const blob = new BlobRef(CID.parse(BLOB_CID), 'image/jpeg', 12345)
|
||||
expect(await computeCid(postWithImageBlob(blob))).toBe(
|
||||
'bafyreiem7g6vja66nebr7he4fshfnlyndyldbvle2n265oixscmepjcbii',
|
||||
)
|
||||
})
|
||||
|
||||
it('case 2b: a plain-JSON blob object hashes identically to the class instance', async () => {
|
||||
/*
|
||||
* This is the post-migration shape: lex `uploadBlob` returns a plain object
|
||||
* `{$type: 'blob', ref, mimeType, size}` (with `ref` a parsed CID), not a
|
||||
* `BlobRef` class instance. The structural `isBlobRef` guard must treat it
|
||||
* exactly like the class instance so the CID is unchanged. Under the
|
||||
* pre-change `instanceof` code this case already matches because the plain
|
||||
* object walks through `prepareForHashing` unchanged and DAG-CBOR encodes
|
||||
* its CID `ref` the same way `.ipld()` does.
|
||||
*/
|
||||
const blob = {
|
||||
$type: 'blob' as const,
|
||||
ref: CID.parse(BLOB_CID),
|
||||
mimeType: 'image/jpeg',
|
||||
size: 12345,
|
||||
}
|
||||
expect(await computeCid(postWithImageBlob(blob))).toBe(
|
||||
'bafyreiem7g6vja66nebr7he4fshfnlyndyldbvle2n265oixscmepjcbii',
|
||||
)
|
||||
})
|
||||
|
||||
it('case 3: three-post thread chains reply StrongRef CIDs', async () => {
|
||||
const did = 'did:plc:abc123'
|
||||
const base = new Date('2024-01-01T00:00:00.000Z')
|
||||
const golden = [
|
||||
'bafyreig62rxs34h5rvznfrracwkjlfgad5b25qxglp2hcziqdfas2nw2ee',
|
||||
'bafyreicxcj2tq5jrh5jcaczg3eli5cvxitgzu7kpu3fm5v3njq2byjxirq',
|
||||
'bafyreigvaswuhlpd7dllja2xrqswhqbruyv2kar7mvbn7gdm5ldzu6vkti',
|
||||
]
|
||||
|
||||
let reply: app.bsky.feed.post.Main['reply'] | undefined
|
||||
for (let i = 0; i < 3; i++) {
|
||||
const now = new Date(base.getTime() + i)
|
||||
const uri = `at://${did}/app.bsky.feed.post/rkey${i}`
|
||||
const record = {
|
||||
$type: 'app.bsky.feed.post',
|
||||
createdAt: now.toISOString(),
|
||||
text: `post ${i}`,
|
||||
reply,
|
||||
} as app.bsky.feed.post.Main
|
||||
const cid = await computeCid(record)
|
||||
expect(cid).toBe(golden[i])
|
||||
const ref = {cid, uri} as com.atproto.repo.strongRef.Main
|
||||
reply = {root: reply?.root ?? ref, parent: ref}
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,158 @@
|
||||
import {sha256} from 'js-sha256'
|
||||
import {CID} from 'multiformats/cid'
|
||||
import * as Hasher from 'multiformats/hashes/hasher'
|
||||
|
||||
import {app} from '#/lexicons'
|
||||
|
||||
/*
|
||||
* Client-side CID computation for post records, extracted from the post
|
||||
* pipeline so it can be unit-tested in isolation (importing the pipeline pulls
|
||||
* in the native gallery/media chain). See `computeCid.test.ts` for the golden
|
||||
* -CID regression fixtures that gate any change to this serialization.
|
||||
*/
|
||||
|
||||
// The built-in hashing functions from multiformats (`multiformats/hashes/sha2`)
|
||||
// are meant for Node.js, this is the cross-platform equivalent.
|
||||
const mf_sha256 = Hasher.from({
|
||||
name: 'sha2-256',
|
||||
code: 0x12,
|
||||
encode: input => {
|
||||
const digest = sha256.arrayBuffer(input)
|
||||
return new Uint8Array(digest)
|
||||
},
|
||||
})
|
||||
|
||||
export async function computeCid(
|
||||
record: app.bsky.feed.post.Main,
|
||||
): Promise<string> {
|
||||
/*
|
||||
* Lazily loaded since it's only needed when posting a thread, and its
|
||||
* `cborg` dependency is ~190KB that would otherwise be in the initial
|
||||
* web bundle.
|
||||
*/
|
||||
const dcbor = await importDagCbor()
|
||||
// IMPORTANT: `prepareObject` prepares the record to be hashed by removing
|
||||
// fields with undefined value, and converting BlobRef instances to the
|
||||
// right IPLD representation.
|
||||
const prepared = prepareForHashing(record)
|
||||
// 1. Encode the record into DAG-CBOR format
|
||||
const encoded = dcbor.encode(prepared)
|
||||
// 2. Hash the record in SHA-256 (code 0x12)
|
||||
const digest = await mf_sha256.digest(encoded)
|
||||
// 3. Create a CIDv1, specifying DAG-CBOR as content (code 0x71)
|
||||
const cid = CID.createV1(0x71, digest)
|
||||
// 4. Get the Base32 representation of the CID (`b` prefix)
|
||||
return cid.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* True for a plain-JSON lexicon blob, the shape lex `uploadBlob` now returns
|
||||
* (`{$type: 'blob', ref, mimeType, size}` with `ref` a parsed CID). Replaces
|
||||
* the old `instanceof BlobRef` check, since lex blobs are plain objects, not
|
||||
* class instances (design section F).
|
||||
*/
|
||||
function isBlobRef(v: unknown): boolean {
|
||||
if (v == null || typeof v !== 'object') return false
|
||||
const o = v as Record<string, unknown>
|
||||
return o.$type === 'blob' && 'ref' in o && 'mimeType' in o
|
||||
}
|
||||
|
||||
/**
|
||||
* True for a legacy `@atproto/api` `BlobRef` class instance. During the
|
||||
* migration the video embed path still yields these (its blob comes from the
|
||||
* not-yet-migrated `app.bsky.video.getJobStatus` bridge call), so we must keep
|
||||
* handling them here even though the composer's own uploads are now plain lex
|
||||
* blobs. A class instance is duck-typed by its `ipld()` method plus the
|
||||
* `ref`/`mimeType` fields; it has NO `$type` and a non-plain prototype, so it
|
||||
* would otherwise slip past both `isBlobRef` and `isPlainObject` and be encoded
|
||||
* wrong - silently breaking video reply-chain CIDs.
|
||||
*/
|
||||
function isBlobRefInstance(
|
||||
v: unknown,
|
||||
): v is {ipld: () => unknown; ref: unknown; mimeType: unknown} {
|
||||
if (v == null || typeof v !== 'object') return false
|
||||
const o = v as Record<string, unknown>
|
||||
return typeof o.ipld === 'function' && 'ref' in o && 'mimeType' in o
|
||||
}
|
||||
|
||||
// Returns a transformed version of the object for use in DAG-CBOR.
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function prepareForHashing(v: any): any {
|
||||
/*
|
||||
* A plain-JSON lex blob is already in the right IPLD shape (its `ref` is a
|
||||
* parsed CID that DAG-CBOR encodes as a CID link), so pass it through
|
||||
* untouched.
|
||||
*/
|
||||
if (isBlobRef(v)) {
|
||||
return v
|
||||
}
|
||||
|
||||
/*
|
||||
* A legacy `BlobRef` class instance must be converted via `ipld()` to the
|
||||
* plain `{$type, ref, mimeType, size}` object; encoding the instance directly
|
||||
* would emit its internal `original` field and omit `$type`, producing the
|
||||
* wrong CID. `ipld()` returns exactly what `isBlobRef` accepts above.
|
||||
*/
|
||||
if (isBlobRefInstance(v)) {
|
||||
return v.ipld()
|
||||
}
|
||||
|
||||
// Walk through arrays
|
||||
if (Array.isArray(v)) {
|
||||
let pure = true
|
||||
const mapped = v.map(value => {
|
||||
if (value !== (value = prepareForHashing(value))) {
|
||||
pure = false
|
||||
}
|
||||
return value
|
||||
})
|
||||
return pure ? v : mapped
|
||||
}
|
||||
|
||||
// Walk through plain objects
|
||||
if (isPlainObject(v)) {
|
||||
const rec = v as Record<string, unknown>
|
||||
const obj: Record<string, unknown> = {}
|
||||
let pure = true
|
||||
for (const key in rec) {
|
||||
let value = rec[key]
|
||||
// `value` is undefined
|
||||
if (value === undefined) {
|
||||
pure = false
|
||||
continue
|
||||
}
|
||||
// `prepareObject` returned a value that's different from what we had before
|
||||
if (value !== (value = prepareForHashing(value))) {
|
||||
pure = false
|
||||
}
|
||||
obj[key] = value
|
||||
}
|
||||
// Return as is if we haven't needed to tamper with anything
|
||||
return pure ? v : obj
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function isPlainObject(v: any): boolean {
|
||||
if (typeof v !== 'object' || v === null) {
|
||||
return false
|
||||
}
|
||||
const proto = Object.getPrototypeOf(v)
|
||||
return proto === Object.prototype || proto === null
|
||||
}
|
||||
|
||||
/**
|
||||
* Load `@ipld/dag-cbor` on demand. The dynamic `import()` lets web bundlers
|
||||
* emit it (and its ~190KB `cborg` dependency) as a separate chunk that only
|
||||
* loads when posting a thread. Under jest (which runs without
|
||||
* `--experimental-vm-modules`) dynamic import throws, so we fall back to a
|
||||
* lazy `require`, which resolves through the test moduleNameMapper.
|
||||
*/
|
||||
function importDagCbor(): Promise<typeof import('@ipld/dag-cbor')> {
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
return Promise.resolve(require('@ipld/dag-cbor'))
|
||||
}
|
||||
return import('@ipld/dag-cbor')
|
||||
}
|
||||
+24
-28
@@ -1,23 +1,21 @@
|
||||
import {
|
||||
AppBskyFeedDefs,
|
||||
type AppBskyFeedGetAuthorFeed as GetAuthorFeed,
|
||||
} from '@atproto/api'
|
||||
import {type Client} from '@atproto/lex-client'
|
||||
|
||||
import {type SessionAgent} from '#/state/session'
|
||||
import {app} from '#/lexicons'
|
||||
import * as bsky from '#/types/bsky'
|
||||
import {type FeedAPI, type FeedAPIResponse} from './types'
|
||||
|
||||
export class AuthorFeedAPI implements FeedAPI {
|
||||
agent: SessionAgent
|
||||
_params: GetAuthorFeed.QueryParams
|
||||
client: Client
|
||||
_params: app.bsky.feed.getAuthorFeed.$Params
|
||||
|
||||
constructor({
|
||||
agent,
|
||||
client,
|
||||
feedParams,
|
||||
}: {
|
||||
agent: SessionAgent
|
||||
feedParams: GetAuthorFeed.QueryParams
|
||||
client: Client
|
||||
feedParams: app.bsky.feed.getAuthorFeed.$Params
|
||||
}) {
|
||||
this.agent = agent
|
||||
this.client = client
|
||||
this._params = feedParams
|
||||
}
|
||||
|
||||
@@ -27,12 +25,12 @@ export class AuthorFeedAPI implements FeedAPI {
|
||||
return params
|
||||
}
|
||||
|
||||
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
|
||||
const res = await this.agent.getAuthorFeed({
|
||||
async peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost> {
|
||||
const res = await this.client.call(app.bsky.feed.getAuthorFeed, {
|
||||
...this.params,
|
||||
limit: 1,
|
||||
})
|
||||
return res.data.feed[0]
|
||||
return res.feed[0]
|
||||
}
|
||||
|
||||
async fetch({
|
||||
@@ -42,28 +40,26 @@ export class AuthorFeedAPI implements FeedAPI {
|
||||
cursor: string | undefined
|
||||
limit: number
|
||||
}): Promise<FeedAPIResponse> {
|
||||
const res = await this.agent.getAuthorFeed({
|
||||
const res = await this.client.call(app.bsky.feed.getAuthorFeed, {
|
||||
...this.params,
|
||||
cursor,
|
||||
limit,
|
||||
})
|
||||
if (res.success) {
|
||||
return {
|
||||
cursor: res.data.cursor,
|
||||
feed: this._filter(res.data.feed),
|
||||
}
|
||||
}
|
||||
return {
|
||||
feed: [],
|
||||
cursor: res.cursor,
|
||||
feed: this._filter(res.feed),
|
||||
}
|
||||
}
|
||||
|
||||
_filter(feed: AppBskyFeedDefs.FeedViewPost[]) {
|
||||
_filter(feed: app.bsky.feed.defs.FeedViewPost[]) {
|
||||
if (this.params.filter === 'posts_and_author_threads') {
|
||||
return feed.filter(post => {
|
||||
const isReply = post.reply
|
||||
const isRepost = AppBskyFeedDefs.isReasonRepost(post.reason)
|
||||
const isPin = AppBskyFeedDefs.isReasonPin(post.reason)
|
||||
const isRepost = bsky.isType(
|
||||
app.bsky.feed.defs.reasonRepost,
|
||||
post.reason,
|
||||
)
|
||||
const isPin = bsky.isType(app.bsky.feed.defs.reasonPin, post.reason)
|
||||
if (!isReply) return true
|
||||
if (isRepost || isPin) return true
|
||||
return isReply && isAuthorReplyChain(this.params.actor, post, feed)
|
||||
@@ -76,15 +72,15 @@ export class AuthorFeedAPI implements FeedAPI {
|
||||
|
||||
function isAuthorReplyChain(
|
||||
actor: string,
|
||||
post: AppBskyFeedDefs.FeedViewPost,
|
||||
posts: AppBskyFeedDefs.FeedViewPost[],
|
||||
post: app.bsky.feed.defs.FeedViewPost,
|
||||
posts: app.bsky.feed.defs.FeedViewPost[],
|
||||
): boolean {
|
||||
// current post is by a different user (shouldn't happen)
|
||||
if (post.post.author.did !== actor) return false
|
||||
|
||||
const replyParent = post.reply?.parent
|
||||
|
||||
if (AppBskyFeedDefs.isPostView(replyParent)) {
|
||||
if (bsky.isType(app.bsky.feed.defs.postView, replyParent)) {
|
||||
// reply parent is by a different user
|
||||
if (replyParent.author.did !== actor) return false
|
||||
|
||||
|
||||
+67
-52
@@ -1,47 +1,53 @@
|
||||
import {
|
||||
type AppBskyFeedDefs,
|
||||
type AppBskyFeedGetFeed as GetCustomFeed,
|
||||
AtpAgent,
|
||||
jsonStringToLex,
|
||||
} from '@atproto/api'
|
||||
import {lexParse} from '@atproto/lex'
|
||||
import {Client} from '@atproto/lex-client'
|
||||
|
||||
import {
|
||||
getAppLanguageAsContentLanguage,
|
||||
getContentLanguages,
|
||||
} from '#/state/preferences/languages'
|
||||
import {type SessionAgent} from '#/state/session'
|
||||
import {app} from '#/lexicons'
|
||||
import {type FeedAPI, type FeedAPIResponse} from './types'
|
||||
import {createBskyTopicsHeader, isBlueskyOwnedFeed} from './utils'
|
||||
|
||||
/**
|
||||
* Input params for {@link CustomFeedAPI}. The generated `$Params` type reflects
|
||||
* post-parse output, where `limit` (which has a lexicon default) is required;
|
||||
* callers supply only `feed` and let `limit`/`cursor` come from `fetch`.
|
||||
*/
|
||||
type CustomFeedParams = {feed: app.bsky.feed.getFeed.$Params['feed']} & Partial<
|
||||
Omit<app.bsky.feed.getFeed.$Params, 'feed'>
|
||||
>
|
||||
|
||||
export class CustomFeedAPI implements FeedAPI {
|
||||
agent: SessionAgent
|
||||
params: GetCustomFeed.QueryParams
|
||||
client: Client
|
||||
params: CustomFeedParams
|
||||
userInterests?: string
|
||||
|
||||
constructor({
|
||||
agent,
|
||||
client,
|
||||
feedParams,
|
||||
userInterests,
|
||||
}: {
|
||||
agent: SessionAgent
|
||||
feedParams: GetCustomFeed.QueryParams
|
||||
client: Client
|
||||
feedParams: CustomFeedParams
|
||||
userInterests?: string
|
||||
}) {
|
||||
this.agent = agent
|
||||
this.client = client
|
||||
this.params = feedParams
|
||||
this.userInterests = userInterests
|
||||
}
|
||||
|
||||
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
|
||||
async peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost> {
|
||||
const contentLangs = getContentLanguages().join(',')
|
||||
const res = await this.agent.app.bsky.feed.getFeed(
|
||||
const res = await this.client.call(
|
||||
app.bsky.feed.getFeed,
|
||||
{
|
||||
...this.params,
|
||||
limit: 1,
|
||||
},
|
||||
{headers: {'Accept-Language': contentLangs}},
|
||||
)
|
||||
return res.data.feed[0]
|
||||
return res.feed[0]
|
||||
}
|
||||
|
||||
async fetch({
|
||||
@@ -52,41 +58,49 @@ export class CustomFeedAPI implements FeedAPI {
|
||||
limit: number
|
||||
}): Promise<FeedAPIResponse> {
|
||||
const contentLangs = getContentLanguages().join(',')
|
||||
const agent = this.agent
|
||||
const isBlueskyOwned = isBlueskyOwnedFeed(this.params.feed)
|
||||
|
||||
const res = agent.did
|
||||
? await this.agent.app.bsky.feed.getFeed(
|
||||
{
|
||||
...this.params,
|
||||
cursor,
|
||||
limit,
|
||||
let feed: app.bsky.feed.defs.FeedViewPost[]
|
||||
let resCursor: string | undefined
|
||||
|
||||
if (this.client.did) {
|
||||
const res = await this.client.call(
|
||||
app.bsky.feed.getFeed,
|
||||
{
|
||||
...this.params,
|
||||
cursor,
|
||||
limit,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
...(isBlueskyOwned
|
||||
? createBskyTopicsHeader(this.userInterests)
|
||||
: {}),
|
||||
'Accept-Language': contentLangs,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
...(isBlueskyOwned
|
||||
? createBskyTopicsHeader(this.userInterests)
|
||||
: {}),
|
||||
'Accept-Language': contentLangs,
|
||||
},
|
||||
},
|
||||
)
|
||||
: await loggedOutFetch({...this.params, cursor, limit})
|
||||
if (res.success) {
|
||||
// NOTE
|
||||
// some custom feeds fail to enforce the pagination limit
|
||||
// so we manually truncate here
|
||||
// -prf
|
||||
if (res.data.feed.length > limit) {
|
||||
res.data.feed = res.data.feed.slice(0, limit)
|
||||
}
|
||||
return {
|
||||
cursor: res.data.feed.length ? res.data.cursor : undefined,
|
||||
feed: res.data.feed,
|
||||
},
|
||||
)
|
||||
feed = res.feed
|
||||
resCursor = res.cursor
|
||||
} else {
|
||||
const res = await loggedOutFetch({...this.params, cursor, limit})
|
||||
if (!res.success) {
|
||||
return {feed: []}
|
||||
}
|
||||
feed = res.data.feed
|
||||
resCursor = res.data.cursor
|
||||
}
|
||||
|
||||
// NOTE
|
||||
// some custom feeds fail to enforce the pagination limit
|
||||
// so we manually truncate here
|
||||
// -prf
|
||||
if (feed.length > limit) {
|
||||
feed = feed.slice(0, limit)
|
||||
}
|
||||
return {
|
||||
feed: [],
|
||||
cursor: feed.length ? resCursor : undefined,
|
||||
feed,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,15 +120,16 @@ async function loggedOutFetch({
|
||||
feed: string
|
||||
limit: number
|
||||
cursor?: string
|
||||
}) {
|
||||
}): Promise<{success: boolean; data: app.bsky.feed.getFeed.$OutputBody}> {
|
||||
let contentLangs = getAppLanguageAsContentLanguage()
|
||||
|
||||
/**
|
||||
* Copied from our root `Agent` class
|
||||
* @see https://github.com/bluesky-social/atproto/blob/60df3fc652b00cdff71dd9235d98a7a4bb828f05/packages/api/src/agent.ts#L120
|
||||
/*
|
||||
* Copied from our root `Agent` class. The global (`;redact`-suffixed) app
|
||||
* labelers are kept on the lex `Client` static (synced in
|
||||
* `#/state/session/moderation`), replacing the old `AtpAgent.appLabelers`.
|
||||
*/
|
||||
const labelersHeader = {
|
||||
'atproto-accept-labelers': AtpAgent.appLabelers
|
||||
'atproto-accept-labelers': Client.appLabelers
|
||||
.map(l => `${l};redact`)
|
||||
.join(', '),
|
||||
}
|
||||
@@ -130,7 +145,7 @@ async function loggedOutFetch({
|
||||
},
|
||||
)
|
||||
let data = res.ok
|
||||
? (jsonStringToLex(await res.text()) as GetCustomFeed.OutputSchema)
|
||||
? (lexParse(await res.text()) as app.bsky.feed.getFeed.$OutputBody)
|
||||
: null
|
||||
if (data?.feed?.length) {
|
||||
return {
|
||||
@@ -147,7 +162,7 @@ async function loggedOutFetch({
|
||||
{method: 'GET', headers: {'Accept-Language': '', ...labelersHeader}},
|
||||
)
|
||||
data = res.ok
|
||||
? (jsonStringToLex(await res.text()) as GetCustomFeed.OutputSchema)
|
||||
? (lexParse(await res.text()) as app.bsky.feed.getFeed.$OutputBody)
|
||||
: null
|
||||
if (data?.feed?.length) {
|
||||
return {
|
||||
|
||||
@@ -1,21 +1,28 @@
|
||||
import {type AppBskyFeedDefs} from '@atproto/api'
|
||||
import {type Client} from '@atproto/lex-client'
|
||||
|
||||
import {DEMO_FEED} from '#/lib/demo'
|
||||
import {type SessionAgent} from '#/state/session'
|
||||
import {type app} from '#/lexicons'
|
||||
import {toLex} from '#/types/bsky'
|
||||
import {type FeedAPI, type FeedAPIResponse} from './types'
|
||||
|
||||
export class DemoFeedAPI implements FeedAPI {
|
||||
agent: SessionAgent
|
||||
client: Client
|
||||
|
||||
constructor({agent}: {agent: SessionAgent}) {
|
||||
this.agent = agent
|
||||
constructor({client}: {client: Client}) {
|
||||
this.client = client
|
||||
}
|
||||
|
||||
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
|
||||
return DEMO_FEED.feed[0]
|
||||
async peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost> {
|
||||
/*
|
||||
* TODO(phase4): drop this cast once `#/lib/demo` (DEMO_FEED) sources its
|
||||
* feed items from `#/lexicons`. Its records are still typed against the old
|
||||
* `@atproto/api` FeedViewPost, which does not assign to the branded lexicon
|
||||
* type this method must return.
|
||||
*/
|
||||
return toLex(DEMO_FEED.feed[0])
|
||||
}
|
||||
|
||||
async fetch(): Promise<FeedAPIResponse> {
|
||||
return DEMO_FEED
|
||||
return toLex(DEMO_FEED)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import {type AppBskyFeedDefs} from '@atproto/api'
|
||||
import {type Client} from '@atproto/lex-client'
|
||||
|
||||
import {type SessionAgent} from '#/state/session'
|
||||
import {app} from '#/lexicons'
|
||||
import {type FeedAPI, type FeedAPIResponse} from './types'
|
||||
|
||||
export class FollowingFeedAPI implements FeedAPI {
|
||||
agent: SessionAgent
|
||||
client: Client
|
||||
|
||||
constructor({agent}: {agent: SessionAgent}) {
|
||||
this.agent = agent
|
||||
constructor({client}: {client: Client}) {
|
||||
this.client = client
|
||||
}
|
||||
|
||||
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
|
||||
const res = await this.agent.getTimeline({
|
||||
async peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost> {
|
||||
const res = await this.client.call(app.bsky.feed.getTimeline, {
|
||||
limit: 1,
|
||||
})
|
||||
return res.data.feed[0]
|
||||
return res.feed[0]
|
||||
}
|
||||
|
||||
async fetch({
|
||||
@@ -24,18 +24,13 @@ export class FollowingFeedAPI implements FeedAPI {
|
||||
cursor: string | undefined
|
||||
limit: number
|
||||
}): Promise<FeedAPIResponse> {
|
||||
const res = await this.agent.getTimeline({
|
||||
const res = await this.client.call(app.bsky.feed.getTimeline, {
|
||||
cursor,
|
||||
limit,
|
||||
})
|
||||
if (res.success) {
|
||||
return {
|
||||
cursor: res.data.cursor,
|
||||
feed: res.data.feed,
|
||||
}
|
||||
}
|
||||
return {
|
||||
feed: [],
|
||||
cursor: res.cursor,
|
||||
feed: res.feed,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+21
-16
@@ -1,7 +1,8 @@
|
||||
import {type AppBskyFeedDefs} from '@atproto/api'
|
||||
import {type Client} from '@atproto/lex-client'
|
||||
import {type AtUriString} from '@atproto/syntax'
|
||||
|
||||
import {PROD_DEFAULT_FEED} from '#/lib/constants'
|
||||
import {type SessionAgent} from '#/state/session'
|
||||
import {type app} from '#/lexicons'
|
||||
import {CustomFeedAPI} from './custom'
|
||||
import {FollowingFeedAPI} from './following'
|
||||
import {type FeedAPI, type FeedAPIResponse} from './types'
|
||||
@@ -14,7 +15,11 @@ import {type FeedAPI, type FeedAPIResponse} from './types'
|
||||
// we use this fallback marker post to drive this instead. see Feed.tsx
|
||||
// for the usage.
|
||||
// -prf
|
||||
export const FALLBACK_MARKER_POST: AppBskyFeedDefs.FeedViewPost = {
|
||||
/*
|
||||
* A sentinel post whose fields intentionally violate the branded lexicon
|
||||
* formats (`uri`, `did`, `indexedAt`), so it is asserted into the view type.
|
||||
*/
|
||||
export const FALLBACK_MARKER_POST: app.bsky.feed.defs.FeedViewPost = {
|
||||
post: {
|
||||
uri: 'fallback-marker-post',
|
||||
cid: 'fake',
|
||||
@@ -25,10 +30,10 @@ export const FALLBACK_MARKER_POST: AppBskyFeedDefs.FeedViewPost = {
|
||||
},
|
||||
indexedAt: new Date().toISOString(),
|
||||
},
|
||||
}
|
||||
} as unknown as app.bsky.feed.defs.FeedViewPost
|
||||
|
||||
export class HomeFeedAPI implements FeedAPI {
|
||||
agent: SessionAgent
|
||||
client: Client
|
||||
following: FollowingFeedAPI
|
||||
discover: CustomFeedAPI
|
||||
usingDiscover = false
|
||||
@@ -37,32 +42,32 @@ export class HomeFeedAPI implements FeedAPI {
|
||||
|
||||
constructor({
|
||||
userInterests,
|
||||
agent,
|
||||
client,
|
||||
}: {
|
||||
userInterests?: string
|
||||
agent: SessionAgent
|
||||
client: Client
|
||||
}) {
|
||||
this.agent = agent
|
||||
this.following = new FollowingFeedAPI({agent})
|
||||
this.client = client
|
||||
this.following = new FollowingFeedAPI({client})
|
||||
this.discover = new CustomFeedAPI({
|
||||
agent,
|
||||
feedParams: {feed: PROD_DEFAULT_FEED('whats-hot')},
|
||||
client,
|
||||
feedParams: {feed: PROD_DEFAULT_FEED('whats-hot') as AtUriString},
|
||||
})
|
||||
this.userInterests = userInterests
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.following = new FollowingFeedAPI({agent: this.agent})
|
||||
this.following = new FollowingFeedAPI({client: this.client})
|
||||
this.discover = new CustomFeedAPI({
|
||||
agent: this.agent,
|
||||
feedParams: {feed: PROD_DEFAULT_FEED('whats-hot')},
|
||||
client: this.client,
|
||||
feedParams: {feed: PROD_DEFAULT_FEED('whats-hot') as AtUriString},
|
||||
userInterests: this.userInterests,
|
||||
})
|
||||
this.usingDiscover = false
|
||||
this.itemCursor = 0
|
||||
}
|
||||
|
||||
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
|
||||
async peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost> {
|
||||
if (this.usingDiscover) {
|
||||
return this.discover.peekLatest()
|
||||
}
|
||||
@@ -81,7 +86,7 @@ export class HomeFeedAPI implements FeedAPI {
|
||||
}
|
||||
|
||||
let returnCursor
|
||||
let posts: AppBskyFeedDefs.FeedViewPost[] = []
|
||||
let posts: app.bsky.feed.defs.FeedViewPost[] = []
|
||||
|
||||
if (!this.usingDiscover) {
|
||||
const res = await this.following.fetch({cursor, limit})
|
||||
|
||||
+16
-24
@@ -1,32 +1,29 @@
|
||||
import {
|
||||
type AppBskyFeedDefs,
|
||||
type AppBskyFeedGetActorLikes as GetActorLikes,
|
||||
} from '@atproto/api'
|
||||
import {type Client} from '@atproto/lex-client'
|
||||
|
||||
import {type SessionAgent} from '#/state/session'
|
||||
import {app} from '#/lexicons'
|
||||
import {type FeedAPI, type FeedAPIResponse} from './types'
|
||||
|
||||
export class LikesFeedAPI implements FeedAPI {
|
||||
agent: SessionAgent
|
||||
params: GetActorLikes.QueryParams
|
||||
client: Client
|
||||
params: app.bsky.feed.getActorLikes.$Params
|
||||
|
||||
constructor({
|
||||
agent,
|
||||
client,
|
||||
feedParams,
|
||||
}: {
|
||||
agent: SessionAgent
|
||||
feedParams: GetActorLikes.QueryParams
|
||||
client: Client
|
||||
feedParams: app.bsky.feed.getActorLikes.$Params
|
||||
}) {
|
||||
this.agent = agent
|
||||
this.client = client
|
||||
this.params = feedParams
|
||||
}
|
||||
|
||||
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
|
||||
const res = await this.agent.getActorLikes({
|
||||
async peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost> {
|
||||
const res = await this.client.call(app.bsky.feed.getActorLikes, {
|
||||
...this.params,
|
||||
limit: 1,
|
||||
})
|
||||
return res.data.feed[0]
|
||||
return res.feed[0]
|
||||
}
|
||||
|
||||
async fetch({
|
||||
@@ -36,21 +33,16 @@ export class LikesFeedAPI implements FeedAPI {
|
||||
cursor: string | undefined
|
||||
limit: number
|
||||
}): Promise<FeedAPIResponse> {
|
||||
const res = await this.agent.getActorLikes({
|
||||
const res = await this.client.call(app.bsky.feed.getActorLikes, {
|
||||
...this.params,
|
||||
cursor,
|
||||
limit,
|
||||
})
|
||||
if (res.success) {
|
||||
// HACKFIX: the API incorrectly returns a cursor when there are no items -sfn
|
||||
const isEmptyPage = res.data.feed.length === 0
|
||||
return {
|
||||
cursor: isEmptyPage ? undefined : res.data.cursor,
|
||||
feed: res.data.feed,
|
||||
}
|
||||
}
|
||||
// HACKFIX: the API incorrectly returns a cursor when there are no items -sfn
|
||||
const isEmptyPage = res.feed.length === 0
|
||||
return {
|
||||
feed: [],
|
||||
cursor: isEmptyPage ? undefined : res.cursor,
|
||||
feed: res.feed,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+14
-22
@@ -1,32 +1,29 @@
|
||||
import {
|
||||
type Agent,
|
||||
type AppBskyFeedDefs,
|
||||
type AppBskyFeedGetListFeed as GetListFeed,
|
||||
} from '@atproto/api'
|
||||
import {type Client} from '@atproto/lex-client'
|
||||
|
||||
import {app} from '#/lexicons'
|
||||
import {type FeedAPI, type FeedAPIResponse} from './types'
|
||||
|
||||
export class ListFeedAPI implements FeedAPI {
|
||||
agent: Agent
|
||||
params: GetListFeed.QueryParams
|
||||
client: Client
|
||||
params: app.bsky.feed.getListFeed.$Params
|
||||
|
||||
constructor({
|
||||
agent,
|
||||
client,
|
||||
feedParams,
|
||||
}: {
|
||||
agent: Agent
|
||||
feedParams: GetListFeed.QueryParams
|
||||
client: Client
|
||||
feedParams: app.bsky.feed.getListFeed.$Params
|
||||
}) {
|
||||
this.agent = agent
|
||||
this.client = client
|
||||
this.params = feedParams
|
||||
}
|
||||
|
||||
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
|
||||
const res = await this.agent.app.bsky.feed.getListFeed({
|
||||
async peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost> {
|
||||
const res = await this.client.call(app.bsky.feed.getListFeed, {
|
||||
...this.params,
|
||||
limit: 1,
|
||||
})
|
||||
return res.data.feed[0]
|
||||
return res.feed[0]
|
||||
}
|
||||
|
||||
async fetch({
|
||||
@@ -36,19 +33,14 @@ export class ListFeedAPI implements FeedAPI {
|
||||
cursor: string | undefined
|
||||
limit: number
|
||||
}): Promise<FeedAPIResponse> {
|
||||
const res = await this.agent.app.bsky.feed.getListFeed({
|
||||
const res = await this.client.call(app.bsky.feed.getListFeed, {
|
||||
...this.params,
|
||||
cursor,
|
||||
limit,
|
||||
})
|
||||
if (res.success) {
|
||||
return {
|
||||
cursor: res.data.cursor,
|
||||
feed: res.data.feed,
|
||||
}
|
||||
}
|
||||
return {
|
||||
feed: [],
|
||||
cursor: res.cursor,
|
||||
feed: res.feed,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+70
-44
@@ -1,4 +1,5 @@
|
||||
import {type AppBskyFeedDefs, type AppBskyFeedGetTimeline} from '@atproto/api'
|
||||
import {type Client} from '@atproto/lex-client'
|
||||
import {type AtUriString} from '@atproto/syntax'
|
||||
import shuffle from 'lodash.shuffle'
|
||||
|
||||
import {bundleAsync} from '#/lib/async/bundle'
|
||||
@@ -6,7 +7,8 @@ import {timeout} from '#/lib/async/timeout'
|
||||
import {feedUriToHref} from '#/lib/strings/url-helpers'
|
||||
import {getContentLanguages} from '#/state/preferences/languages'
|
||||
import {type FeedParams} from '#/state/queries/post-feed'
|
||||
import {type SessionAgent} from '#/state/session'
|
||||
import {app} from '#/lexicons'
|
||||
import {toLex} from '#/types/bsky'
|
||||
import {FeedTuner} from '../feed-manip'
|
||||
import {type FeedTunerFn} from '../feed-manip'
|
||||
import {
|
||||
@@ -19,9 +21,21 @@ import {createBskyTopicsHeader, isBlueskyOwnedFeed} from './utils'
|
||||
const REQUEST_WAIT_MS = 500 // 500ms
|
||||
const POST_AGE_CUTOFF = 60e3 * 60 * 24 // 24hours
|
||||
|
||||
/**
|
||||
* Internal result shape for a single feed page fetch. Lex `client.call`
|
||||
* returns the response body directly (throwing on error), so we no longer
|
||||
* carry the old `{success, headers, data}` wrapper - `success` here just
|
||||
* distinguishes an empty/errored fetch from a populated one.
|
||||
*/
|
||||
type FeedPage = {
|
||||
success: boolean
|
||||
cursor?: string
|
||||
feed: app.bsky.feed.defs.FeedViewPost[]
|
||||
}
|
||||
|
||||
export class MergeFeedAPI implements FeedAPI {
|
||||
userInterests?: string
|
||||
agent: SessionAgent
|
||||
client: Client
|
||||
params: FeedParams
|
||||
feedTuners: FeedTunerFn[]
|
||||
following: MergeFeedSource_Following
|
||||
@@ -31,29 +45,29 @@ export class MergeFeedAPI implements FeedAPI {
|
||||
sampleCursor = 0
|
||||
|
||||
constructor({
|
||||
agent,
|
||||
client,
|
||||
feedParams,
|
||||
feedTuners,
|
||||
userInterests,
|
||||
}: {
|
||||
agent: SessionAgent
|
||||
client: Client
|
||||
feedParams: FeedParams
|
||||
feedTuners: FeedTunerFn[]
|
||||
userInterests?: string
|
||||
}) {
|
||||
this.agent = agent
|
||||
this.client = client
|
||||
this.params = feedParams
|
||||
this.feedTuners = feedTuners
|
||||
this.userInterests = userInterests
|
||||
this.following = new MergeFeedSource_Following({
|
||||
agent: this.agent,
|
||||
client: this.client,
|
||||
feedTuners: this.feedTuners,
|
||||
})
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.following = new MergeFeedSource_Following({
|
||||
agent: this.agent,
|
||||
client: this.client,
|
||||
feedTuners: this.feedTuners,
|
||||
})
|
||||
this.customFeeds = []
|
||||
@@ -65,7 +79,7 @@ export class MergeFeedAPI implements FeedAPI {
|
||||
this.params.mergeFeedSources.map(
|
||||
feedUri =>
|
||||
new MergeFeedSource_Custom({
|
||||
agent: this.agent,
|
||||
client: this.client,
|
||||
feedUri,
|
||||
feedTuners: this.feedTuners,
|
||||
userInterests: this.userInterests,
|
||||
@@ -77,11 +91,11 @@ export class MergeFeedAPI implements FeedAPI {
|
||||
}
|
||||
}
|
||||
|
||||
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
|
||||
const res = await this.agent.getTimeline({
|
||||
async peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost> {
|
||||
const res = await this.client.call(app.bsky.feed.getTimeline, {
|
||||
limit: 1,
|
||||
})
|
||||
return res.data.feed[0]
|
||||
return res.feed[0]
|
||||
}
|
||||
|
||||
async fetch({
|
||||
@@ -124,7 +138,7 @@ export class MergeFeedAPI implements FeedAPI {
|
||||
await Promise.all(promises)
|
||||
|
||||
// assemble a response by sampling from feeds with content
|
||||
const posts: AppBskyFeedDefs.FeedViewPost[] = []
|
||||
const posts: app.bsky.feed.defs.FeedViewPost[] = []
|
||||
while (posts.length < limit) {
|
||||
let slice = this.sampleItem()
|
||||
if (slice[0]) {
|
||||
@@ -172,21 +186,21 @@ export class MergeFeedAPI implements FeedAPI {
|
||||
}
|
||||
|
||||
class MergeFeedSource {
|
||||
agent: SessionAgent
|
||||
client: Client
|
||||
feedTuners: FeedTunerFn[]
|
||||
sourceInfo: ReasonFeedSource | undefined
|
||||
cursor: string | undefined = undefined
|
||||
queue: AppBskyFeedDefs.FeedViewPost[] = []
|
||||
queue: app.bsky.feed.defs.FeedViewPost[] = []
|
||||
hasMore = true
|
||||
|
||||
constructor({
|
||||
agent,
|
||||
client,
|
||||
feedTuners,
|
||||
}: {
|
||||
agent: SessionAgent
|
||||
client: Client
|
||||
feedTuners: FeedTunerFn[]
|
||||
}) {
|
||||
this.agent = agent
|
||||
this.client = client
|
||||
this.feedTuners = feedTuners
|
||||
}
|
||||
|
||||
@@ -198,7 +212,7 @@ class MergeFeedSource {
|
||||
return this.hasMore && this.queue.length === 0
|
||||
}
|
||||
|
||||
take(n: number): AppBskyFeedDefs.FeedViewPost[] {
|
||||
take(n: number): app.bsky.feed.defs.FeedViewPost[] {
|
||||
return this.queue.splice(0, n)
|
||||
}
|
||||
|
||||
@@ -209,9 +223,9 @@ class MergeFeedSource {
|
||||
_fetchNextInner = bundleAsync(async (n: number) => {
|
||||
const res = await this._getFeed(this.cursor, n)
|
||||
if (res.success) {
|
||||
this.cursor = res.data.cursor
|
||||
if (res.data.feed.length) {
|
||||
this.queue = this.queue.concat(res.data.feed)
|
||||
this.cursor = res.cursor
|
||||
if (res.feed.length) {
|
||||
this.queue = this.queue.concat(res.feed)
|
||||
} else {
|
||||
this.hasMore = false
|
||||
}
|
||||
@@ -223,7 +237,7 @@ class MergeFeedSource {
|
||||
protected _getFeed(
|
||||
_cursor: string | undefined,
|
||||
_limit: number,
|
||||
): Promise<AppBskyFeedGetTimeline.Response> {
|
||||
): Promise<FeedPage> {
|
||||
throw new Error('Must be overridden')
|
||||
}
|
||||
}
|
||||
@@ -238,39 +252,51 @@ class MergeFeedSource_Following extends MergeFeedSource {
|
||||
protected async _getFeed(
|
||||
cursor: string | undefined,
|
||||
limit: number,
|
||||
): Promise<AppBskyFeedGetTimeline.Response> {
|
||||
const res = await this.agent.getTimeline({cursor, limit})
|
||||
): Promise<FeedPage> {
|
||||
const res = await this.client.call(app.bsky.feed.getTimeline, {
|
||||
cursor,
|
||||
limit,
|
||||
})
|
||||
// run the tuner pre-emptively to ensure better mixing
|
||||
const slices = this.tuner.tune(res.data.feed, {
|
||||
const slices = this.tuner.tune(res.feed, {
|
||||
dryRun: false,
|
||||
})
|
||||
res.data.feed = slices.map(slice => slice._feedPost)
|
||||
return res
|
||||
return {
|
||||
success: true,
|
||||
cursor: res.cursor,
|
||||
/*
|
||||
* TODO(phase4): drop the toLex once `#/lib/api/feed-manip` (FeedTuner)
|
||||
* flips its FeedViewPost source from `@atproto/api` to `#/lexicons`. Its
|
||||
* `_feedPost` is still the old-world view type, which does not assign to
|
||||
* the branded lexicon type this page carries.
|
||||
*/
|
||||
feed: slices.map(slice => toLex(slice._feedPost)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MergeFeedSource_Custom extends MergeFeedSource {
|
||||
agent: SessionAgent
|
||||
client: Client
|
||||
minDate: Date
|
||||
feedUri: string
|
||||
userInterests?: string
|
||||
|
||||
constructor({
|
||||
agent,
|
||||
client,
|
||||
feedUri,
|
||||
feedTuners,
|
||||
userInterests,
|
||||
}: {
|
||||
agent: SessionAgent
|
||||
client: Client
|
||||
feedUri: string
|
||||
feedTuners: FeedTunerFn[]
|
||||
userInterests?: string
|
||||
}) {
|
||||
super({
|
||||
agent,
|
||||
client,
|
||||
feedTuners,
|
||||
})
|
||||
this.agent = agent
|
||||
this.client = client
|
||||
this.feedUri = feedUri
|
||||
this.userInterests = userInterests
|
||||
this.sourceInfo = {
|
||||
@@ -284,15 +310,16 @@ class MergeFeedSource_Custom extends MergeFeedSource {
|
||||
protected async _getFeed(
|
||||
cursor: string | undefined,
|
||||
limit: number,
|
||||
): Promise<AppBskyFeedGetTimeline.Response> {
|
||||
): Promise<FeedPage> {
|
||||
try {
|
||||
const contentLangs = getContentLanguages().join(',')
|
||||
const isBlueskyOwned = isBlueskyOwnedFeed(this.feedUri)
|
||||
const res = await this.agent.app.bsky.feed.getFeed(
|
||||
const res = await this.client.call(
|
||||
app.bsky.feed.getFeed,
|
||||
{
|
||||
cursor,
|
||||
limit,
|
||||
feed: this.feedUri,
|
||||
feed: this.feedUri as AtUriString,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
@@ -303,26 +330,25 @@ class MergeFeedSource_Custom extends MergeFeedSource {
|
||||
},
|
||||
},
|
||||
)
|
||||
let feed = res.feed
|
||||
// NOTE
|
||||
// some custom feeds fail to enforce the pagination limit
|
||||
// so we manually truncate here
|
||||
// -prf
|
||||
if (limit && res.data.feed.length > limit) {
|
||||
res.data.feed = res.data.feed.slice(0, limit)
|
||||
if (limit && feed.length > limit) {
|
||||
feed = feed.slice(0, limit)
|
||||
}
|
||||
// filter out older posts
|
||||
res.data.feed = res.data.feed.filter(
|
||||
post => new Date(post.post.indexedAt) > this.minDate,
|
||||
)
|
||||
feed = feed.filter(post => new Date(post.post.indexedAt) > this.minDate)
|
||||
// attach source info
|
||||
for (const post of res.data.feed) {
|
||||
for (const post of feed) {
|
||||
// @ts-ignore
|
||||
post.__source = this.sourceInfo
|
||||
}
|
||||
return res
|
||||
return {success: true, cursor: res.cursor, feed}
|
||||
} catch {
|
||||
// dont bubble custom-feed errors
|
||||
return {success: false, headers: {}, data: {feed: []}}
|
||||
return {success: false, feed: []}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
-21
@@ -1,25 +1,22 @@
|
||||
import {
|
||||
type Agent,
|
||||
type AppBskyFeedDefs,
|
||||
type AppBskyFeedGetPosts,
|
||||
} from '@atproto/api'
|
||||
import {type Client} from '@atproto/lex-client'
|
||||
|
||||
import {logger} from '#/logger'
|
||||
import {app} from '#/lexicons'
|
||||
import {type FeedAPI, type FeedAPIResponse} from './types'
|
||||
|
||||
export class PostListFeedAPI implements FeedAPI {
|
||||
agent: Agent
|
||||
params: AppBskyFeedGetPosts.QueryParams
|
||||
peek: AppBskyFeedDefs.FeedViewPost | null = null
|
||||
client: Client
|
||||
params: app.bsky.feed.getPosts.$Params
|
||||
peek: app.bsky.feed.defs.FeedViewPost | null = null
|
||||
|
||||
constructor({
|
||||
agent,
|
||||
client,
|
||||
feedParams,
|
||||
}: {
|
||||
agent: Agent
|
||||
feedParams: AppBskyFeedGetPosts.QueryParams
|
||||
client: Client
|
||||
feedParams: app.bsky.feed.getPosts.$Params
|
||||
}) {
|
||||
this.agent = agent
|
||||
this.client = client
|
||||
if (feedParams.uris.length > 25) {
|
||||
logger.warn(
|
||||
`Too many URIs provided - expected 25, got ${feedParams.uris.length}`,
|
||||
@@ -30,23 +27,18 @@ export class PostListFeedAPI implements FeedAPI {
|
||||
}
|
||||
}
|
||||
|
||||
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
|
||||
async peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost> {
|
||||
if (this.peek) return this.peek
|
||||
throw new Error('Has not fetched yet')
|
||||
}
|
||||
|
||||
async fetch({}: {}): Promise<FeedAPIResponse> {
|
||||
const res = await this.agent.app.bsky.feed.getPosts({
|
||||
const res = await this.client.call(app.bsky.feed.getPosts, {
|
||||
...this.params,
|
||||
})
|
||||
if (res.success) {
|
||||
this.peek = {post: res.data.posts[0]}
|
||||
return {
|
||||
feed: res.data.posts.map(post => ({post})),
|
||||
}
|
||||
}
|
||||
this.peek = {post: res.posts[0]}
|
||||
return {
|
||||
feed: [],
|
||||
feed: res.posts.map(post => ({post})),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import {type AppBskyFeedDefs} from '@atproto/api'
|
||||
import {type app} from '#/lexicons'
|
||||
|
||||
export interface FeedAPIResponse {
|
||||
cursor?: string
|
||||
feed: AppBskyFeedDefs.FeedViewPost[]
|
||||
feed: app.bsky.feed.defs.FeedViewPost[]
|
||||
}
|
||||
|
||||
export interface FeedAPI {
|
||||
peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost>
|
||||
peekLatest(): Promise<app.bsky.feed.defs.FeedViewPost>
|
||||
fetch({
|
||||
cursor,
|
||||
limit,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {AtUri} from '@atproto/api'
|
||||
import {AtUri} from '@atproto/syntax'
|
||||
|
||||
import {BSKY_FEED_OWNER_DIDS} from '#/lib/constants'
|
||||
import {type UsePreferencesQueryResponse} from '#/state/queries/preferences'
|
||||
|
||||
+129
-190
@@ -1,25 +1,14 @@
|
||||
import {
|
||||
type $Typed,
|
||||
type AppBskyEmbedExternal,
|
||||
type AppBskyEmbedGallery,
|
||||
type AppBskyEmbedImages,
|
||||
type AppBskyEmbedRecord,
|
||||
type AppBskyEmbedRecordWithMedia,
|
||||
type AppBskyEmbedVideo,
|
||||
AppBskyFeedPost,
|
||||
BlobRef,
|
||||
ChatBskyGroupDefs,
|
||||
type ComAtprotoLabelDefs,
|
||||
type ComAtprotoRepoApplyWrites,
|
||||
type ComAtprotoRepoStrongRef,
|
||||
RichText,
|
||||
} from '@atproto/api'
|
||||
import {TID} from '@atproto/common-web'
|
||||
import {type $Typed} from '@atproto/lex'
|
||||
import {type Client} from '@atproto/lex-client'
|
||||
import {
|
||||
type AtUriString,
|
||||
toDatetimeString,
|
||||
type UriString,
|
||||
} from '@atproto/syntax'
|
||||
import {RichText} from '@bsky.app/sdk/richtext'
|
||||
import {t} from '@lingui/core/macro'
|
||||
import {type QueryClient} from '@tanstack/react-query'
|
||||
import {sha256} from 'js-sha256'
|
||||
import {CID} from 'multiformats/cid'
|
||||
import * as Hasher from 'multiformats/hashes/hasher'
|
||||
|
||||
import {IMAGE_SIZE_CONFIG_POSTS} from '#/lib/constants'
|
||||
import {isNetworkError} from '#/lib/strings/errors'
|
||||
@@ -34,18 +23,33 @@ import {
|
||||
createThreadgateRecord,
|
||||
threadgateAllowUISettingToAllowRecordValue,
|
||||
} from '#/state/queries/threadgate'
|
||||
import {type SessionAgent} from '#/state/session'
|
||||
import {
|
||||
type EmbedDraft,
|
||||
type PostDraft,
|
||||
type ThreadDraft,
|
||||
} from '#/view/com/composer/state/composer'
|
||||
import {app, chat, com} from '#/lexicons'
|
||||
import * as bsky from '#/types/bsky'
|
||||
import {createGIFDescription} from '../gif-alt-text'
|
||||
import {computeCid} from './computeCid'
|
||||
import {type ResolveClients} from './resolve'
|
||||
import {uploadBlob} from './upload-blob'
|
||||
|
||||
export {uploadBlob}
|
||||
|
||||
/**
|
||||
* The lex clients the post pipeline needs. `pdsClient` handles writes to the
|
||||
* user's repo (applyWrites, uploadBlob) - proxied to their PDS, never the
|
||||
* appview. `appviewClient` handles the `app.bsky.*` reads (getPosts, when
|
||||
* resolving a reply's root). `resolveClients` is threaded to the link/gif
|
||||
* resolvers, which need the appview + chat + bridge agent (design section H).
|
||||
*/
|
||||
export type PostClients = {
|
||||
pdsClient: Client
|
||||
appviewClient: Client
|
||||
resolveClients: ResolveClients
|
||||
}
|
||||
|
||||
interface PostOpts {
|
||||
thread: ThreadDraft
|
||||
replyTo?: string
|
||||
@@ -54,20 +58,21 @@ interface PostOpts {
|
||||
}
|
||||
|
||||
export async function post(
|
||||
agent: SessionAgent,
|
||||
clients: PostClients,
|
||||
queryClient: QueryClient,
|
||||
opts: PostOpts,
|
||||
) {
|
||||
const {pdsClient, appviewClient, resolveClients} = clients
|
||||
const thread = opts.thread
|
||||
opts.onStateChange?.(t`Processing...`)
|
||||
|
||||
let replyPromise:
|
||||
| Promise<AppBskyFeedPost.Record['reply']>
|
||||
| AppBskyFeedPost.Record['reply']
|
||||
| Promise<app.bsky.feed.post.Main['reply']>
|
||||
| app.bsky.feed.post.Main['reply']
|
||||
| undefined
|
||||
if (opts.replyTo) {
|
||||
// Not awaited to avoid waterfalls.
|
||||
replyPromise = resolveReply(agent, opts.replyTo)
|
||||
replyPromise = resolveReply(appviewClient, opts.replyTo)
|
||||
}
|
||||
|
||||
// add top 3 languages from user preferences if langs is provided
|
||||
@@ -76,8 +81,8 @@ export async function post(
|
||||
langs = opts.langs.slice(0, 3)
|
||||
}
|
||||
|
||||
const did = agent.assertDid
|
||||
const writes: $Typed<ComAtprotoRepoApplyWrites.Create>[] = []
|
||||
const did = pdsClient.assertDid
|
||||
const writes: com.atproto.repo.applyWrites.$InputBody['writes'] = []
|
||||
const uris: string[] = []
|
||||
|
||||
let now = new Date()
|
||||
@@ -86,15 +91,23 @@ export async function post(
|
||||
for (let i = 0; i < thread.posts.length; i++) {
|
||||
const draft = thread.posts[i]
|
||||
|
||||
// Not awaited to avoid waterfalls.
|
||||
const rtPromise = resolveRT(agent, draft.richtext)
|
||||
/*
|
||||
* Not awaited to avoid waterfalls. `draft.richtext` is still an
|
||||
* `@atproto/api` RichText (composer state is migrated by Task 7); the SDK
|
||||
* RichText is structurally the same transplant, so bridge it here.
|
||||
* TODO(phase4): drop toLex once composer state migrates to SDK RichText.
|
||||
*/
|
||||
const rtPromise = resolveRT(
|
||||
resolveClients.appview,
|
||||
bsky.toLex<RichText>(draft.richtext),
|
||||
)
|
||||
const embedPromise = resolveEmbed(
|
||||
agent,
|
||||
clients,
|
||||
queryClient,
|
||||
draft,
|
||||
opts.onStateChange,
|
||||
)
|
||||
let labels: $Typed<ComAtprotoLabelDefs.SelfLabels> | undefined
|
||||
let labels: $Typed<com.atproto.label.defs.SelfLabels> | undefined
|
||||
if (draft.labels.length) {
|
||||
labels = {
|
||||
$type: 'com.atproto.label.defs#selfLabels',
|
||||
@@ -107,17 +120,17 @@ export async function post(
|
||||
now.setMilliseconds(now.getMilliseconds() + 1)
|
||||
tid = TID.next(tid)
|
||||
const rkey = tid.toString()
|
||||
const uri = `at://${did}/app.bsky.feed.post/${rkey}`
|
||||
const uri = `at://${did}/app.bsky.feed.post/${rkey}` as AtUriString
|
||||
uris.push(uri)
|
||||
|
||||
const rt = await rtPromise
|
||||
const embed = await embedPromise
|
||||
const reply = await replyPromise
|
||||
const record: AppBskyFeedPost.Record = {
|
||||
const record: app.bsky.feed.post.Main = {
|
||||
// IMPORTANT: $type has to exist, CID is calculated with the `$type` field
|
||||
// present and will produce the wrong CID if you omit it.
|
||||
$type: 'app.bsky.feed.post',
|
||||
createdAt: now.toISOString(),
|
||||
createdAt: toDatetimeString(now),
|
||||
text: rt.text,
|
||||
facets: rt.facets,
|
||||
reply,
|
||||
@@ -125,11 +138,17 @@ export async function post(
|
||||
langs,
|
||||
labels,
|
||||
}
|
||||
/*
|
||||
* `value` is typed `LexMap` (a loose index-signature map). A generated
|
||||
* record type is a valid LexMap at runtime but a strict interface is not
|
||||
* assignable to an index-signature type, so widen with `toLex` at this
|
||||
* boundary. Not a brand cast - the record is already fully typed.
|
||||
*/
|
||||
writes.push({
|
||||
$type: 'com.atproto.repo.applyWrites#create',
|
||||
collection: 'app.bsky.feed.post',
|
||||
rkey: rkey,
|
||||
value: record,
|
||||
value: bsky.toLex(record),
|
||||
})
|
||||
|
||||
if (i === 0 && thread.threadgate.some(tg => tg.type !== 'everybody')) {
|
||||
@@ -137,11 +156,14 @@ export async function post(
|
||||
$type: 'com.atproto.repo.applyWrites#create',
|
||||
collection: 'app.bsky.feed.threadgate',
|
||||
rkey: rkey,
|
||||
value: createThreadgateRecord({
|
||||
createdAt: now.toISOString(),
|
||||
post: uri,
|
||||
allow: threadgateAllowUISettingToAllowRecordValue(thread.threadgate),
|
||||
}),
|
||||
value: bsky.toLex(
|
||||
createThreadgateRecord({
|
||||
post: uri,
|
||||
allow: threadgateAllowUISettingToAllowRecordValue(
|
||||
thread.threadgate,
|
||||
),
|
||||
}),
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -153,12 +175,12 @@ export async function post(
|
||||
$type: 'com.atproto.repo.applyWrites#create',
|
||||
collection: 'app.bsky.feed.postgate',
|
||||
rkey: rkey,
|
||||
value: {
|
||||
value: bsky.toLex({
|
||||
...thread.postgate,
|
||||
$type: 'app.bsky.feed.postgate',
|
||||
createdAt: now.toISOString(),
|
||||
post: uri,
|
||||
},
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -174,8 +196,8 @@ export async function post(
|
||||
}
|
||||
|
||||
try {
|
||||
await agent.com.atproto.repo.applyWrites({
|
||||
repo: agent.assertDid,
|
||||
await pdsClient.call(com.atproto.repo.applyWrites, {
|
||||
repo: did,
|
||||
writes: writes,
|
||||
validate: true,
|
||||
})
|
||||
@@ -196,14 +218,18 @@ export async function post(
|
||||
return {uris}
|
||||
}
|
||||
|
||||
async function resolveRT(agent: SessionAgent, richtext: RichText) {
|
||||
async function resolveRT(appviewClient: Client, richtext: RichText) {
|
||||
const trimmedText = richtext.text
|
||||
// Trim leading whitespace-only lines (but don't break ASCII art).
|
||||
.replace(/^(\s*\n)+/, '')
|
||||
// Trim any trailing whitespace.
|
||||
.trimEnd()
|
||||
let rt = new RichText({text: trimmedText}, {cleanNewlines: true})
|
||||
await rt.detectFacets(agent)
|
||||
/*
|
||||
* Facet detection resolves handles via `com.atproto.identity.resolveHandle`,
|
||||
* which the appview client serves (design section B).
|
||||
*/
|
||||
await rt.detectFacets(appviewClient)
|
||||
|
||||
rt = shortenLinks(rt)
|
||||
rt = stripInvalidMentions(rt)
|
||||
@@ -216,9 +242,9 @@ export class ReplyDeletedError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
async function resolveReply(agent: SessionAgent, replyTo: string) {
|
||||
const {data} = await agent.app.bsky.feed.getPosts({
|
||||
uris: [replyTo],
|
||||
async function resolveReply(appviewClient: Client, replyTo: string) {
|
||||
const data = await appviewClient.call(app.bsky.feed.getPosts, {
|
||||
uris: [replyTo as AtUriString],
|
||||
})
|
||||
const parentPost = data.posts[0]
|
||||
if (!parentPost) {
|
||||
@@ -229,14 +255,9 @@ async function resolveReply(agent: SessionAgent, replyTo: string) {
|
||||
uri: parentPost.uri,
|
||||
cid: parentPost.cid,
|
||||
}
|
||||
let rootRef = parentRef
|
||||
let rootRef: com.atproto.repo.strongRef.Main = parentRef
|
||||
|
||||
if (
|
||||
bsky.dangerousIsType<AppBskyFeedPost.Record>(
|
||||
parentPost.record,
|
||||
AppBskyFeedPost.isRecord,
|
||||
)
|
||||
) {
|
||||
if (bsky.isType(app.bsky.feed.post, parentPost.record)) {
|
||||
if (parentPost.record.reply) {
|
||||
rootRef = parentPost.record.reply.root
|
||||
}
|
||||
@@ -249,23 +270,15 @@ async function resolveReply(agent: SessionAgent, replyTo: string) {
|
||||
}
|
||||
|
||||
async function resolveEmbed(
|
||||
agent: SessionAgent,
|
||||
clients: PostClients,
|
||||
queryClient: QueryClient,
|
||||
draft: PostDraft,
|
||||
onStateChange: ((state: string) => void) | undefined,
|
||||
): Promise<
|
||||
| $Typed<AppBskyEmbedImages.Main>
|
||||
| $Typed<AppBskyEmbedGallery.Main>
|
||||
| $Typed<AppBskyEmbedVideo.Main>
|
||||
| $Typed<AppBskyEmbedExternal.Main>
|
||||
| $Typed<AppBskyEmbedRecord.Main>
|
||||
| $Typed<AppBskyEmbedRecordWithMedia.Main>
|
||||
| undefined
|
||||
> {
|
||||
): Promise<app.bsky.feed.post.Main['embed']> {
|
||||
if (draft.embed.quote) {
|
||||
const [resolvedMedia, resolvedQuote] = await Promise.all([
|
||||
resolveMedia(agent, queryClient, draft.embed, onStateChange),
|
||||
resolveRecord(agent, queryClient, draft.embed.quote.uri),
|
||||
resolveMedia(clients, queryClient, draft.embed, onStateChange),
|
||||
resolveRecord(clients, queryClient, draft.embed.quote.uri),
|
||||
])
|
||||
if (resolvedMedia) {
|
||||
return {
|
||||
@@ -283,7 +296,7 @@ async function resolveEmbed(
|
||||
}
|
||||
}
|
||||
const resolvedMedia = await resolveMedia(
|
||||
agent,
|
||||
clients,
|
||||
queryClient,
|
||||
draft.embed,
|
||||
onStateChange,
|
||||
@@ -294,7 +307,7 @@ async function resolveEmbed(
|
||||
if (draft.embed.link) {
|
||||
const resolvedLink = await fetchResolveLinkQuery(
|
||||
queryClient,
|
||||
agent,
|
||||
clients.resolveClients,
|
||||
draft.embed.link.uri,
|
||||
)
|
||||
if (resolvedLink.type === 'record') {
|
||||
@@ -308,24 +321,25 @@ async function resolveEmbed(
|
||||
}
|
||||
|
||||
async function resolveMedia(
|
||||
agent: SessionAgent,
|
||||
clients: PostClients,
|
||||
queryClient: QueryClient,
|
||||
embedDraft: EmbedDraft,
|
||||
onStateChange: ((state: string) => void) | undefined,
|
||||
): Promise<
|
||||
| $Typed<AppBskyEmbedExternal.Main>
|
||||
| $Typed<AppBskyEmbedImages.Main>
|
||||
| $Typed<AppBskyEmbedGallery.Main>
|
||||
| $Typed<AppBskyEmbedVideo.Main>
|
||||
| $Typed<app.bsky.embed.external.Main>
|
||||
| $Typed<app.bsky.embed.images.Main>
|
||||
| $Typed<app.bsky.embed.gallery.Main>
|
||||
| $Typed<app.bsky.embed.video.Main>
|
||||
| undefined
|
||||
> {
|
||||
const {pdsClient, resolveClients} = clients
|
||||
if (embedDraft.media?.type === 'images') {
|
||||
const imagesDraft = embedDraft.media.images
|
||||
logger.debug(`Uploading images`, {
|
||||
count: imagesDraft.length,
|
||||
})
|
||||
onStateChange?.(t`Uploading images...`)
|
||||
const images: AppBskyEmbedImages.Image[] = await Promise.all(
|
||||
const images: app.bsky.embed.images.Image[] = await Promise.all(
|
||||
imagesDraft.map(async (image, i) => {
|
||||
logger.debug(`Compressing image #${i}`)
|
||||
const {path, width, height, mime} = await compressImage(
|
||||
@@ -333,9 +347,9 @@ async function resolveMedia(
|
||||
IMAGE_SIZE_CONFIG_POSTS,
|
||||
)
|
||||
logger.debug(`Uploading image #${i}`)
|
||||
const res = await uploadBlob(agent, path, mime)
|
||||
const res = await uploadBlob(pdsClient, path, mime)
|
||||
return {
|
||||
image: res.data.blob,
|
||||
image: res.blob,
|
||||
alt: image.alt,
|
||||
aspectRatio: {width, height},
|
||||
}
|
||||
@@ -352,7 +366,7 @@ async function resolveMedia(
|
||||
count: imagesDraft.length,
|
||||
})
|
||||
onStateChange?.(t`Uploading images...`)
|
||||
const items: $Typed<AppBskyEmbedGallery.Image>[] = await Promise.all(
|
||||
const items: $Typed<app.bsky.embed.gallery.Image>[] = await Promise.all(
|
||||
imagesDraft.map(async (image, i) => {
|
||||
logger.debug(`Compressing image #${i}`)
|
||||
const {path, width, height, mime} = await compressImage(
|
||||
@@ -360,10 +374,10 @@ async function resolveMedia(
|
||||
IMAGE_SIZE_CONFIG_POSTS,
|
||||
)
|
||||
logger.debug(`Uploading image #${i}`)
|
||||
const res = await uploadBlob(agent, path, mime)
|
||||
const res = await uploadBlob(pdsClient, path, mime)
|
||||
return {
|
||||
$type: 'app.bsky.embed.gallery#image' as const,
|
||||
image: res.data.blob,
|
||||
image: res.blob,
|
||||
alt: image.alt,
|
||||
aspectRatio: {width, height},
|
||||
}
|
||||
@@ -383,10 +397,10 @@ async function resolveMedia(
|
||||
videoDraft.captions
|
||||
.filter(caption => caption.lang !== '')
|
||||
.map(async caption => {
|
||||
const {data} = await agent.uploadBlob(caption.file, {
|
||||
const res = await pdsClient.uploadBlob(caption.file, {
|
||||
encoding: 'text/vtt',
|
||||
})
|
||||
return {lang: caption.lang, file: data.blob}
|
||||
return {lang: caption.lang, file: res.body.blob}
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -406,7 +420,13 @@ async function resolveMedia(
|
||||
|
||||
return {
|
||||
$type: 'app.bsky.embed.video',
|
||||
video: videoDraft.pendingPublish.blobRef,
|
||||
/*
|
||||
* The video blob is a legacy `@atproto/api` BlobRef from the not-yet
|
||||
* -migrated video pipeline (getJobStatus, in composer state/video). Its
|
||||
* structural shape matches the lexicon blob field; the CID hasher handles
|
||||
* both class instances and plain lex blobs (see computeCid).
|
||||
*/
|
||||
video: bsky.toLex(videoDraft.pendingPublish.blobRef),
|
||||
alt: videoDraft.altText || undefined,
|
||||
captions: captions.length === 0 ? undefined : captions,
|
||||
aspectRatio,
|
||||
@@ -416,22 +436,18 @@ async function resolveMedia(
|
||||
}
|
||||
if (embedDraft.media?.type === 'gif') {
|
||||
const gifDraft = embedDraft.media
|
||||
const resolvedGif = await fetchResolveGifQuery(
|
||||
queryClient,
|
||||
agent,
|
||||
gifDraft.gif,
|
||||
)
|
||||
let blob: BlobRef | undefined
|
||||
const resolvedGif = await fetchResolveGifQuery(queryClient, gifDraft.gif)
|
||||
let blob: app.bsky.embed.external.External['thumb']
|
||||
if (resolvedGif.thumb) {
|
||||
onStateChange?.(t`Uploading link thumbnail...`)
|
||||
const {path, mime} = resolvedGif.thumb.source
|
||||
const response = await uploadBlob(agent, path, mime)
|
||||
blob = response.data.blob
|
||||
const response = await uploadBlob(pdsClient, path, mime)
|
||||
blob = response.blob
|
||||
}
|
||||
return {
|
||||
$type: 'app.bsky.embed.external',
|
||||
external: {
|
||||
uri: resolvedGif.uri,
|
||||
uri: resolvedGif.uri as UriString,
|
||||
title: resolvedGif.title,
|
||||
description: createGIFDescription(resolvedGif.title, gifDraft.alt),
|
||||
thumb: blob,
|
||||
@@ -441,36 +457,42 @@ async function resolveMedia(
|
||||
if (embedDraft.link) {
|
||||
const resolvedLink = await fetchResolveLinkQuery(
|
||||
queryClient,
|
||||
agent,
|
||||
resolveClients,
|
||||
embedDraft.link.uri,
|
||||
)
|
||||
if (resolvedLink.type === 'external') {
|
||||
let blob: BlobRef | undefined
|
||||
let blob: app.bsky.embed.external.External['thumb']
|
||||
if (resolvedLink.thumb) {
|
||||
onStateChange?.(t`Uploading link thumbnail...`)
|
||||
const {path, mime} = resolvedLink.thumb.source
|
||||
const response = await uploadBlob(agent, path, mime)
|
||||
blob = response.data.blob
|
||||
const response = await uploadBlob(pdsClient, path, mime)
|
||||
blob = response.blob
|
||||
}
|
||||
return {
|
||||
$type: 'app.bsky.embed.external',
|
||||
external: {
|
||||
uri: resolvedLink.uri,
|
||||
uri: resolvedLink.uri as UriString,
|
||||
title: resolvedLink.title,
|
||||
description: resolvedLink.description,
|
||||
thumb: blob,
|
||||
associatedRefs: resolvedLink.associatedRefs,
|
||||
/*
|
||||
* associatedRefs comes from getLinkMeta, still typed with the old
|
||||
* `@atproto/api` StrongRef (link-meta.ts is out of scope). The shape
|
||||
* is identical; bridge with toLex.
|
||||
* TODO(phase4): drop toLex once link-meta migrates.
|
||||
*/
|
||||
associatedRefs: bsky.toLex(resolvedLink.associatedRefs),
|
||||
},
|
||||
}
|
||||
}
|
||||
if (
|
||||
resolvedLink.type === 'chat-invite' &&
|
||||
ChatBskyGroupDefs.isJoinLinkPreviewView(resolvedLink.view)
|
||||
bsky.isType(chat.bsky.group.defs.joinLinkPreviewView, resolvedLink.view)
|
||||
) {
|
||||
return {
|
||||
$type: 'app.bsky.embed.external',
|
||||
external: {
|
||||
uri: resolvedLink.uri,
|
||||
uri: resolvedLink.uri as UriString,
|
||||
title: resolvedLink.view.name,
|
||||
description: `${resolvedLink.view.memberCount}/${resolvedLink.view.memberLimit}`,
|
||||
},
|
||||
@@ -481,100 +503,17 @@ async function resolveMedia(
|
||||
}
|
||||
|
||||
async function resolveRecord(
|
||||
agent: SessionAgent,
|
||||
clients: PostClients,
|
||||
queryClient: QueryClient,
|
||||
uri: string,
|
||||
): Promise<ComAtprotoRepoStrongRef.Main> {
|
||||
const resolvedLink = await fetchResolveLinkQuery(queryClient, agent, uri)
|
||||
): Promise<com.atproto.repo.strongRef.Main> {
|
||||
const resolvedLink = await fetchResolveLinkQuery(
|
||||
queryClient,
|
||||
clients.resolveClients,
|
||||
uri,
|
||||
)
|
||||
if (resolvedLink.type !== 'record') {
|
||||
throw Error(t`Expected uri to resolve to a record`)
|
||||
}
|
||||
return resolvedLink.record
|
||||
}
|
||||
|
||||
// The built-in hashing functions from multiformats (`multiformats/hashes/sha2`)
|
||||
// are meant for Node.js, this is the cross-platform equivalent.
|
||||
const mf_sha256 = Hasher.from({
|
||||
name: 'sha2-256',
|
||||
code: 0x12,
|
||||
encode: input => {
|
||||
const digest = sha256.arrayBuffer(input)
|
||||
return new Uint8Array(digest)
|
||||
},
|
||||
})
|
||||
|
||||
async function computeCid(record: AppBskyFeedPost.Record): Promise<string> {
|
||||
/*
|
||||
* Lazily loaded since it's only needed when posting a thread, and its
|
||||
* `cborg` dependency is ~190KB that would otherwise be in the initial
|
||||
* web bundle.
|
||||
*/
|
||||
const dcbor = await import('@ipld/dag-cbor')
|
||||
// IMPORTANT: `prepareObject` prepares the record to be hashed by removing
|
||||
// fields with undefined value, and converting BlobRef instances to the
|
||||
// right IPLD representation.
|
||||
const prepared = prepareForHashing(record)
|
||||
// 1. Encode the record into DAG-CBOR format
|
||||
const encoded = dcbor.encode(prepared)
|
||||
// 2. Hash the record in SHA-256 (code 0x12)
|
||||
const digest = await mf_sha256.digest(encoded)
|
||||
// 3. Create a CIDv1, specifying DAG-CBOR as content (code 0x71)
|
||||
const cid = CID.createV1(0x71, digest)
|
||||
// 4. Get the Base32 representation of the CID (`b` prefix)
|
||||
return cid.toString()
|
||||
}
|
||||
|
||||
// Returns a transformed version of the object for use in DAG-CBOR.
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function prepareForHashing(v: any): any {
|
||||
// IMPORTANT: BlobRef#ipld() returns the correct object we need for hashing,
|
||||
// the API client will convert this for you but we're hashing in the client,
|
||||
// so we need it *now*.
|
||||
if (v instanceof BlobRef) {
|
||||
return v.ipld()
|
||||
}
|
||||
|
||||
// Walk through arrays
|
||||
if (Array.isArray(v)) {
|
||||
let pure = true
|
||||
const mapped = v.map(value => {
|
||||
if (value !== (value = prepareForHashing(value))) {
|
||||
pure = false
|
||||
}
|
||||
return value
|
||||
})
|
||||
return pure ? v : mapped
|
||||
}
|
||||
|
||||
// Walk through plain objects
|
||||
if (isPlainObject(v)) {
|
||||
const obj: Record<string, unknown> = {}
|
||||
let pure = true
|
||||
for (const key in v) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
let value = v[key]
|
||||
// `value` is undefined
|
||||
if (value === undefined) {
|
||||
pure = false
|
||||
continue
|
||||
}
|
||||
// `prepareObject` returned a value that's different from what we had before
|
||||
if (value !== (value = prepareForHashing(value))) {
|
||||
pure = false
|
||||
}
|
||||
obj[key] = value
|
||||
}
|
||||
// Return as is if we haven't needed to tamper with anything
|
||||
return pure ? v : obj
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function isPlainObject(v: any): boolean {
|
||||
if (typeof v !== 'object' || v === null) {
|
||||
return false
|
||||
}
|
||||
const proto = Object.getPrototypeOf(v)
|
||||
return proto === Object.prototype || proto === null
|
||||
}
|
||||
|
||||
+63
-49
@@ -1,11 +1,7 @@
|
||||
import {
|
||||
type AppBskyFeedDefs,
|
||||
type AppBskyGraphDefs,
|
||||
type ComAtprotoRepoStrongRef,
|
||||
} from '@atproto/api'
|
||||
import {AtUri} from '@atproto/api'
|
||||
import {type Client} from '@atproto/lex-client'
|
||||
import {AtUri, type AtUriString, type HandleString} from '@atproto/syntax'
|
||||
|
||||
import {DM_SERVICE_HEADERS, IMAGE_SIZE_CONFIG_2K_1MB} from '#/lib/constants'
|
||||
import {IMAGE_SIZE_CONFIG_2K_1MB} from '#/lib/constants'
|
||||
import {getLinkMeta, type LinkMeta} from '#/lib/link-meta/link-meta'
|
||||
import {resolveShortLink} from '#/lib/link-meta/resolve-short-link'
|
||||
import {downloadAndResize} from '#/lib/media/manip'
|
||||
@@ -29,8 +25,21 @@ import {createComposerImage} from '#/state/gallery'
|
||||
import {type ChatInvitePreview} from '#/state/queries/join-links'
|
||||
import {type SessionAgent} from '#/state/session'
|
||||
import {type Gif} from '#/features/gifPicker/types'
|
||||
import {app, chat, com} from '#/lexicons'
|
||||
import {createGIFDescription} from '../gif-alt-text'
|
||||
|
||||
/**
|
||||
* Clients the link resolver needs. `appview` serves the `app.bsky.*` feed/graph
|
||||
* reads plus handle resolution; `chat` serves the group join-link previews.
|
||||
* `agent` is still threaded through to {@link getLinkMeta}, which has not yet
|
||||
* migrated off the bridge - it only reads the (unused) service URL from it.
|
||||
*/
|
||||
export type ResolveClients = {
|
||||
appview: Client
|
||||
chat: Client
|
||||
agent: SessionAgent
|
||||
}
|
||||
|
||||
type ResolvedExternalLink = {
|
||||
type: 'external'
|
||||
uri: string
|
||||
@@ -47,30 +56,30 @@ type ResolvedExternalLink = {
|
||||
|
||||
type ResolvedPostRecord = {
|
||||
type: 'record'
|
||||
record: ComAtprotoRepoStrongRef.Main
|
||||
record: com.atproto.repo.strongRef.Main
|
||||
kind: 'post'
|
||||
view: AppBskyFeedDefs.PostView
|
||||
view: app.bsky.feed.defs.PostView
|
||||
}
|
||||
|
||||
type ResolvedFeedRecord = {
|
||||
type: 'record'
|
||||
record: ComAtprotoRepoStrongRef.Main
|
||||
record: com.atproto.repo.strongRef.Main
|
||||
kind: 'feed'
|
||||
view: AppBskyFeedDefs.GeneratorView
|
||||
view: app.bsky.feed.defs.GeneratorView
|
||||
}
|
||||
|
||||
type ResolvedListRecord = {
|
||||
type: 'record'
|
||||
record: ComAtprotoRepoStrongRef.Main
|
||||
record: com.atproto.repo.strongRef.Main
|
||||
kind: 'list'
|
||||
view: AppBskyGraphDefs.ListView
|
||||
view: app.bsky.graph.defs.ListView
|
||||
}
|
||||
|
||||
type ResolvedStarterPackRecord = {
|
||||
type: 'record'
|
||||
record: ComAtprotoRepoStrongRef.Main
|
||||
record: com.atproto.repo.strongRef.Main
|
||||
kind: 'starter-pack'
|
||||
view: AppBskyGraphDefs.StarterPackView
|
||||
view: app.bsky.graph.defs.StarterPackView
|
||||
}
|
||||
|
||||
type ResolvedChatInvite = {
|
||||
@@ -95,9 +104,10 @@ export class EmbeddingDisabledError extends Error {
|
||||
}
|
||||
|
||||
export async function resolveLink(
|
||||
agent: SessionAgent,
|
||||
clients: ResolveClients,
|
||||
uri: string,
|
||||
): Promise<ResolvedLink> {
|
||||
const {appview, chat: chatClient} = clients
|
||||
if (isShortLink(uri)) {
|
||||
uri = await resolveShortLink(uri)
|
||||
}
|
||||
@@ -124,15 +134,15 @@ export async function resolveLink(
|
||||
const [_0, handleOrDid, _1, rkey] = uri.split('/').filter(Boolean)
|
||||
const did = await fetchDid(handleOrDid)
|
||||
const feed = makeRecordUri(did, 'app.bsky.feed.generator', rkey)
|
||||
const res = await agent.app.bsky.feed.getFeedGenerator({feed})
|
||||
const {view} = await appview.call(app.bsky.feed.getFeedGenerator, {feed})
|
||||
return {
|
||||
type: 'record',
|
||||
record: {
|
||||
uri: res.data.view.uri,
|
||||
cid: res.data.view.cid,
|
||||
uri: view.uri,
|
||||
cid: view.cid,
|
||||
},
|
||||
kind: 'feed',
|
||||
view: res.data.view,
|
||||
view,
|
||||
}
|
||||
}
|
||||
if (isBskyListUrl(uri)) {
|
||||
@@ -140,28 +150,27 @@ export async function resolveLink(
|
||||
const [_0, handleOrDid, _1, rkey] = uri.split('/').filter(Boolean)
|
||||
const did = await fetchDid(handleOrDid)
|
||||
const list = makeRecordUri(did, 'app.bsky.graph.list', rkey)
|
||||
const res = await agent.app.bsky.graph.getList({list})
|
||||
const res = await appview.call(app.bsky.graph.getList, {list})
|
||||
return {
|
||||
type: 'record',
|
||||
record: {
|
||||
uri: res.data.list.uri,
|
||||
cid: res.data.list.cid,
|
||||
uri: res.list.uri,
|
||||
cid: res.list.cid,
|
||||
},
|
||||
kind: 'list',
|
||||
view: res.data.list,
|
||||
view: res.list,
|
||||
}
|
||||
}
|
||||
const chatInviteCode = getChatInviteCodeFromUrl(uri)
|
||||
if (chatInviteCode) {
|
||||
const res = await agent.chat.bsky.group.getJoinLinkPreviews(
|
||||
{codes: [chatInviteCode]},
|
||||
{headers: DM_SERVICE_HEADERS},
|
||||
)
|
||||
const res = await chatClient.call(chat.bsky.group.getJoinLinkPreviews, {
|
||||
codes: [chatInviteCode],
|
||||
})
|
||||
return {
|
||||
type: 'chat-invite',
|
||||
uri,
|
||||
code: chatInviteCode,
|
||||
view: res.data.joinLinkPreviews[0],
|
||||
view: res.joinLinkPreviews[0],
|
||||
}
|
||||
}
|
||||
if (isBskyStartUrl(uri) || isBskyStarterPackUrl(uri)) {
|
||||
@@ -173,34 +182,35 @@ export async function resolveLink(
|
||||
}
|
||||
const did = await fetchDid(parsed.name)
|
||||
const starterPack = createStarterPackUri({did, rkey: parsed.rkey})
|
||||
const res = await agent.app.bsky.graph.getStarterPack({starterPack})
|
||||
const res = await appview.call(app.bsky.graph.getStarterPack, {
|
||||
starterPack: starterPack as AtUriString,
|
||||
})
|
||||
return {
|
||||
type: 'record',
|
||||
record: {
|
||||
uri: res.data.starterPack.uri,
|
||||
cid: res.data.starterPack.cid,
|
||||
uri: res.starterPack.uri,
|
||||
cid: res.starterPack.cid,
|
||||
},
|
||||
kind: 'starter-pack',
|
||||
view: res.data.starterPack,
|
||||
view: res.starterPack,
|
||||
}
|
||||
}
|
||||
return resolveExternal(agent, uri)
|
||||
return resolveExternal(clients, uri)
|
||||
|
||||
// Forked from useGetPost. TODO: move into RQ.
|
||||
async function getPost({uri}: {uri: string}) {
|
||||
const urip = new AtUri(uri)
|
||||
if (!urip.host.startsWith('did:')) {
|
||||
const res = await agent.resolveHandle({
|
||||
handle: urip.host,
|
||||
const {did} = await appview.call(com.atproto.identity.resolveHandle, {
|
||||
handle: urip.host as HandleString,
|
||||
})
|
||||
// @ts-expect-error TODO new-sdk-migration
|
||||
urip.host = res.data.did
|
||||
urip.host = did
|
||||
}
|
||||
const res = await agent.getPosts({
|
||||
const res = await appview.call(app.bsky.feed.getPosts, {
|
||||
uris: [urip.toString()],
|
||||
})
|
||||
if (res.success && res.data.posts[0]) {
|
||||
return res.data.posts[0]
|
||||
if (res.posts[0]) {
|
||||
return res.posts[0]
|
||||
}
|
||||
throw new Error('getPost: post not found')
|
||||
}
|
||||
@@ -209,17 +219,16 @@ export async function resolveLink(
|
||||
async function fetchDid(handleOrDid: string) {
|
||||
let identifier = handleOrDid
|
||||
if (!identifier.startsWith('did:')) {
|
||||
const res = await agent.resolveHandle({handle: identifier})
|
||||
identifier = res.data.did
|
||||
const {did} = await appview.call(com.atproto.identity.resolveHandle, {
|
||||
handle: identifier as HandleString,
|
||||
})
|
||||
identifier = did
|
||||
}
|
||||
return identifier
|
||||
}
|
||||
}
|
||||
|
||||
export async function resolveGif(
|
||||
agent: SessionAgent,
|
||||
gif: Gif,
|
||||
): Promise<ResolvedExternalLink> {
|
||||
export async function resolveGif(gif: Gif): Promise<ResolvedExternalLink> {
|
||||
const gifUrl = gif.media_formats.gif.url
|
||||
const params = new URLSearchParams()
|
||||
params.set('hh', String(gif.media_formats.gif.dims[1]))
|
||||
@@ -259,10 +268,15 @@ function getFileSlug(url: string | undefined): string | undefined {
|
||||
}
|
||||
|
||||
async function resolveExternal(
|
||||
agent: SessionAgent,
|
||||
clients: ResolveClients,
|
||||
uri: string,
|
||||
): Promise<ResolvedExternalLink> {
|
||||
const result = await getLinkMeta(agent, uri)
|
||||
/*
|
||||
* getLinkMeta still takes the bridge agent (not yet migrated); it only reads
|
||||
* a service URL from it that LINK_META_PROXY ignores. Keep threading the
|
||||
* agent here until link-meta migrates.
|
||||
*/
|
||||
const result = await getLinkMeta(clients.agent, uri)
|
||||
return {
|
||||
type: 'external',
|
||||
uri: result.url,
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user