From 019aae5f01cb7b503d242917ae0092c2818f3b71 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Fri, 17 Nov 2023 14:15:14 -0600 Subject: [PATCH] Improve dedupe logic on search suggestions (#1958) --- src/view/screens/Search/Search.tsx | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/view/screens/Search/Search.tsx b/src/view/screens/Search/Search.tsx index 6674d7cd..a17c0d40 100644 --- a/src/view/screens/Search/Search.tsx +++ b/src/view/screens/Search/Search.tsx @@ -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 = ( - await Promise.all( - friends - .slice(0, 4) - .map(friend => - getSuggestedFollowsByActor(friend.did).then( - foafsRes => foafsRes.suggestions, - ), - ), - ) - ).flat() - const deduped = friendsOfFriends.filter( - (f, i) => friendsOfFriends.findIndex(f2 => f.did === f2.did) === i, + 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) { + friendsOfFriends.set(user.did, user) + } + }), + ), ) - setSuggestions(deduped) + setSuggestions(Array.from(friendsOfFriends.values())) setDataUpdatedAt(Date.now()) }