diff options
Diffstat (limited to 'src/view/com')
-rw-r--r-- | src/view/com/lists/ListMembers.tsx | 7 | ||||
-rw-r--r-- | src/view/com/notifications/NotificationFeedItem.tsx | 18 | ||||
-rw-r--r-- | src/view/com/post-thread/PostRepostedBy.tsx | 2 | ||||
-rw-r--r-- | src/view/com/post-thread/PostThreadFollowBtn.tsx | 5 | ||||
-rw-r--r-- | src/view/com/post-thread/PostThreadItem.tsx | 6 | ||||
-rw-r--r-- | src/view/com/post/Post.tsx | 4 | ||||
-rw-r--r-- | src/view/com/posts/PostFeedItem.tsx | 9 | ||||
-rw-r--r-- | src/view/com/profile/FollowButton.tsx | 4 | ||||
-rw-r--r-- | src/view/com/profile/ProfileCard.tsx | 12 | ||||
-rw-r--r-- | src/view/com/profile/ProfileFollowers.tsx | 2 | ||||
-rw-r--r-- | src/view/com/profile/ProfileFollows.tsx | 2 | ||||
-rw-r--r-- | src/view/com/util/UserAvatar.tsx | 5 | ||||
-rw-r--r-- | src/view/com/util/post-embeds/QuoteEmbed.tsx | 13 |
13 files changed, 58 insertions, 31 deletions
diff --git a/src/view/com/lists/ListMembers.tsx b/src/view/com/lists/ListMembers.tsx index 0caae6701..31d2b5fb5 100644 --- a/src/view/com/lists/ListMembers.tsx +++ b/src/view/com/lists/ListMembers.tsx @@ -1,6 +1,6 @@ import React, {useCallback} from 'react' import {Dimensions, StyleProp, View, ViewStyle} from 'react-native' -import {AppBskyActorDefs, AppBskyGraphDefs} from '@atproto/api' +import {AppBskyGraphDefs} from '@atproto/api' import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' @@ -11,6 +11,7 @@ import {useModalControls} from '#/state/modals' import {useListMembersQuery} from '#/state/queries/list-members' import {useSession} from '#/state/session' import {ListFooter} from '#/components/Lists' +import * as bsky from '#/types/bsky' import {ProfileCard} from '../profile/ProfileCard' import {ErrorMessage} from '../util/error/ErrorMessage' import {Button} from '../util/forms/Button' @@ -116,7 +117,7 @@ export function ListMembers({ }, [fetchNextPage]) const onPressEditMembership = React.useCallback( - (profile: AppBskyActorDefs.ProfileViewBasic) => { + (profile: bsky.profile.AnyProfileView) => { openModal({ name: 'user-add-remove-lists', subject: profile.did, @@ -131,7 +132,7 @@ export function ListMembers({ // = const renderMemberButton = React.useCallback( - (profile: AppBskyActorDefs.ProfileViewBasic) => { + (profile: bsky.profile.AnyProfileView) => { if (!isOwner) { return null } diff --git a/src/view/com/notifications/NotificationFeedItem.tsx b/src/view/com/notifications/NotificationFeedItem.tsx index 1267ce089..84694fe3b 100644 --- a/src/view/com/notifications/NotificationFeedItem.tsx +++ b/src/view/com/notifications/NotificationFeedItem.tsx @@ -58,6 +58,7 @@ import * as MediaPreview from '#/components/MediaPreview' import {ProfileHoverCard} from '#/components/ProfileHoverCard' import {Notification as StarterPackCard} from '#/components/StarterPack/StarterPackCard' import {SubtleWebHover} from '#/components/SubtleWebHover' +import * as bsky from '#/types/bsky' import {FeedSourceCard} from '../feeds/FeedSourceCard' import {Post} from '../post/Post' import {Link, TextLink} from '../util/Link' @@ -71,7 +72,7 @@ const MAX_AUTHORS = 5 const EXPANDED_AUTHOR_EL_HEIGHT = 35 interface Author { - profile: AppBskyActorDefs.ProfileViewBasic + profile: AppBskyActorDefs.ProfileView href: string moderation: ModerationDecision } @@ -264,7 +265,10 @@ let NotificationFeedItem = ({ if ( item.notification.author.viewer?.following && - AppBskyGraphFollow.isRecord(item.notification.record) + bsky.dangerousIsType<AppBskyGraphFollow.Record>( + item.notification.record, + AppBskyGraphFollow.isRecord, + ) ) { let followingTimestamp try { @@ -521,7 +525,7 @@ function ExpandListPressable({ } } -function SayHelloBtn({profile}: {profile: AppBskyActorDefs.ProfileViewBasic}) { +function SayHelloBtn({profile}: {profile: AppBskyActorDefs.ProfileView}) { const {_} = useLingui() const agent = useAgent() const navigation = useNavigation<NavigationProp>() @@ -716,7 +720,13 @@ function ExpandedAuthorsList({ function AdditionalPostText({post}: {post?: AppBskyFeedDefs.PostView}) { const pal = usePalette('default') - if (post && AppBskyFeedPost.isRecord(post?.record)) { + if ( + post && + bsky.dangerousIsType<AppBskyFeedPost.Record>( + post?.record, + AppBskyFeedPost.isRecord, + ) + ) { const text = post.record.text return ( diff --git a/src/view/com/post-thread/PostRepostedBy.tsx b/src/view/com/post-thread/PostRepostedBy.tsx index 2143bd9c2..c27e37f49 100644 --- a/src/view/com/post-thread/PostRepostedBy.tsx +++ b/src/view/com/post-thread/PostRepostedBy.tsx @@ -16,7 +16,7 @@ function renderItem({ item, index, }: { - item: ActorDefs.ProfileViewBasic + item: ActorDefs.ProfileView index: number }) { return ( diff --git a/src/view/com/post-thread/PostThreadFollowBtn.tsx b/src/view/com/post-thread/PostThreadFollowBtn.tsx index 9dc93916a..145e919f9 100644 --- a/src/view/com/post-thread/PostThreadFollowBtn.tsx +++ b/src/view/com/post-thread/PostThreadFollowBtn.tsx @@ -5,7 +5,7 @@ import {useLingui} from '@lingui/react' import {useNavigation} from '@react-navigation/native' import {logger} from '#/logger' -import {Shadow, useProfileShadow} from '#/state/cache/profile-shadow' +import {useProfileShadow} from '#/state/cache/profile-shadow' import { useProfileFollowMutationQueue, useProfileQuery, @@ -35,8 +35,7 @@ function PostThreadFollowBtnLoaded({ const navigation = useNavigation() const {_} = useLingui() const {gtMobile} = useBreakpoints() - const profile: Shadow<AppBskyActorDefs.ProfileViewBasic> = - useProfileShadow(profileUnshadowed) + const profile = useProfileShadow(profileUnshadowed) const [queueFollow, queueUnfollow] = useProfileFollowMutationQueue( profile, 'PostThreadItem', diff --git a/src/view/com/post-thread/PostThreadItem.tsx b/src/view/com/post-thread/PostThreadItem.tsx index 928ccd783..024629198 100644 --- a/src/view/com/post-thread/PostThreadItem.tsx +++ b/src/view/com/post-thread/PostThreadItem.tsx @@ -58,6 +58,7 @@ import {RichText} from '#/components/RichText' import {SubtleWebHover} from '#/components/SubtleWebHover' import {Text} from '#/components/Typography' import {WhoCanReply} from '#/components/WhoCanReply' +import * as bsky from '#/types/bsky' export function PostThreadItem({ post, @@ -790,7 +791,10 @@ function BackdatedPostIndicator({post}: {post: AppBskyFeedDefs.PostView}) { const control = Prompt.usePromptControl() const indexedAt = new Date(post.indexedAt) - const createdAt = AppBskyFeedPost.isRecord(post.record) + const createdAt = bsky.dangerousIsType<AppBskyFeedPost.Record>( + post.record, + AppBskyFeedPost.isRecord, + ) ? new Date(post.record.createdAt) : new Date(post.indexedAt) diff --git a/src/view/com/post/Post.tsx b/src/view/com/post/Post.tsx index c87e361e1..2645237ad 100644 --- a/src/view/com/post/Post.tsx +++ b/src/view/com/post/Post.tsx @@ -28,6 +28,7 @@ import {atoms as a} from '#/alf' import {ProfileHoverCard} from '#/components/ProfileHoverCard' import {RichText} from '#/components/RichText' import {SubtleWebHover} from '#/components/SubtleWebHover' +import * as bsky from '#/types/bsky' import {ContentHider} from '../../../components/moderation/ContentHider' import {LabelsOnMyPost} from '../../../components/moderation/LabelsOnMe' import {PostAlerts} from '../../../components/moderation/PostAlerts' @@ -53,8 +54,7 @@ export function Post({ const moderationOpts = useModerationOpts() const record = useMemo<AppBskyFeedPost.Record | undefined>( () => - AppBskyFeedPost.isRecord(post.record) && - AppBskyFeedPost.validateRecord(post.record).success + bsky.validate(post.record, AppBskyFeedPost.validateRecord) ? post.record : undefined, [post], diff --git a/src/view/com/posts/PostFeedItem.tsx b/src/view/com/posts/PostFeedItem.tsx index 4b18c470a..13c243c0a 100644 --- a/src/view/com/posts/PostFeedItem.tsx +++ b/src/view/com/posts/PostFeedItem.tsx @@ -47,6 +47,7 @@ import {AppModerationCause} from '#/components/Pills' import {ProfileHoverCard} from '#/components/ProfileHoverCard' import {RichText} from '#/components/RichText' import {SubtleWebHover} from '#/components/SubtleWebHover' +import * as bsky from '#/types/bsky' import {Link, TextLink, TextLinkOnWebOnly} from '../util/Link' import {AviFollowButton} from './AviFollowButton' @@ -232,8 +233,9 @@ let FeedItemInner = ({ * If `post[0]` in this slice is the actual root post (not an orphan thread), * then we may have a threadgate record to reference */ - const threadgateRecord = AppBskyFeedThreadgate.isRecord( + const threadgateRecord = bsky.dangerousIsType<AppBskyFeedThreadgate.Record>( rootPost.threadgate?.record, + AppBskyFeedThreadgate.isRecord, ) ? rootPost.threadgate.record : undefined @@ -461,7 +463,10 @@ let PostContent = ({ }) const additionalPostAlerts: AppModerationCause[] = React.useMemo(() => { const isPostHiddenByThreadgate = threadgateHiddenReplies.has(post.uri) - const rootPostUri = AppBskyFeedPost.isRecord(post.record) + const rootPostUri = bsky.dangerousIsType<AppBskyFeedPost.Record>( + post.record, + AppBskyFeedPost.isRecord, + ) ? post.record?.reply?.root?.uri || post.uri : undefined const isControlledByViewer = diff --git a/src/view/com/profile/FollowButton.tsx b/src/view/com/profile/FollowButton.tsx index ff58dc945..656ed914a 100644 --- a/src/view/com/profile/FollowButton.tsx +++ b/src/view/com/profile/FollowButton.tsx @@ -1,10 +1,10 @@ import {StyleProp, TextStyle, View} from 'react-native' -import {AppBskyActorDefs} from '@atproto/api' import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' import {Shadow} from '#/state/cache/types' import {useProfileFollowMutationQueue} from '#/state/queries/profile' +import * as bsky from '#/types/bsky' import {Button, ButtonType} from '../util/forms/Button' import * as Toast from '../util/Toast' @@ -18,7 +18,7 @@ export function FollowButton({ }: { unfollowedType?: ButtonType followedType?: ButtonType - profile: Shadow<AppBskyActorDefs.ProfileViewBasic> + profile: Shadow<bsky.profile.AnyProfileView> labelStyle?: StyleProp<TextStyle> logContext: 'ProfileCard' | 'StarterPackProfilesList' onFollow?: () => void diff --git a/src/view/com/profile/ProfileCard.tsx b/src/view/com/profile/ProfileCard.tsx index f710d7b4e..bd09d6514 100644 --- a/src/view/com/profile/ProfileCard.tsx +++ b/src/view/com/profile/ProfileCard.tsx @@ -24,6 +24,7 @@ import { shouldShowKnownFollowers, } from '#/components/KnownFollowers' import * as Pills from '#/components/Pills' +import * as bsky from '#/types/bsky' import {Link} from '../util/Link' import {Text} from '../util/text/Text' import {PreviewableUserAvatar} from '../util/UserAvatar' @@ -41,12 +42,12 @@ export function ProfileCard({ showKnownFollowers, }: { testID?: string - profile: AppBskyActorDefs.ProfileViewBasic + profile: bsky.profile.AnyProfileView noModFilter?: boolean noBg?: boolean noBorder?: boolean renderButton?: ( - profile: Shadow<AppBskyActorDefs.ProfileViewBasic>, + profile: Shadow<bsky.profile.AnyProfileView>, ) => React.ReactNode onPress?: () => void style?: StyleProp<ViewStyle> @@ -76,6 +77,7 @@ export function ProfileCard({ showKnownFollowers && shouldShowKnownFollowers(profile.viewer?.knownFollowers) && moderationOpts + const hasDescription = 'description' in profile return ( <Link @@ -126,9 +128,9 @@ export function ProfileCard({ <View style={styles.layoutButton}>{renderButton(profile)}</View> ) : undefined} </View> - {profile.description || knownFollowersVisible ? ( + {hasDescription || knownFollowersVisible ? ( <View style={styles.details}> - {profile.description ? ( + {hasDescription && profile.description ? ( <Text emoji style={pal.text} numberOfLines={4}> {profile.description as string} </Text> @@ -139,7 +141,7 @@ export function ProfileCard({ a.flex_row, a.align_center, a.gap_sm, - !!profile.description && a.mt_md, + !!hasDescription && a.mt_md, ]}> <KnownFollowers minimal diff --git a/src/view/com/profile/ProfileFollowers.tsx b/src/view/com/profile/ProfileFollowers.tsx index 3c0476929..d6b764656 100644 --- a/src/view/com/profile/ProfileFollowers.tsx +++ b/src/view/com/profile/ProfileFollowers.tsx @@ -17,7 +17,7 @@ function renderItem({ item, index, }: { - item: ActorDefs.ProfileViewBasic + item: ActorDefs.ProfileView index: number }) { return ( diff --git a/src/view/com/profile/ProfileFollows.tsx b/src/view/com/profile/ProfileFollows.tsx index 1cd65c74c..d67a7261a 100644 --- a/src/view/com/profile/ProfileFollows.tsx +++ b/src/view/com/profile/ProfileFollows.tsx @@ -17,7 +17,7 @@ function renderItem({ item, index, }: { - item: ActorDefs.ProfileViewBasic + item: ActorDefs.ProfileView index: number }) { return ( diff --git a/src/view/com/util/UserAvatar.tsx b/src/view/com/util/UserAvatar.tsx index 2496f9d2a..934e8f50c 100644 --- a/src/view/com/util/UserAvatar.tsx +++ b/src/view/com/util/UserAvatar.tsx @@ -2,7 +2,7 @@ import React, {memo, useMemo} from 'react' import {Image, Pressable, StyleSheet, View} from 'react-native' import {Image as RNImage} from 'react-native-image-crop-picker' import Svg, {Circle, Path, Rect} from 'react-native-svg' -import {AppBskyActorDefs, ModerationUI} from '@atproto/api' +import {ModerationUI} from '@atproto/api' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' @@ -31,6 +31,7 @@ import {Link} from '#/components/Link' import {MediaInsetBorder} from '#/components/MediaInsetBorder' import * as Menu from '#/components/Menu' import {ProfileHoverCard} from '#/components/ProfileHoverCard' +import * as bsky from '#/types/bsky' import {openCamera, openCropper, openPicker} from '../../../lib/media/picker' export type UserAvatarType = 'user' | 'algo' | 'list' | 'labeler' @@ -55,7 +56,7 @@ interface EditableUserAvatarProps extends BaseUserAvatarProps { interface PreviewableUserAvatarProps extends BaseUserAvatarProps { moderation?: ModerationUI - profile: AppBskyActorDefs.ProfileViewBasic + profile: bsky.profile.AnyProfileView disableHoverCard?: boolean onBeforePress?: () => void } diff --git a/src/view/com/util/post-embeds/QuoteEmbed.tsx b/src/view/com/util/post-embeds/QuoteEmbed.tsx index cb549f7cd..e283a2eec 100644 --- a/src/view/com/util/post-embeds/QuoteEmbed.tsx +++ b/src/view/com/util/post-embeds/QuoteEmbed.tsx @@ -36,6 +36,7 @@ import {useSession} from '#/state/session' import {atoms as a, useTheme} from '#/alf' import {RichText} from '#/components/RichText' import {SubtleWebHover} from '#/components/SubtleWebHover' +import * as bsky from '#/types/bsky' import {ContentHider} from '../../../../components/moderation/ContentHider' import {PostAlerts} from '../../../../components/moderation/PostAlerts' import {Link} from '../Link' @@ -171,10 +172,14 @@ export function QuoteEmbed({ const itemTitle = `Post by ${quote.author.handle}` const richText = React.useMemo(() => { - const text = AppBskyFeedPost.isRecord(quote.record) ? quote.record.text : '' - const facets = AppBskyFeedPost.isRecord(quote.record) - ? quote.record.facets - : undefined + if ( + !bsky.dangerousIsType<AppBskyFeedPost.Record>( + quote.record, + AppBskyFeedPost.isRecord, + ) + ) + return undefined + const {text, facets} = quote.record return text.trim() ? new RichTextAPI({text: text, facets: facets}) : undefined |