From 4d31412e753303c8059c2e890d27c8593af7527b Mon Sep 17 00:00:00 2001 From: Jason McBrayer Date: Mon, 11 Jun 2018 19:38:49 -0400 Subject: [PATCH] Add blocking and muting --- brutaldon/templates/main/block.html | 58 +++++++++++++++++++++++++++++ brutaldon/templates/main/mute.html | 58 +++++++++++++++++++++++++++++ brutaldon/templates/main/user.html | 4 +- brutaldon/urls.py | 2 +- brutaldon/views.py | 45 ++++++++++++++++++++-- 5 files changed, 161 insertions(+), 6 deletions(-) create mode 100644 brutaldon/templates/main/block.html create mode 100644 brutaldon/templates/main/mute.html diff --git a/brutaldon/templates/main/block.html b/brutaldon/templates/main/block.html new file mode 100644 index 0000000..257bfcb --- /dev/null +++ b/brutaldon/templates/main/block.html @@ -0,0 +1,58 @@ +{% extends "base.html" %} +{% load taglinks %} +{% load sanitizer %} + +{% block title %}Brutaldon - confirm (un)block {% endblock %} + +{% block content %} + {% if relationship.blocking %} +

Unblock this user?

+ {% else %} +

Block this user?

+ {% endif %} + +
+
+

+ + + +

+
+
+
+

+ {{ user.display_name }} + + + @{{ user.acct }} + + +

+ {{ user.note | relink_toot | strip_html | safe }} +

+

+ +
+
+
+ +
+ {% csrf_token %} +
+
+
+ +
+
+
+
+ +
+
+
+
+ +{% endblock %} diff --git a/brutaldon/templates/main/mute.html b/brutaldon/templates/main/mute.html new file mode 100644 index 0000000..5918be7 --- /dev/null +++ b/brutaldon/templates/main/mute.html @@ -0,0 +1,58 @@ +{% extends "base.html" %} +{% load taglinks %} +{% load sanitizer %} + +{% block title %}Brutaldon - confirm (un)mute {% endblock %} + +{% block content %} + {% if relationship.muting %} +

Unmute this user?

+ {% else %} +

Mute this user?

+ {% endif %} + +
+
+

+ + + +

+
+
+
+

+ {{ user.display_name }} + + + @{{ user.acct }} + + +

+ {{ user.note | relink_toot | strip_html | safe }} +

+

+ +
+
+
+ +
+ {% csrf_token %} +
+
+
+ +
+
+
+
+ +
+
+
+
+ +{% endblock %} diff --git a/brutaldon/templates/main/user.html b/brutaldon/templates/main/user.html index 55735c4..4be698c 100644 --- a/brutaldon/templates/main/user.html +++ b/brutaldon/templates/main/user.html @@ -4,7 +4,7 @@ {% load taglinks %} {% block title %} -Brutaldon - {{ timeline }} timelime +Brutaldon - {{ user.acct }} timelime {% endblock %} {% block content %} @@ -33,6 +33,7 @@ Brutaldon - {{ timeline }} timelime
{{ user.note | relink_toot | strip_html | safe }}
+ {% if user.acct != own_username %}
{% if relationship.requested %} @@ -85,6 +86,7 @@ Brutaldon - {{ timeline }} timelime {% endif %}
+ {% endif %} diff --git a/brutaldon/urls.py b/brutaldon/urls.py index 5fb039b..ecc0f2e 100644 --- a/brutaldon/urls.py +++ b/brutaldon/urls.py @@ -48,7 +48,7 @@ urlpatterns = [ path('delete/', views.delete, name='delete'), path('follow/', views.follow, name='follow'), path('block/', views.block, name='block'), - path('mute/', views.follow, name='mute'), + path('mute/', views.mute, name='mute'), path('search', views.search, name='search'), path('search_results', views.search_results, name='search_results'), path('', views.home), diff --git a/brutaldon/views.py b/brutaldon/views.py index 508b5be..636bca5 100644 --- a/brutaldon/views.py +++ b/brutaldon/views.py @@ -443,16 +443,53 @@ def follow(request, id): return redirect(user, user_dict.acct) else: return render(request, 'main/follow.html', - {"user": user_dict, "relationship": relationship, "confirm_page": True, - 'fullbrutalism': fullbrutalism_p(request)}) + {"user": user_dict, "relationship": relationship, + "confirm_page": True, + 'fullbrutalism': fullbrutalism_p(request)}) @never_cache def block(request, id): - pass + mastodon = get_mastodon(request) + try: + user_dict = mastodon.account(id) + relationship = mastodon.account_relationships(user_dict.id)[0] + except IndexError: + raise Http404("The user could not be found.") + if request.method == 'POST': + if not request.POST.get('cancel', None): + if relationship.blocking: + mastodon.account_unblock(id) + else: + mastodon.account_block(id) + return redirect(user, user_dict.acct) + else: + return render(request, 'main/block.html', + {"user": user_dict, "relationship": relationship, + "confirm_page": True, + 'fullbrutalism': fullbrutalism_p(request)}) + @never_cache def mute(request, id): - pass + mastodon = get_mastodon(request) + try: + user_dict = mastodon.account(id) + relationship = mastodon.account_relationships(user_dict.id)[0] + except IndexError: + raise Http404("The user could not be found.") + if request.method == 'POST': + if not request.POST.get('cancel', None): + if relationship.muting: + mastodon.account_unmute(id) + else: + mastodon.account_mute(id) + return redirect(user, user_dict.acct) + else: + return render(request, 'main/mute.html', + {"user": user_dict, "relationship": relationship, + "confirm_page": True, + 'fullbrutalism': fullbrutalism_p(request)}) + def search(request): return render(request, 'main/search.html',