Fall back for non-public feeds (#1988)

zio/stable
Eric Bailey 2023-11-24 17:37:28 -06:00 committed by GitHub
parent 1bcbc0cf2a
commit 20b699a008
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 90 additions and 14 deletions

View File

@ -160,6 +160,35 @@ export function useFeedSourceInfoQuery({uri}: {uri: string}) {
}) })
} }
export const isFeedPublicQueryKey = ({uri}: {uri: string}) => [
'isFeedPublic',
uri,
]
export function useIsFeedPublicQuery({uri}: {uri: string}) {
return useQuery({
queryKey: isFeedPublicQueryKey({uri}),
queryFn: async ({queryKey}) => {
const [, uri] = queryKey
try {
const res = await getAgent().app.bsky.feed.getFeed({
feed: uri,
limit: 1,
})
return Boolean(res.data.feed)
} catch (e: any) {
const msg = e.toString() as string
if (msg.includes('missing jwt')) {
return false
}
return true
}
},
})
}
export const useGetPopularFeedsQueryKey = ['getPopularFeeds'] export const useGetPopularFeedsQueryKey = ['getPopularFeeds']
export function useGetPopularFeedsQuery() { export function useGetPopularFeedsQuery() {

View File

@ -47,7 +47,11 @@ import {Trans, msg} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {useModalControls} from '#/state/modals' import {useModalControls} from '#/state/modals'
import {useAnimatedScrollHandler} from '#/lib/hooks/useAnimatedScrollHandler_FIXED' import {useAnimatedScrollHandler} from '#/lib/hooks/useAnimatedScrollHandler_FIXED'
import {useFeedSourceInfoQuery, FeedSourceFeedInfo} from '#/state/queries/feed' import {
useFeedSourceInfoQuery,
FeedSourceFeedInfo,
useIsFeedPublicQuery,
} from '#/state/queries/feed'
import {useResolveUriQuery} from '#/state/queries/resolve-uri' import {useResolveUriQuery} from '#/state/queries/resolve-uri'
import { import {
UsePreferencesQueryResponse, UsePreferencesQueryResponse,
@ -131,8 +135,10 @@ export function ProfileFeedScreen(props: Props) {
function ProfileFeedScreenIntermediate({feedUri}: {feedUri: string}) { function ProfileFeedScreenIntermediate({feedUri}: {feedUri: string}) {
const {data: preferences} = usePreferencesQuery() const {data: preferences} = usePreferencesQuery()
const {data: info} = useFeedSourceInfoQuery({uri: feedUri}) const {data: info} = useFeedSourceInfoQuery({uri: feedUri})
const {isLoading: isPublicStatusLoading, data: isPublic} =
useIsFeedPublicQuery({uri: feedUri})
if (!preferences || !info) { if (!preferences || !info || isPublicStatusLoading) {
return ( return (
<CenteredView> <CenteredView>
<View style={s.p20}> <View style={s.p20}>
@ -146,6 +152,7 @@ function ProfileFeedScreenIntermediate({feedUri}: {feedUri: string}) {
<ProfileFeedScreenInner <ProfileFeedScreenInner
preferences={preferences} preferences={preferences}
feedInfo={info as FeedSourceFeedInfo} feedInfo={info as FeedSourceFeedInfo}
isPublic={Boolean(isPublic)}
/> />
) )
} }
@ -153,9 +160,11 @@ function ProfileFeedScreenIntermediate({feedUri}: {feedUri: string}) {
export function ProfileFeedScreenInner({ export function ProfileFeedScreenInner({
preferences, preferences,
feedInfo, feedInfo,
isPublic,
}: { }: {
preferences: UsePreferencesQueryResponse preferences: UsePreferencesQueryResponse
feedInfo: FeedSourceFeedInfo feedInfo: FeedSourceFeedInfo
isPublic: boolean
}) { }) {
const {_} = useLingui() const {_} = useLingui()
const pal = usePalette('default') const pal = usePalette('default')
@ -391,18 +400,24 @@ export function ProfileFeedScreenInner({
isHeaderReady={true} isHeaderReady={true}
renderHeader={renderHeader} renderHeader={renderHeader}
onCurrentPageSelected={onCurrentPageSelected}> onCurrentPageSelected={onCurrentPageSelected}>
{({onScroll, headerHeight, isScrolledDown, scrollElRef}) => ( {({onScroll, headerHeight, isScrolledDown, scrollElRef}) =>
<FeedSection isPublic ? (
ref={feedSectionRef} <FeedSection
feed={`feedgen|${feedInfo.uri}`} ref={feedSectionRef}
onScroll={onScroll} feed={`feedgen|${feedInfo.uri}`}
headerHeight={headerHeight} onScroll={onScroll}
isScrolledDown={isScrolledDown} headerHeight={headerHeight}
scrollElRef={ isScrolledDown={isScrolledDown}
scrollElRef as React.MutableRefObject<FlatList<any> | null> scrollElRef={
} scrollElRef as React.MutableRefObject<FlatList<any> | null>
/> }
)} />
) : (
<CenteredView sideBorders style={[{paddingTop: headerHeight}]}>
<NonPublicFeedMessage />
</CenteredView>
)
}
{({onScroll, headerHeight, scrollElRef}) => ( {({onScroll, headerHeight, scrollElRef}) => (
<AboutSection <AboutSection
feedOwnerDid={feedInfo.creatorDid} feedOwnerDid={feedInfo.creatorDid}
@ -437,6 +452,38 @@ export function ProfileFeedScreenInner({
) )
} }
function NonPublicFeedMessage() {
const pal = usePalette('default')
return (
<View
style={[
pal.border,
{
padding: 18,
borderTopWidth: 1,
minHeight: Dimensions.get('window').height * 1.5,
},
]}>
<View
style={[
pal.viewLight,
{
padding: 12,
borderRadius: 8,
},
]}>
<Text style={[pal.text]}>
<Trans>
Looks like this feed is only available to users with a Bluesky
account. Please sign up or sign in to view this feed!
</Trans>
</Text>
</View>
</View>
)
}
interface FeedSectionProps { interface FeedSectionProps {
feed: FeedDescriptor feed: FeedDescriptor
onScroll: OnScrollHandler onScroll: OnScrollHandler