Remove old Suggested Follows logic (#3689)
parent
8ec3d8c76e
commit
e2a59449df
|
@ -8,4 +8,3 @@ export type Gate =
|
||||||
| 'start_session_with_following_v2'
|
| 'start_session_with_following_v2'
|
||||||
| 'test_gate_1'
|
| 'test_gate_1'
|
||||||
| 'test_gate_2'
|
| 'test_gate_2'
|
||||||
| 'use_new_suggestions_endpoint'
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import React from 'react'
|
|
||||||
import {
|
import {
|
||||||
AppBskyActorDefs,
|
AppBskyActorDefs,
|
||||||
AppBskyActorGetSuggestions,
|
AppBskyActorGetSuggestions,
|
||||||
|
@ -11,7 +10,6 @@ import {
|
||||||
QueryKey,
|
QueryKey,
|
||||||
useInfiniteQuery,
|
useInfiniteQuery,
|
||||||
useQuery,
|
useQuery,
|
||||||
useQueryClient,
|
|
||||||
} from '@tanstack/react-query'
|
} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {STALE} from '#/state/queries'
|
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(
|
export function* findAllProfilesInQueryData(
|
||||||
queryClient: QueryClient,
|
queryClient: QueryClient,
|
||||||
did: string,
|
did: string,
|
||||||
|
|
|
@ -22,7 +22,6 @@ import {HITSLOP_10} from '#/lib/constants'
|
||||||
import {usePalette} from '#/lib/hooks/usePalette'
|
import {usePalette} from '#/lib/hooks/usePalette'
|
||||||
import {MagnifyingGlassIcon} from '#/lib/icons'
|
import {MagnifyingGlassIcon} from '#/lib/icons'
|
||||||
import {NavigationProp} from '#/lib/routes/types'
|
import {NavigationProp} from '#/lib/routes/types'
|
||||||
import {useGate} from '#/lib/statsig/statsig'
|
|
||||||
import {augmentSearchQuery} from '#/lib/strings/helpers'
|
import {augmentSearchQuery} from '#/lib/strings/helpers'
|
||||||
import {s} from '#/lib/styles'
|
import {s} from '#/lib/styles'
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
|
@ -32,10 +31,7 @@ import {useActorAutocompleteFn} from '#/state/queries/actor-autocomplete'
|
||||||
import {useActorSearch} from '#/state/queries/actor-search'
|
import {useActorSearch} from '#/state/queries/actor-search'
|
||||||
import {useModerationOpts} from '#/state/queries/preferences'
|
import {useModerationOpts} from '#/state/queries/preferences'
|
||||||
import {useSearchPostsQuery} from '#/state/queries/search-posts'
|
import {useSearchPostsQuery} from '#/state/queries/search-posts'
|
||||||
import {
|
import {useSuggestedFollowsQuery} from '#/state/queries/suggested-follows'
|
||||||
useGetSuggestedFollowersByActor,
|
|
||||||
useSuggestedFollowsQuery,
|
|
||||||
} from '#/state/queries/suggested-follows'
|
|
||||||
import {useSession} from '#/state/session'
|
import {useSession} from '#/state/session'
|
||||||
import {useSetDrawerOpen} from '#/state/shell'
|
import {useSetDrawerOpen} from '#/state/shell'
|
||||||
import {useSetDrawerSwipeDisabled, useSetMinimalShellMode} from '#/state/shell'
|
import {useSetDrawerSwipeDisabled, useSetMinimalShellMode} from '#/state/shell'
|
||||||
|
@ -121,56 +117,7 @@ function EmptyState({message, error}: {message: string; error?: string}) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function useSuggestedFollowsV1(): [
|
function useSuggestedFollows(): [
|
||||||
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(): [
|
|
||||||
AppBskyActorDefs.ProfileViewBasic[],
|
AppBskyActorDefs.ProfileViewBasic[],
|
||||||
() => void,
|
() => void,
|
||||||
] {
|
] {
|
||||||
|
@ -210,12 +157,6 @@ function useSuggestedFollowsV2(): [
|
||||||
|
|
||||||
function SearchScreenSuggestedFollows() {
|
function SearchScreenSuggestedFollows() {
|
||||||
const pal = usePalette('default')
|
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()
|
const [suggestions, onEndReached] = useSuggestedFollows()
|
||||||
|
|
||||||
return suggestions.length ? (
|
return suggestions.length ? (
|
||||||
|
|
Loading…
Reference in New Issue