diff options
author | Eric Bailey <git@esb.lol> | 2023-11-17 14:15:14 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-17 12:15:14 -0800 |
commit | 019aae5f01cb7b503d242917ae0092c2818f3b71 (patch) | |
tree | 3ae142ba4245bcc5beca5339672fcdfa01e7d347 /src | |
parent | 7c51a3931a81daa4162f4f9421467cee25ea2890 (diff) | |
download | voidsky-019aae5f01cb7b503d242917ae0092c2818f3b71.tar.zst |
Improve dedupe logic on search suggestions (#1958)
Diffstat (limited to 'src')
-rw-r--r-- | src/view/screens/Search/Search.tsx | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/src/view/screens/Search/Search.tsx b/src/view/screens/Search/Search.tsx index 6674d7cd1..a17c0d407 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()) } |