From 29f18ee123c79997834fbf9ada7b6021009b5ce8 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sat, 2 Oct 2021 19:35:57 +1000 Subject: [PATCH] only suggest local users as potential group members --- bookwyrm/suggested_users.py | 22 +++++++++++++++++++ .../snippets/add_to_group_button.html | 5 ----- bookwyrm/views/group.py | 2 +- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/bookwyrm/suggested_users.py b/bookwyrm/suggested_users.py index e8f23632..06ce6db7 100644 --- a/bookwyrm/suggested_users.py +++ b/bookwyrm/suggested_users.py @@ -103,6 +103,28 @@ class SuggestedUsers(RedisStore): break return results + def get_group_suggestions(self, user): + """get suggestions for new group members""" + values = self.get_store(self.store_id(user), withscores=True) + results = [] + # annotate users with mutuals and shared book counts + for user_id, rank in values: + counts = self.get_counts_from_rank(rank) + try: + user = models.User.objects.get( + id=user_id, is_active=True, bookwyrm_user=True + ) + except models.User.DoesNotExist as err: + # if this happens, the suggestions are janked way up + logger.exception(err) + continue + user.mutuals = counts["mutuals"] + # only suggest local users until Groups are ActivityPub compliant + if user.local: + results.append(user) + if len(results) >= 5: + break + return results def get_annotated_users(viewer, *args, **kwargs): """Users, annotated with things they have in common""" diff --git a/bookwyrm/templates/snippets/add_to_group_button.html b/bookwyrm/templates/snippets/add_to_group_button.html index dd3b93c3..cf9ae15d 100644 --- a/bookwyrm/templates/snippets/add_to_group_button.html +++ b/bookwyrm/templates/snippets/add_to_group_button.html @@ -11,7 +11,6 @@ {% csrf_token %} - {% if user.local %} - {% else %} - - Remote User - {% endif %}
{% csrf_token %} diff --git a/bookwyrm/views/group.py b/bookwyrm/views/group.py index 718aa9ee..17db93ed 100644 --- a/bookwyrm/views/group.py +++ b/bookwyrm/views/group.py @@ -108,7 +108,7 @@ class FindUsers(View): data = {"no_results": not user_results} if user_results.count() < 5: - user_results = list(user_results) + suggested_users.get_suggestions( + user_results = list(user_results) + suggested_users.get_group_suggestions( request.user )