Send Bluesky feeds and suggested follows more data (#3695)
* WIP * Fix constructors * Clean up * Tweak * Rm extra assignment * Narrow down the argument --------- Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
This commit is contained in:
parent
d893fe005d
commit
a4e34537ce
6 changed files with 91 additions and 10 deletions
|
@ -15,6 +15,7 @@ import {
|
|||
} from '@tanstack/react-query'
|
||||
|
||||
import {HomeFeedAPI} from '#/lib/api/feed/home'
|
||||
import {aggregateUserInterests} from '#/lib/api/feed/utils'
|
||||
import {moderatePost_wrapped as moderatePost} from '#/lib/moderatePost_wrapped'
|
||||
import {logger} from '#/logger'
|
||||
import {STALE} from '#/state/queries'
|
||||
|
@ -31,7 +32,7 @@ import {FeedTuner, FeedTunerFn, NoopFeedTuner} from 'lib/api/feed-manip'
|
|||
import {BSKY_FEED_OWNER_DIDS} from 'lib/constants'
|
||||
import {KnownError} from '#/view/com/posts/FeedErrorMessage'
|
||||
import {useFeedTuners} from '../preferences/feed-tuners'
|
||||
import {useModerationOpts} from './preferences'
|
||||
import {useModerationOpts, usePreferencesQuery} from './preferences'
|
||||
import {embedViewRecordToPostView, getEmbeddedPost} from './util'
|
||||
|
||||
type ActorDid = string
|
||||
|
@ -102,8 +103,11 @@ export function usePostFeedQuery(
|
|||
) {
|
||||
const feedTuners = useFeedTuners(feedDesc)
|
||||
const moderationOpts = useModerationOpts()
|
||||
const {data: preferences} = usePreferencesQuery()
|
||||
const enabled =
|
||||
opts?.enabled !== false && Boolean(moderationOpts) && Boolean(preferences)
|
||||
const userInterests = aggregateUserInterests(preferences)
|
||||
const {getAgent} = useAgent()
|
||||
const enabled = opts?.enabled !== false && Boolean(moderationOpts)
|
||||
const lastRun = useRef<{
|
||||
data: InfiniteData<FeedPageUnselected>
|
||||
args: typeof selectArgs
|
||||
|
@ -141,6 +145,7 @@ export function usePostFeedQuery(
|
|||
feedDesc,
|
||||
feedParams: params || {},
|
||||
feedTuners,
|
||||
userInterests, // Not in the query key because they don't change.
|
||||
getAgent,
|
||||
}),
|
||||
cursor: undefined,
|
||||
|
@ -371,11 +376,13 @@ function createApi({
|
|||
feedDesc,
|
||||
feedParams,
|
||||
feedTuners,
|
||||
userInterests,
|
||||
getAgent,
|
||||
}: {
|
||||
feedDesc: FeedDescriptor
|
||||
feedParams: FeedParams
|
||||
feedTuners: FeedTunerFn[]
|
||||
userInterests?: string
|
||||
getAgent: () => BskyAgent
|
||||
}) {
|
||||
if (feedDesc === 'home') {
|
||||
|
@ -384,9 +391,10 @@ function createApi({
|
|||
getAgent,
|
||||
feedParams,
|
||||
feedTuners,
|
||||
userInterests,
|
||||
})
|
||||
} else {
|
||||
return new HomeFeedAPI({getAgent})
|
||||
return new HomeFeedAPI({getAgent, userInterests})
|
||||
}
|
||||
} else if (feedDesc === 'following') {
|
||||
return new FollowingFeedAPI({getAgent})
|
||||
|
@ -401,6 +409,7 @@ function createApi({
|
|||
return new CustomFeedAPI({
|
||||
getAgent,
|
||||
feedParams: {feed},
|
||||
userInterests,
|
||||
})
|
||||
} else if (feedDesc.startsWith('list')) {
|
||||
const [_, list] = feedDesc.split('|')
|
||||
|
|
|
@ -12,8 +12,16 @@ import {
|
|||
useQuery,
|
||||
} from '@tanstack/react-query'
|
||||
|
||||
import {
|
||||
aggregateUserInterests,
|
||||
createBskyTopicsHeader,
|
||||
} from '#/lib/api/feed/utils'
|
||||
import {getContentLanguages} from '#/state/preferences/languages'
|
||||
import {STALE} from '#/state/queries'
|
||||
import {useModerationOpts} from '#/state/queries/preferences'
|
||||
import {
|
||||
useModerationOpts,
|
||||
usePreferencesQuery,
|
||||
} from '#/state/queries/preferences'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
|
||||
const suggestedFollowsQueryKeyRoot = 'suggested-follows'
|
||||
|
@ -29,6 +37,7 @@ export function useSuggestedFollowsQuery() {
|
|||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const moderationOpts = useModerationOpts()
|
||||
const {data: preferences} = usePreferencesQuery()
|
||||
|
||||
return useInfiniteQuery<
|
||||
AppBskyActorGetSuggestions.OutputSchema,
|
||||
|
@ -37,14 +46,23 @@ export function useSuggestedFollowsQuery() {
|
|||
QueryKey,
|
||||
string | undefined
|
||||
>({
|
||||
enabled: !!moderationOpts,
|
||||
enabled: !!moderationOpts && !!preferences,
|
||||
staleTime: STALE.HOURS.ONE,
|
||||
queryKey: suggestedFollowsQueryKey,
|
||||
queryFn: async ({pageParam}) => {
|
||||
const res = await getAgent().app.bsky.actor.getSuggestions({
|
||||
limit: 25,
|
||||
cursor: pageParam,
|
||||
})
|
||||
const contentLangs = getContentLanguages().join(',')
|
||||
const res = await getAgent().app.bsky.actor.getSuggestions(
|
||||
{
|
||||
limit: 25,
|
||||
cursor: pageParam,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
...createBskyTopicsHeader(aggregateUserInterests(preferences)),
|
||||
'Accept-Language': contentLangs,
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
res.data.actors = res.data.actors
|
||||
.filter(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue