From de2c5b710aadcce18276e973a3dff0073a499963 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Fri, 25 Oct 2024 13:14:56 +1300 Subject: [PATCH] instance block on user profile --- app/static/styles.css | 4 ++++ app/static/styles.scss | 4 ++++ app/templates/user/show_profile.html | 35 ++++++++++++++++++++-------- app/user/routes.py | 24 +++++++++++++++++++ 4 files changed, 57 insertions(+), 10 deletions(-) diff --git a/app/static/styles.css b/app/static/styles.css index 80fe04cc..483abd1c 100644 --- a/app/static/styles.css +++ b/app/static/styles.css @@ -514,6 +514,10 @@ a { display: none; } +.display-inline { + display: inline; +} + .skip-link { position: absolute; top: -40px; /* Adjust as needed to hide the link off-screen */ diff --git a/app/static/styles.scss b/app/static/styles.scss index 29d0130c..bb025d78 100644 --- a/app/static/styles.scss +++ b/app/static/styles.scss @@ -68,6 +68,10 @@ a { } } +.display-inline { + display: inline; +} + .skip-link { position: absolute; top: -40px; /* Adjust as needed to hide the link off-screen */ diff --git a/app/templates/user/show_profile.html b/app/templates/user/show_profile.html index 4a2b6066..3210316d 100644 --- a/app/templates/user/show_profile.html +++ b/app/templates/user/show_profile.html @@ -77,17 +77,32 @@ {% if user.matrix_user_id %} {{ _('Send message using Matrix') }} {% endif %} - {% if current_user.has_blocked_user(user.id) %} - {{ _('Unblock') }} - {% else %} - {{ _('Block') }} - {% endif %} - {{ _('Report') }} - {% endif %} - {% if user.is_local() %} - {{ _('Follow') }} - {% endif %} + {% if user.is_local() -%} + {{ _('Follow') }} + {% endif -%} + + + {% endif %}

{{ _('Instance') }}: {{ user.instance_domain() }}
{{ _('Joined') }}: {{ arrow.get(user.created).humanize(locale=locale) }}
diff --git a/app/user/routes.py b/app/user/routes.py index 141be32e..86a14e33 100644 --- a/app/user/routes.py +++ b/app/user/routes.py @@ -574,6 +574,29 @@ def block_profile(actor): return redirect(goto) +@bp.route('/u//block_instance', methods=['GET', 'POST']) +@login_required +def user_block_instance(actor): + actor = actor.strip() + user = User.query.filter_by(user_name=actor, deleted=False).first() + if user is None: + user = User.query.filter_by(ap_id=actor, deleted=False).first() + if user is None: + abort(404) + + if user.instance_id == 1: + flash(_('You cannot block your instance.'), 'error') + else: + existing = InstanceBlock.query.filter_by(user_id=current_user.id, instance_id=user.instance_id).first() + if not existing: + db.session.add(InstanceBlock(user_id=current_user.id, instance_id=user.instance_id)) + db.session.commit() + cache.delete_memoized(blocked_instances, current_user.id) + flash(_('Content from %(name)s will be hidden.', name=user.ap_domain)) + goto = request.args.get('redirect') if 'redirect' in request.args else f'/u/{actor}' + return redirect(goto) + + @bp.route('/u//unblock', methods=['GET']) @login_required def unblock_profile(actor): @@ -682,6 +705,7 @@ def delete_profile(actor): goto = request.args.get('redirect') if 'redirect' in request.args else f'/u/{actor}' return redirect(goto) + @bp.route('/instance//unblock', methods=['GET']) @login_required def instance_unblock(instance_id):