nsfw and nsfl icons on posts

This commit is contained in:
rimu 2024-02-16 06:17:13 +13:00
parent 5d20327598
commit 066646b4f6
8 changed files with 78 additions and 7 deletions

View file

@ -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()

View file

@ -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

View file

@ -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)]

View file

@ -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 */

View file

@ -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;
}
}

View file

@ -19,7 +19,7 @@
<button class="nav-link" id="link-tab" data-bs-toggle="tab" data-bs-target="#link-tab-pane"
type="button" role="tab" aria-controls="link-tab-pane" aria-selected="false">Link</button>
<button class="nav-link" id="image-tab" data-bs-toggle="tab" data-bs-target="#image-tab-pane"
type="button" role="tab" aria-controls="image-tab-pane" aria-selected="false" {{ images_disabled }}>Image</button>
type="button" role="tab" aria-controls="image-tab-pane" aria-selected="false">Image</button>
<button class="nav-link" id="poll-tab" data-bs-toggle="tab" data-bs-target="#poll-tab-pane"
type="button" role="tab" aria-controls="poll-tab-pane" aria-selected="false" disabled>Poll</button>
</div>

View file

@ -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 %}<span class="warning_badge nsfw" title="{{ _('Not safe for work') }}">nsfw</span>{% endif %}
{% if post.nsfl %}<span class="warning_badge nsfl" title="{{ _('Potentially emotionally scarring content') }}">nsfl</span>{% endif %}
</h1>
{% if post.url %}
<p><a href="{{ post.url }}" rel="nofollow ugc" target="_blank">{{ 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 %}<span class="warning_badge nsfw" title="{{ _('Not safe for work') }}">nsfw</span>{% endif %}
{% if post.nsfl %}<span class="warning_badge nsfl" title="{{ _('Potentially emotionally scarring content') }}">nsfl</span>{% endif %}
</h1>
{% if post.type == POST_TYPE_LINK and post.image_id and not (post.url and 'youtube.com' in post.url) %}
<div class="url_thumbnail">

View file

@ -45,6 +45,8 @@
{% endif %}
<span class="domain_link" aria-hidden="true">(<a href="/d/{{ post.domain_id }}" aria-label="{{ _('All posts about this domain') }}">{{ post.domain.name }}</a>)</span>
{% endif %}
{% if post.nsfw %}<span class="warning_badge nsfw" title="{{ _('Not safe for work') }}">nsfw</span>{% endif %}
{% if post.nsfl %}<span class="warning_badge nsfl" title="{{ _('Potentially emotionally scarring content') }}">nsfl</span>{% endif %}
{% if post.reports and current_user.is_authenticated and post.community.is_moderator(current_user) %}
<span class="red fe fe-report" title="{{ _('Reported. Check post for issues.') }}"></span>
{% endif %}