Remove suggested users on block

This commit is contained in:
Mouse Reeve 2021-05-22 14:05:59 -07:00
parent 9250b8b85d
commit 644e5926db
3 changed files with 18 additions and 7 deletions

View file

@ -132,6 +132,16 @@ def update_suggestions_on_follow(sender, instance, created, *args, **kwargs):
suggested_users.rerank_obj(instance.user_object)
@receiver(signals.post_save, sender=models.UserBlocks)
# pylint: disable=unused-argument
def update_suggestions_on_block(sender, instance, *args, **kwargs):
"""remove blocked users from recs"""
if instance.user_subject.local:
suggested_users.remove_suggestion(instance.user_subject, instance.user_object)
if instance.user_object.local:
suggested_users.remove_suggestion(instance.user_object, instance.user_subject)
@receiver(signals.post_delete, sender=models.UserFollows)
# pylint: disable=unused-argument
def update_suggestions_on_unfollow(sender, instance, **kwargs):
@ -163,7 +173,7 @@ def add_new_user(sender, instance, created, **kwargs):
# a new user is found, create suggestions for them
suggested_users.rerank_user_suggestions(instance)
# TODO: this happens on every save, not just when discoverability changes
# this happens on every save, not just when discoverability changes, annoyingly
if instance.discoverable:
suggested_users.rerank_obj(instance, update_only=False)
elif not created:

View file

@ -9,7 +9,7 @@
<form class="field has-addons" method="get" action="{% url 'get-started-users' %}">
<div class="control">
<input type="text" name="query" value="{{ request.GET.query }}" class="input" placeholder="{% trans 'Search for a user' %}" aria-label="{% trans 'Search for a user' %}">
{% if request.GET.query and not user_results %}
{% if request.GET.query and no_results %}
<p class="help">{% blocktrans with query=request.GET.query %}No users found for "{{ query }}"{% endblocktrans %}</p>
{% endif %}
</div>

View file

@ -13,6 +13,7 @@ from django.views import View
from bookwyrm import forms, models
from bookwyrm.connectors import connector_manager
from bookwyrm.suggested_users import suggested_users
from .user import save_user_form
@ -117,12 +118,12 @@ class GetStartedUsers(View):
)
.order_by("-similarity")[:5]
)
data = {"no_results": not user_results}
if user_results.count() < 5:
suggested_users = [] # TODO: get_suggested_users(request.user)
user_results = list(user_results) + list(suggested_users)
user_results = list(user_results) + suggested_users.get_suggestions(
request.user
)
data = {
"suggested_users": user_results,
}
data["suggested_users"] = user_results
return TemplateResponse(request, "get_started/users.html", data)