forked from mirrors/bookwyrm
only suggest local users as potential group members
This commit is contained in:
parent
2c399fe1aa
commit
29f18ee123
3 changed files with 23 additions and 6 deletions
|
@ -103,6 +103,28 @@ class SuggestedUsers(RedisStore):
|
||||||
break
|
break
|
||||||
return results
|
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):
|
def get_annotated_users(viewer, *args, **kwargs):
|
||||||
"""Users, annotated with things they have in common"""
|
"""Users, annotated with things they have in common"""
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input type="hidden" name="group" value="{{ group.id }}">
|
<input type="hidden" name="group" value="{{ group.id }}">
|
||||||
<input type="hidden" name="user" value="{{ user.username }}">
|
<input type="hidden" name="user" value="{{ user.username }}">
|
||||||
{% if user.local %}
|
|
||||||
<button class="button is-small{% if not minimal %} is-link{% endif %}" type="submit">
|
<button class="button is-small{% if not minimal %} is-link{% endif %}" type="submit">
|
||||||
{% if show_username %}
|
{% if show_username %}
|
||||||
{% blocktrans with username=user.localname %}Invite @{{ username }}{% endblocktrans %}
|
{% blocktrans with username=user.localname %}Invite @{{ username }}{% endblocktrans %}
|
||||||
|
@ -19,10 +18,6 @@
|
||||||
{% trans "Invite" %}
|
{% trans "Invite" %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</button>
|
</button>
|
||||||
{% else %}
|
|
||||||
<!-- TODO: This is an incredibly ugly hack until groups are AP enabled -->
|
|
||||||
<span><em>Remote User</em></span>
|
|
||||||
{% endif %}
|
|
||||||
</form>
|
</form>
|
||||||
<form action="{% url 'remove-group-member' %}" method="POST" class="interaction add_{{ user.id }} {% if not group|is_member:user and not group|is_invited:user %}is-hidden{% endif %}" data-id="add_{{ user.id }}">
|
<form action="{% url 'remove-group-member' %}" method="POST" class="interaction add_{{ user.id }} {% if not group|is_member:user and not group|is_invited:user %}is-hidden{% endif %}" data-id="add_{{ user.id }}">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|
|
@ -108,7 +108,7 @@ class FindUsers(View):
|
||||||
data = {"no_results": not user_results}
|
data = {"no_results": not user_results}
|
||||||
|
|
||||||
if user_results.count() < 5:
|
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
|
request.user
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue