Remove old Suggested Follows logic (#3689)
parent
8ec3d8c76e
commit
e2a59449df
|
@ -8,4 +8,3 @@ export type Gate =
|
|||
| 'start_session_with_following_v2'
|
||||
| 'test_gate_1'
|
||||
| 'test_gate_2'
|
||||
| 'use_new_suggestions_endpoint'
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import React from 'react'
|
||||
import {
|
||||
AppBskyActorDefs,
|
||||
AppBskyActorGetSuggestions,
|
||||
|
@ -11,7 +10,6 @@ import {
|
|||
QueryKey,
|
||||
useInfiniteQuery,
|
||||
useQuery,
|
||||
useQueryClient,
|
||||
} from '@tanstack/react-query'
|
||||
|
||||
import {STALE} from '#/state/queries'
|
||||
|
@ -90,29 +88,6 @@ export function useSuggestedFollowsByActorQuery({did}: {did: string}) {
|
|||
})
|
||||
}
|
||||
|
||||
export function useGetSuggestedFollowersByActor() {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return React.useCallback(
|
||||
async (actor: string) => {
|
||||
const res = await queryClient.fetchQuery({
|
||||
staleTime: STALE.MINUTES.ONE,
|
||||
queryKey: suggestedFollowsByActorQueryKey(actor),
|
||||
queryFn: async () => {
|
||||
const res =
|
||||
await getAgent().app.bsky.graph.getSuggestedFollowsByActor({
|
||||
actor: actor,
|
||||
})
|
||||
return res.data
|
||||
},
|
||||
})
|
||||
|
||||
return res
|
||||
},
|
||||
[queryClient],
|
||||
)
|
||||
}
|
||||
|
||||
export function* findAllProfilesInQueryData(
|
||||
queryClient: QueryClient,
|
||||
did: string,
|
||||
|
|
|
@ -22,7 +22,6 @@ import {HITSLOP_10} from '#/lib/constants'
|
|||
import {usePalette} from '#/lib/hooks/usePalette'
|
||||
import {MagnifyingGlassIcon} from '#/lib/icons'
|
||||
import {NavigationProp} from '#/lib/routes/types'
|
||||
import {useGate} from '#/lib/statsig/statsig'
|
||||
import {augmentSearchQuery} from '#/lib/strings/helpers'
|
||||
import {s} from '#/lib/styles'
|
||||
import {logger} from '#/logger'
|
||||
|
@ -32,10 +31,7 @@ import {useActorAutocompleteFn} from '#/state/queries/actor-autocomplete'
|
|||
import {useActorSearch} from '#/state/queries/actor-search'
|
||||
import {useModerationOpts} from '#/state/queries/preferences'
|
||||
import {useSearchPostsQuery} from '#/state/queries/search-posts'
|
||||
import {
|
||||
useGetSuggestedFollowersByActor,
|
||||
useSuggestedFollowsQuery,
|
||||
} from '#/state/queries/suggested-follows'
|
||||
import {useSuggestedFollowsQuery} from '#/state/queries/suggested-follows'
|
||||
import {useSession} from '#/state/session'
|
||||
import {useSetDrawerOpen} from '#/state/shell'
|
||||
import {useSetDrawerSwipeDisabled, useSetMinimalShellMode} from '#/state/shell'
|
||||
|
@ -121,56 +117,7 @@ function EmptyState({message, error}: {message: string; error?: string}) {
|
|||
)
|
||||
}
|
||||
|
||||
function useSuggestedFollowsV1(): [
|
||||
AppBskyActorDefs.ProfileViewBasic[],
|
||||
() => void,
|
||||
] {
|
||||
const {currentAccount} = useSession()
|
||||
const [suggestions, setSuggestions] = React.useState<
|
||||
AppBskyActorDefs.ProfileViewBasic[]
|
||||
>([])
|
||||
const getSuggestedFollowsByActor = useGetSuggestedFollowersByActor()
|
||||
|
||||
React.useEffect(() => {
|
||||
async function getSuggestions() {
|
||||
const friends = await getSuggestedFollowsByActor(
|
||||
currentAccount!.did,
|
||||
).then(friendsRes => friendsRes.suggestions)
|
||||
|
||||
if (!friends) return // :(
|
||||
|
||||
const friendsOfFriends = new Map<
|
||||
string,
|
||||
AppBskyActorDefs.ProfileViewBasic
|
||||
>()
|
||||
|
||||
await Promise.all(
|
||||
friends.slice(0, 4).map(friend =>
|
||||
getSuggestedFollowsByActor(friend.did).then(foafsRes => {
|
||||
for (const user of foafsRes.suggestions) {
|
||||
if (user.associated?.labeler) continue
|
||||
friendsOfFriends.set(user.did, user)
|
||||
}
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
||||
setSuggestions(Array.from(friendsOfFriends.values()))
|
||||
}
|
||||
|
||||
try {
|
||||
getSuggestions()
|
||||
} catch (e) {
|
||||
logger.error(`SearchScreenSuggestedFollows: failed to get suggestions`, {
|
||||
message: e,
|
||||
})
|
||||
}
|
||||
}, [currentAccount, setSuggestions, getSuggestedFollowsByActor])
|
||||
|
||||
return [suggestions, () => {}]
|
||||
}
|
||||
|
||||
function useSuggestedFollowsV2(): [
|
||||
function useSuggestedFollows(): [
|
||||
AppBskyActorDefs.ProfileViewBasic[],
|
||||
() => void,
|
||||
] {
|
||||
|
@ -210,12 +157,6 @@ function useSuggestedFollowsV2(): [
|
|||
|
||||
function SearchScreenSuggestedFollows() {
|
||||
const pal = usePalette('default')
|
||||
const gate = useGate()
|
||||
const useSuggestedFollows = gate('use_new_suggestions_endpoint')
|
||||
? // Conditional hook call here is *only* OK because useGate()
|
||||
// result won't change until a remount.
|
||||
useSuggestedFollowsV2
|
||||
: useSuggestedFollowsV1
|
||||
const [suggestions, onEndReached] = useSuggestedFollows()
|
||||
|
||||
return suggestions.length ? (
|
||||
|
|
Loading…
Reference in New Issue