From a7fa609ddfbe14c8cc697ef8637c3a624db3729e Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Fri, 28 Jun 2024 13:22:15 +0200 Subject: [PATCH] add blur and transparent options to the nsfw, nsfw and bots filter --- app/admin/forms.py | 20 +++++++++++++++++++- app/admin/routes.py | 8 ++++++-- app/cli.py | 6 +++--- app/community/routes.py | 6 +++--- app/domain/routes.py | 2 +- app/main/routes.py | 20 ++++++++++---------- app/models.py | 6 +++--- app/post/util.py | 2 +- app/search/routes.py | 6 +++--- app/tag/routes.py | 4 ++-- app/templates/admin/edit_user.html | 6 +++--- app/topic/routes.py | 6 +++--- app/user/forms.py | 16 ++++++++++------ 13 files changed, 67 insertions(+), 41 deletions(-) diff --git a/app/admin/forms.py b/app/admin/forms.py index 3dbebf0e..8a08f153 100644 --- a/app/admin/forms.py +++ b/app/admin/forms.py @@ -125,7 +125,17 @@ class AddUserForm(FlaskForm): verified = BooleanField(_l('Email address is verified')) banned = BooleanField(_l('Banned')) newsletter = BooleanField(_l('Subscribe to email newsletter')) - ignore_bots = BooleanField(_l('Hide posts by bots')) + hide_type_choices = [(0, _l('Show')), + (1, _l('Hide completely')), + (2, _l('Blur')), + (3, _l('Make semi-transparent'))] + ignore_bots = SelectField(_l('Hide posts by bots'), choices=hide_type_choices, + default=0, coerce=int, render_kw={'class': 'form-select'}) + show_nsfw = SelectField(_l('Show NSFW posts'), choices=hide_type_choices, default=1, + coerce=int, render_kw={'class': 'form-select'}) + show_nsfl = SelectField(_l('Show NSFL posts'), choices=hide_type_choices, default=1, + coerce=int, render_kw={'class': 'form-select'}) + nsfw = BooleanField(_l('Show NSFW posts')) nsfl = BooleanField(_l('Show NSFL posts')) role_options = [(2, _l('User')), @@ -178,6 +188,14 @@ class EditUserForm(FlaskForm): bot = BooleanField(_l('This profile is a bot')) verified = BooleanField(_l('Email address is verified')) banned = BooleanField(_l('Banned')) + hide_type_choices = [(0, _l('Show')), + (1, _l('Hide completely')), + (2, _l('Blur')), + (3, _l('Make semi-transparent'))] + show_nsfw = SelectField(_l('Show NSFW posts'), choices=hide_type_choices, default=1, + coerce=int, render_kw={'class': 'form-select'}) + show_nsfl = SelectField(_l('Show NSFL posts'), choices=hide_type_choices, default=1, + coerce=int, render_kw={'class': 'form-select'}) role_options = [(2, _l('User')), (3, _l('Staff')), (4, _l('Admin')), diff --git a/app/admin/routes.py b/app/admin/routes.py index 94986f48..ccfb54ac 100644 --- a/app/admin/routes.py +++ b/app/admin/routes.py @@ -743,6 +743,8 @@ def admin_user_edit(user_id): if form.validate_on_submit(): user.bot = form.bot.data user.banned = form.banned.data + user.show_nsfw = form.show_nsfw.data + user.show_nsfl = form.show_nsfl.data if form.verified.data and not user.verified: finalize_user_setup(user) user.verified = form.verified.data @@ -774,6 +776,8 @@ def admin_user_edit(user_id): form.bot.data = user.bot form.verified.data = user.verified form.banned.data = user.banned + form.show_nsfw.data = user.show_nsfw + form.show_nsfl.data = user.show_nsfl if user.roles and user.roles.count() > 0: form.role.data = user.roles[0].id @@ -828,8 +832,8 @@ def admin_users_add(): user.cover = file user.newsletter = form.newsletter.data user.ignore_bots = form.ignore_bots.data - user.show_nsfw = form.nsfw.data - user.show_nsfl = form.nsfl.data + user.show_nsfw = form.show_nsfw.data + user.show_nsfl = form.show_nsfl.data user.instance_id = 1 user.roles.append(Role.query.get(form.role.data)) diff --git a/app/cli.py b/app/cli.py index c659f3c0..6d610f9c 100644 --- a/app/cli.py +++ b/app/cli.py @@ -330,11 +330,11 @@ def register(app): posts = Post.query.join(CommunityMember, Post.community_id == CommunityMember.community_id).filter( CommunityMember.is_banned == False) posts = posts.filter(CommunityMember.user_id == user.id) - if user.ignore_bots: + if user.ignore_bots == 1: posts = posts.filter(Post.from_bot == False) - if user.show_nsfl is False: + if user.show_nsfl == 1: posts = posts.filter(Post.nsfl == False) - if user.show_nsfw is False: + if user.show_nsfw == 1: posts = posts.filter(Post.nsfw == False) domains_ids = blocked_domains(user.id) if domains_ids: diff --git a/app/community/routes.py b/app/community/routes.py index 5b0ac926..1d51014c 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -201,11 +201,11 @@ def show_community(community: Community): posts = posts.filter(Post.from_bot == False, Post.nsfw == False, Post.nsfl == False, Post.deleted == False) content_filters = {} else: - if current_user.ignore_bots: + if current_user.ignore_bots == 1: posts = posts.filter(Post.from_bot == False) - if current_user.show_nsfl is False: + if current_user.show_nsfl == 1: posts = posts.filter(Post.nsfl == False) - if current_user.show_nsfw is False: + if current_user.show_nsfw == 1: posts = posts.filter(Post.nsfw == False) content_filters = user_filters_posts(current_user.id) posts = posts.filter(Post.deleted == False) diff --git a/app/domain/routes.py b/app/domain/routes.py index cd96ca17..b031adb0 100644 --- a/app/domain/routes.py +++ b/app/domain/routes.py @@ -24,7 +24,7 @@ def show_domain(domain_id): if domain.banned: domain = None if domain: - if current_user.is_anonymous or current_user.ignore_bots: + if current_user.is_anonymous or current_user.ignore_bots == 1: posts = Post.query.join(Community, Community.id == Post.community_id).\ filter(Post.from_bot == False, Post.domain_id == domain.id, Community.banned == False, Post.deleted == False).\ order_by(desc(Post.posted_at)) diff --git a/app/main/routes.py b/app/main/routes.py index 66be9248..070ceb47 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -97,11 +97,11 @@ def home_page(type, sort): posts = posts.join(Community, Community.id == Post.community_id) posts = posts.filter(Community.show_all == True, Post.deleted == False) - if current_user.ignore_bots: + if current_user.ignore_bots == 1: posts = posts.filter(Post.from_bot == False) - if current_user.show_nsfl is False: + if current_user.show_nsfl == 1: posts = posts.filter(Post.nsfl == False) - if current_user.show_nsfw is False: + if current_user.show_nsfw == 1: posts = posts.filter(Post.nsfw == False) domains_ids = blocked_domains(current_user.id) @@ -211,9 +211,9 @@ def list_communities(): banned_from = communities_banned_from(current_user.id) if banned_from: communities = communities.filter(Community.id.not_in(banned_from)) - if not current_user.show_nsfw: + if current_user.show_nsfw == 1: communities = communities.filter(Community.nsfw == False) - if not current_user.show_nsfl: + if current_user.show_nsfl == 1: communities = communities.filter(Community.nsfl == False) else: communities = communities.filter(and_(Community.nsfw == False, Community.nsfl == False)) @@ -263,9 +263,9 @@ def list_local_communities(): banned_from = communities_banned_from(current_user.id) if banned_from: communities = communities.filter(Community.id.not_in(banned_from)) - if not current_user.show_nsfw: + if current_user.show_nsfw == 1: communities = communities.filter(Community.nsfw == False) - if not current_user.show_nsfl: + if current_user.show_nsfl == 1: communities = communities.filter(Community.nsfl == False) else: communities = communities.filter(and_(Community.nsfw == False, Community.nsfl == False)) @@ -440,11 +440,11 @@ def test(): posts = Post.query.join(CommunityMember, Post.community_id == CommunityMember.community_id).filter( CommunityMember.is_banned == False) posts = posts.filter(CommunityMember.user_id == user.id) - if user.ignore_bots: + if user.ignore_bots == 1: posts = posts.filter(Post.from_bot == False) - if user.show_nsfl is False: + if user.show_nsfl == 1: posts = posts.filter(Post.nsfl == False) - if user.show_nsfw is False: + if user.show_nsfw == 1: posts = posts.filter(Post.nsfw == False) domains_ids = blocked_domains(user.id) if domains_ids: diff --git a/app/models.py b/app/models.py index 38561343..6032d4ea 100644 --- a/app/models.py +++ b/app/models.py @@ -585,8 +585,8 @@ class User(UserMixin, db.Model): about_html = db.Column(db.Text) # html keywords = db.Column(db.String(256)) matrix_user_id = db.Column(db.String(256)) - show_nsfw = db.Column(db.Boolean, default=False) - show_nsfl = db.Column(db.Boolean, default=False) + show_nsfw = db.Column(db.Integer, default=1) + show_nsfl = db.Column(db.Integer, default=1) created = db.Column(db.DateTime, default=utcnow) last_seen = db.Column(db.DateTime, default=utcnow, index=True) avatar_id = db.Column(db.Integer, db.ForeignKey('file.id'), index=True) @@ -606,7 +606,7 @@ class User(UserMixin, db.Model): searchable = db.Column(db.Boolean, default=True) indexable = db.Column(db.Boolean, default=False) bot = db.Column(db.Boolean, default=False) - ignore_bots = db.Column(db.Boolean, default=False) + ignore_bots = db.Column(db.Integer, default=0) unread_notifications = db.Column(db.Integer, default=0) ip_address = db.Column(db.String(50)) instance_id = db.Column(db.Integer, db.ForeignKey('instance.id'), index=True) diff --git a/app/post/util.py b/app/post/util.py index 8ab4ca9f..f1768cdc 100644 --- a/app/post/util.py +++ b/app/post/util.py @@ -16,7 +16,7 @@ def post_replies(post_id: int, sort_by: str, show_first: int = 0) -> List[PostRe instance_ids = blocked_instances(current_user.id) if instance_ids: comments = comments.filter(or_(PostReply.instance_id.not_in(instance_ids), PostReply.instance_id == None)) - if current_user.ignore_bots: + if current_user.ignore_bots == 1: comments = comments.filter(PostReply.from_bot == False) blocked_accounts = blocked_users(current_user.id) if blocked_accounts: diff --git a/app/search/routes.py b/app/search/routes.py index 9e1b4f46..23f27e30 100644 --- a/app/search/routes.py +++ b/app/search/routes.py @@ -30,11 +30,11 @@ def run_search(): posts = Post.query.search(q) if current_user.is_authenticated: - if current_user.ignore_bots: + if current_user.ignore_bots == 1: posts = posts.filter(Post.from_bot == False) - if current_user.show_nsfl is False: + if current_user.show_nsfl == 1: posts = posts.filter(Post.nsfl == False) - if current_user.show_nsfw is False: + if current_user.show_nsfw == 1: posts = posts.filter(Post.nsfw == False) domains_ids = blocked_domains(current_user.id) if domains_ids: diff --git a/app/tag/routes.py b/app/tag/routes.py index 42f2c8a4..144af064 100644 --- a/app/tag/routes.py +++ b/app/tag/routes.py @@ -26,7 +26,7 @@ def show_tag(tag): join(post_tag, post_tag.c.post_id == Post.id).filter(post_tag.c.tag_id == tag.id). \ filter(Community.banned == False, Post.deleted == False) - if current_user.is_anonymous or current_user.ignore_bots: + if current_user.is_anonymous or current_user.ignore_bots == 1: posts = posts.filter(Post.from_bot == False) if current_user.is_authenticated: @@ -75,7 +75,7 @@ def show_tag_rss(tag): join(post_tag, post_tag.c.post_id == Post.id).filter(post_tag.c.tag_id == tag.id). \ filter(Community.banned == False, Post.deleted == False) - if current_user.is_anonymous or current_user.ignore_bots: + if current_user.is_anonymous or current_user.ignore_bots == 1: posts = posts.filter(Post.from_bot == False) posts = posts.order_by(desc(Post.posted_at)).limit(100).all() diff --git a/app/templates/admin/edit_user.html b/app/templates/admin/edit_user.html index 23ae1a81..e276c43f 100644 --- a/app/templates/admin/edit_user.html +++ b/app/templates/admin/edit_user.html @@ -27,8 +27,8 @@ {{ render_field(form.verified) }} {{ render_field(form.banned) }}

receive newsletter: {{ user.newsletter }}

-

view nsfw: {{ user.show_nsfw }}

-

view nsfl: {{ user.show_nsfl }}

+ {{ render_field(form.show_nsfw) }} + {{ render_field(form.show_nsfl) }}

searchable: {{ user.searchable }}

indexable: {{ user.indexable }}

{{ render_field(form.role) }} @@ -50,4 +50,4 @@
-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/app/topic/routes.py b/app/topic/routes.py index b0f00c76..91430832 100644 --- a/app/topic/routes.py +++ b/app/topic/routes.py @@ -57,11 +57,11 @@ def show_topic(topic_path): posts = posts.filter(Post.from_bot == False, Post.nsfw == False, Post.nsfl == False, Post.deleted == False) content_filters = {} else: - if current_user.ignore_bots: + if current_user.ignore_bots == 1: posts = posts.filter(Post.from_bot == False) - if current_user.show_nsfl is False: + if current_user.show_nsfl == 1: posts = posts.filter(Post.nsfl == False) - if current_user.show_nsfw is False: + if current_user.show_nsfw == 1: posts = posts.filter(Post.nsfw == False) posts = posts.filter(Post.deleted == False) content_filters = user_filters_posts(current_user.id) diff --git a/app/user/forms.py b/app/user/forms.py index 0d1db99b..c7448b58 100644 --- a/app/user/forms.py +++ b/app/user/forms.py @@ -35,9 +35,6 @@ class SettingsForm(FlaskForm): interface_language = SelectField(_l('Interface language'), coerce=str, validators=[Optional()], render_kw={'class': 'form-select'}) newsletter = BooleanField(_l('Subscribe to email newsletter')) email_unread = BooleanField(_l('Receive email about missed notifications')) - ignore_bots = BooleanField(_l('Hide posts by bots')) - nsfw = BooleanField(_l('Show NSFW posts')) - nsfl = BooleanField(_l('Show NSFL posts')) reply_collapse_threshold = IntegerField(_l('Reply collapse threshold')) reply_hide_threshold = IntegerField(_l('Reply hide threshold')) markdown_editor = BooleanField(_l('Use markdown editor GUI when writing')) @@ -90,9 +87,16 @@ class ReportUserForm(FlaskForm): class FilterForm(FlaskForm): - ignore_bots = BooleanField(_l('Hide posts by bots')) - show_nsfw = BooleanField(_l('Show NSFW posts')) - show_nsfl = BooleanField(_l('Show NSFL posts')) + hide_type_choices = [(0, _l('Show')), + (1, _l('Hide completely')), + (2, _l('Blur')), + (3, _l('Make semi-transparent'))] + ignore_bots = SelectField(_l('Hide posts by bots'), choices=hide_type_choices, + default=0, coerce=int, render_kw={'class': 'form-select'}) + show_nsfw = SelectField(_l('Show NSFW posts'), choices=hide_type_choices, + default=1, coerce=int, render_kw={'class': 'form-select'}) + show_nsfl = SelectField(_l('Show NSFL posts'), choices=hide_type_choices, + default=1, coerce=int, render_kw={'class': 'form-select'}) submit = SubmitField(_l('Save settings'))