From 8bd657b726a01dbc8f9d2e673a25f53ee94c9cd2 Mon Sep 17 00:00:00 2001 From: Aevann Date: Sat, 24 Jun 2023 20:39:50 +0300 Subject: [PATCH] add /blockers and /blocking to profile pages --- files/routes/users.py | 27 +++++++++++-- files/templates/settings/blocks.html | 3 +- files/templates/userpage/banner.html | 4 +- files/templates/userpage/blocked.html | 20 ++++++++++ files/templates/userpage/blockers.html | 2 - files/templates/userpage/blocking.html | 52 +++++++++++++++++--------- 6 files changed, 82 insertions(+), 26 deletions(-) create mode 100644 files/templates/userpage/blocked.html diff --git a/files/routes/users.py b/files/routes/users.py index b5ff675c8..6c02bfc5d 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -762,6 +762,25 @@ def blockers(v:User, username:str): return render_template("userpage/blockers.html", v=v, u=u, users=users, page=page, total=total) +@app.get("/@/blocking") +@limiter.limit(DEFAULT_RATELIMIT) +@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID) +@auth_required +def blocking(v:User, username:str): + u = get_user(username, v=v) + + page = get_page() + + users = g.db.query(UserBlock, User).join(UserBlock, UserBlock.user_id == u.id) \ + .filter(UserBlock.target_id == User.id) + + total = users.count() + + users = users.order_by(UserBlock.created_utc.desc()) \ + .offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE ).all() + + return render_template("userpage/blocking.html", v=v, u=u, users=users, page=page, total=total) + @app.get("/@/followers") @limiter.limit(DEFAULT_RATELIMIT) @limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID) @@ -842,7 +861,7 @@ def u_username_wall(v:Optional[User], username:str): if v and hasattr(u, 'is_blocking') and u.is_blocking: if g.is_api_or_xhr: abort(403, f"You are blocking @{u.username}.") - return render_template("userpage/blocking.html", u=u, v=v), 403 + return render_template("userpage/blocked.html", u=u, v=v), 403 is_following = v and u.has_follower(v) @@ -892,7 +911,7 @@ def u_username_wall_comment(v:User, username:str, cid): if v and hasattr(u, 'is_blocking') and u.is_blocking: if g.is_api_or_xhr: abort(403, f"You are blocking @{u.username}.") - return render_template("userpage/blocking.html", u=u, v=v), 403 + return render_template("userpage/blocked.html", u=u, v=v), 403 is_following = v and u.has_follower(v) @@ -939,7 +958,7 @@ def u_username(v:Optional[User], username:str): if v and hasattr(u, 'is_blocking') and u.is_blocking: if g.is_api_or_xhr: abort(403, f"You are blocking @{u.username}.") - return render_template("userpage/blocking.html", u=u, v=v), 403 + return render_template("userpage/blocked.html", u=u, v=v), 403 is_following = v and u.has_follower(v) @@ -1010,7 +1029,7 @@ def u_username_comments(username, v=None): if v and hasattr(u, 'is_blocking') and u.is_blocking: if g.is_api_or_xhr: abort(403, f"You are blocking @{u.username}.") - return render_template("userpage/blocking.html", u=u, v=v), 403 + return render_template("userpage/blocked.html", u=u, v=v), 403 is_following = v and u.has_follower(v) diff --git a/files/templates/settings/blocks.html b/files/templates/settings/blocks.html index 06cae7933..cfd2bb3c1 100644 --- a/files/templates/settings/blocks.html +++ b/files/templates/settings/blocks.html @@ -1,7 +1,6 @@ {% extends "settings.html" %} {% block pagetitle %}Blocks{% endblock %} {% block content %} -
@@ -79,4 +78,6 @@ Error. Please try again.
+ + {% endblock %} diff --git a/files/templates/userpage/banner.html b/files/templates/userpage/banner.html index c89f8e96e..e90fd1704 100644 --- a/files/templates/userpage/banner.html +++ b/files/templates/userpage/banner.html @@ -72,7 +72,7 @@ {% if v and (v.id == u.id or v.admin_level >= PERMS['USER_VOTERS_VISIBLE']) -%} {%- endif %} @@ -354,7 +354,7 @@ {% if v and (v.id == u.id or v.admin_level >= PERMS['USER_VOTERS_VISIBLE']) -%} {%- endif %} diff --git a/files/templates/userpage/blocked.html b/files/templates/userpage/blocked.html new file mode 100644 index 000000000..b1fa55c19 --- /dev/null +++ b/files/templates/userpage/blocked.html @@ -0,0 +1,20 @@ +{% extends "default.html" %} + +{% block pagetype %}userpage{% endblock %} +{% block pagetitle %}@{{u.username}}{% endblock %} +{% block content %} +
+
+
+ + + + +
You are blocking @{{u.username}}.
+

So we aren't going to show you their profile.

+
+
+
+{% endblock %} +{% block pagenav %}{% endblock %} diff --git a/files/templates/userpage/blockers.html b/files/templates/userpage/blockers.html index 1305ddb38..dd4f848db 100644 --- a/files/templates/userpage/blockers.html +++ b/files/templates/userpage/blockers.html @@ -19,8 +19,6 @@ - - {% endblock %} {% block pagenav %} diff --git a/files/templates/userpage/blocking.html b/files/templates/userpage/blocking.html index b1fa55c19..234a545ec 100644 --- a/files/templates/userpage/blocking.html +++ b/files/templates/userpage/blocking.html @@ -1,20 +1,38 @@ {% extends "default.html" %} - -{% block pagetype %}userpage{% endblock %} -{% block pagetitle %}@{{u.username}}{% endblock %} +{% block pagetitle %}Users blocked by @{{u.username}}{% endblock %} {% block content %} -
-
-
- - - - -
You are blocking @{{u.username}}.
-

So we aren't going to show you their profile.

-
-
-
+
Users blocked by @{{u.username}}
+
+ + + + + {% if v.id == u.id %} + + {% endif %} + + + +{% for block, user in users %} + + + + {% if v.id == u.id %} + + {% endif %} + +{% endfor %} + +
NameBlocking since
{% include "user_in_table.html" %} 1599343262 %}data-time="{{block.created_utc}}"{% endif %}> + +
+ +{% if v.id == u.id %} + +{% endif %} + +{% endblock %} + +{% block pagenav %} +{% include "pagination.html" %} {% endblock %} -{% block pagenav %}{% endblock %}