diff --git a/bookwyrm/templates/snippets/block_button.html b/bookwyrm/templates/snippets/block_button.html new file mode 100644 index 000000000..ed9bb551f --- /dev/null +++ b/bookwyrm/templates/snippets/block_button.html @@ -0,0 +1,11 @@ +{% if not user in request.user.blocks.all %} +
+ {% csrf_token %} + +
+{% else %} +
+ {% csrf_token %} + +
+{% endif %} diff --git a/bookwyrm/templates/snippets/status_options.html b/bookwyrm/templates/snippets/status_options.html index 9b312c7ca..2e2e5d35b 100644 --- a/bookwyrm/templates/snippets/status_options.html +++ b/bookwyrm/templates/snippets/status_options.html @@ -17,14 +17,9 @@ -
  • -{% endif %} +{% else %}
  • - + {% include 'snippets/block_button.html' with user=status.user %}
  • +{% endif %} {% endblock %} diff --git a/bookwyrm/templates/snippets/user_header.html b/bookwyrm/templates/snippets/user_header.html index 14216d4be..8f5e264a4 100644 --- a/bookwyrm/templates/snippets/user_header.html +++ b/bookwyrm/templates/snippets/user_header.html @@ -35,11 +35,14 @@ {% if not is_self %} - {% include 'snippets/follow_button.html' with user=user %} -
    - {% csrf_token %} - -
    +
    +
    + {% include 'snippets/follow_button.html' with user=user %} +
    +
    + {% include 'snippets/user_options.html' with user=user class="is-small" %} +
    +
    {% endif %} {% if is_self and user.follower_requests.all %} diff --git a/bookwyrm/templates/snippets/user_options.html b/bookwyrm/templates/snippets/user_options.html new file mode 100644 index 000000000..9515d9128 --- /dev/null +++ b/bookwyrm/templates/snippets/user_options.html @@ -0,0 +1,14 @@ +{% extends 'snippets/components/dropdown.html' %} +{% load bookwyrm_tags %} + +{% block dropdown-trigger %} + + More options + +{% endblock %} + +{% block dropdown-list %} +
  • + {% include 'snippets/block_button.html' with user=user %} +
  • +{% endblock %} diff --git a/bookwyrm/views/block.py b/bookwyrm/views/block.py new file mode 100644 index 000000000..36f64f739 --- /dev/null +++ b/bookwyrm/views/block.py @@ -0,0 +1,29 @@ +''' views for actions you can take in the application ''' +from django.contrib.auth.decorators import login_required +from django.shortcuts import get_object_or_404, redirect +from django.utils.decorators import method_decorator +from django.views import View + +from bookwyrm import models +from bookwyrm.broadcast import broadcast + +# pylint: disable= no-self-use +@method_decorator(login_required, name='dispatch') +class Block(View): + ''' blocking users ''' + def get(self, request): + ''' list of blocked users? ''' + + def post(self, request, user_id): + ''' block a user ''' + to_block = get_object_or_404(models.User, id=user_id) + block = models.UserBlocks.objects.create( + user_subject=request.user, user_object=to_block) + if not to_block.local: + broadcast( + request.user, + block.to_activity(), + privacy='direct', + direct_recipients=[to_block] + ) + return redirect('/blocks') diff --git a/bookwyrm/views/helpers.py b/bookwyrm/views/helpers.py index b0f867b74..5872b2de5 100644 --- a/bookwyrm/views/helpers.py +++ b/bookwyrm/views/helpers.py @@ -72,9 +72,10 @@ def get_activity_feed( queryset = queryset.exclude(deleted=True).order_by('-published_date') # exclude blocks from both directions - blocked = models.User.objects.filter(id__in=user.blocks.all()).all() - queryset = queryset.exclude( - Q(user__in=blocked) | Q(user__blocks=user)) + if not user.is_anonymous: + blocked = models.User.objects.filter(id__in=user.blocks.all()).all() + queryset = queryset.exclude( + Q(user__in=blocked) | Q(user__blocks=user)) # you can't see followers only or direct messages if you're not logged in if user.is_anonymous: