Improve dedupe logic on search suggestions (#1958)

zio/stable
Eric Bailey 2023-11-17 14:15:14 -06:00 committed by GitHub
parent 7c51a3931a
commit 019aae5f01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 15 deletions

View File

@ -119,29 +119,28 @@ function SearchScreenSuggestedFollows() {
React.useEffect(() => {
async function getSuggestions() {
// TODO not quite right, doesn't fetch your follows
const friends = await getSuggestedFollowsByActor(
currentAccount!.did,
).then(friendsRes => friendsRes.suggestions)
if (!friends) return // :(
const friendsOfFriends = (
const friendsOfFriends = new Map<
string,
AppBskyActorDefs.ProfileViewBasic
>()
await Promise.all(
friends
.slice(0, 4)
.map(friend =>
getSuggestedFollowsByActor(friend.did).then(
foafsRes => foafsRes.suggestions,
friends.slice(0, 4).map(friend =>
getSuggestedFollowsByActor(friend.did).then(foafsRes => {
for (const user of foafsRes.suggestions) {
friendsOfFriends.set(user.did, user)
}
}),
),
),
)
).flat()
const deduped = friendsOfFriends.filter(
(f, i) => friendsOfFriends.findIndex(f2 => f.did === f2.did) === i,
)
setSuggestions(deduped)
setSuggestions(Array.from(friendsOfFriends.values()))
setDataUpdatedAt(Date.now())
}