diff --git a/app/activitypub/util.py b/app/activitypub/util.py index 0f43e12e..52eefad2 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -1180,6 +1180,10 @@ def update_post_from_activity(post: Post, request_json: dict): post.body = html_to_markdown(post.body_html) if 'attachment' in request_json['object'] and 'href' in request_json['object']['attachment']: post.url = request_json['object']['attachment']['href'] + post.nsfw = request_json['object']['sensitive'] + if 'nsfl' in request_json['object']: + post.nsfl = request_json['object']['nsfl'] + post.comments_enabled = request_json['object']['commentsEnabled'] post.edited_at = utcnow() db.session.commit() diff --git a/app/community/forms.py b/app/community/forms.py index 27aaf9b0..fc05feb2 100644 --- a/app/community/forms.py +++ b/app/community/forms.py @@ -1,4 +1,4 @@ -from flask import request +from flask import request, g from flask_login import current_user from flask_wtf import FlaskForm from wtforms import StringField, SubmitField, TextAreaField, BooleanField, HiddenField, SelectField, FileField @@ -6,6 +6,7 @@ from wtforms.validators import ValidationError, DataRequired, Email, EqualTo, Le from flask_babel import _, lazy_gettext as _l from app import db +from app.models import Community from app.utils import domain_from_url, MultiCheckboxField from PIL import Image, ImageOps from io import BytesIO @@ -57,7 +58,7 @@ class CreatePostForm(FlaskForm): image_file = FileField(_('Image')) # flair = SelectField(_l('Flair'), coerce=int) nsfw = BooleanField(_l('NSFW')) - nsfl = BooleanField(_l('Content warning')) + nsfl = BooleanField(_l('Gore/gross')) notify_author = BooleanField(_l('Notify about replies')) submit = SubmitField(_l('Save')) @@ -102,6 +103,9 @@ class CreatePostForm(FlaskForm): current_user.reputation -= 1 db.session.commit() return False + community = Community.query.get(self.communities.data).first() + if community.is_local() and g.site.allow_local_image_posts is False: + self.communities.errors.append(_('Images cannot be posted to local communities.')) elif self.post_type.data == 'poll': self.discussion_title.errors.append(_('Poll not implemented yet.')) return False diff --git a/app/community/routes.py b/app/community/routes.py index 9bf9287e..0350e43c 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -392,8 +392,6 @@ def join_then_add(actor): def add_post(actor): community = actor_to_community(actor) form = CreatePostForm() - if g.site.enable_nsfw is False: - form.nsfw.render_kw = {'disabled': True} if g.site.enable_nsfl is False: form.nsfl.render_kw = {'disabled': True} if community.nsfw: @@ -402,7 +400,6 @@ def add_post(actor): if community.nsfl: form.nsfl.data = True form.nsfw.render_kw = {'disabled': True} - images_disabled = 'disabled' if not get_setting('allow_local_image_posts', True) else '' # bug: this will disable posting of images to *remote* hosts too form.communities.choices = [(c.id, c.display_name()) for c in current_user.communities()] @@ -515,7 +512,7 @@ def add_post(actor): form.notify_author.data = True return render_template('community/add_post.html', title=_('Add post to community'), form=form, community=community, - images_disabled=images_disabled, markdown_editor=True, low_bandwidth=request.cookies.get('low_bandwidth', '0') == '1', + markdown_editor=True, low_bandwidth=request.cookies.get('low_bandwidth', '0') == '1', moderating_communities=moderating_communities(current_user.get_id()), joined_communities=joined_communities(current_user.id), inoculation=inoculation[randint(0, len(inoculation) - 1)] diff --git a/app/static/structure.css b/app/static/structure.css index 88f5b7a1..bff9c1fd 100644 --- a/app/static/structure.css +++ b/app/static/structure.css @@ -1177,4 +1177,32 @@ fieldset legend { vertical-align: middle; } +.warning_badge { + font-size: 12px; + border-radius: 2px; + margin-right: 2px; + overflow: hidden; + text-overflow: ellipsis; + vertical-align: text-bottom; + line-height: 20px; + padding: 0 4px; +} +.warning_badge.nsfw { + border: 1px solid #FF585B; + color: #FF585B; +} +.warning_badge.nsfl { + border: 1px solid black; + color: black; +} + +[data-bs-theme=dark] .warning_badge.nsfl { + border: 1px solid white; + color: white; +} + +.post_title .warning_badge { + line-height: 32px; +} + /*# sourceMappingURL=structure.css.map */ diff --git a/app/static/structure.scss b/app/static/structure.scss index ae95514f..feb3bc51 100644 --- a/app/static/structure.scss +++ b/app/static/structure.scss @@ -863,3 +863,35 @@ fieldset { } } } + +.warning_badge { + font-size: 12px; + border-radius: 2px; + margin-right: 2px; + overflow: hidden; + text-overflow: ellipsis; + vertical-align: text-bottom; + line-height: 20px; + padding: 0 4px; + + &.nsfw { + border:1px solid #FF585B; + color:#FF585B; + } + + &.nsfl { + border:1px solid black; + color:black; + } +} +[data-bs-theme=dark] .warning_badge.nsfl { + border:1px solid white; + color:white; +} + +.post_title { + .warning_badge { + line-height: 32px; + } +} + diff --git a/app/templates/community/add_post.html b/app/templates/community/add_post.html index 2a037418..f5f1c0de 100644 --- a/app/templates/community/add_post.html +++ b/app/templates/community/add_post.html @@ -19,7 +19,7 @@ + type="button" role="tab" aria-controls="image-tab-pane" aria-selected="false">Image diff --git a/app/templates/post/_post_full.html b/app/templates/post/_post_full.html index f353e1cc..b293242c 100644 --- a/app/templates/post/_post_full.html +++ b/app/templates/post/_post_full.html @@ -19,6 +19,8 @@ {% if current_user.is_authenticated and post.user_id == current_user.id %} {% include 'post/_post_notification_toggle.html' %} {% endif %} + {% if post.nsfw %}nsfw{% endif %} + {% if post.nsfl %}nsfl{% endif %} {% if post.url %}

{{ post.url|shorten_url }} @@ -66,6 +68,8 @@ {% if current_user.is_authenticated and post.user_id == current_user.id %} {% include 'post/_post_notification_toggle.html' %} {% endif %} + {% if post.nsfw %}nsfw{% endif %} + {% if post.nsfl %}nsfl{% endif %} {% if post.type == POST_TYPE_LINK and post.image_id and not (post.url and 'youtube.com' in post.url) %}

diff --git a/app/templates/post/_post_teaser.html b/app/templates/post/_post_teaser.html index cfaab6f2..17c3db2b 100644 --- a/app/templates/post/_post_teaser.html +++ b/app/templates/post/_post_teaser.html @@ -45,6 +45,8 @@ {% endif %} {{ post.domain.name }}) {% endif %} + {% if post.nsfw %}nsfw{% endif %} + {% if post.nsfl %}nsfl{% endif %} {% if post.reports and current_user.is_authenticated and post.community.is_moderator(current_user) %} {% endif %}