add: nsfw marker for posts/communities
This commit is contained in:
parent
f83cfa3756
commit
51534fbd52
8 changed files with 49 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
|||
{% extends "root.html" %} {% block body %}
|
||||
{% import "macros.html" as macros %} {% extends "root.html" %} {% block body %}
|
||||
<main class="flex flex-col gap-2" style="max-width: 25rem">
|
||||
<h2 class="w-full text-center">{% block title %}{% endblock %}</h2>
|
||||
<div class="card w-full flex flex-col gap-4 justify-center align-center">
|
||||
|
|
|
@ -16,13 +16,26 @@
|
|||
community=community, size="72px") }}
|
||||
<div class="flex flex-col">
|
||||
<div class="flex gap-2 items-center">
|
||||
<h3 id="title" class="title name shorter">
|
||||
<h3
|
||||
id="title"
|
||||
class="title name shorter flex gap-2"
|
||||
>
|
||||
<!-- prettier-ignore -->
|
||||
{% if community.context.display_name %}
|
||||
{{ community.context.display_name }}
|
||||
{% else %}
|
||||
{{ community.title }}
|
||||
{% endif %}
|
||||
|
||||
{% if community.context.is_nsfw %}
|
||||
<span
|
||||
title="NSFW community"
|
||||
class="flex items-center"
|
||||
style="color: var(--color-primary)"
|
||||
>
|
||||
{{ icon "square-asterisk" }}
|
||||
</span>
|
||||
{% endif %}
|
||||
</h3>
|
||||
|
||||
{% if user %} {% if user.id != community.owner
|
||||
|
|
|
@ -116,6 +116,11 @@
|
|||
"{{ post.context.comments_enabled }}",
|
||||
"checkbox",
|
||||
],
|
||||
[
|
||||
["is_nsfw", "Mark as NSFW"],
|
||||
"{{ community.context.is_nsfw }}",
|
||||
"checkbox",
|
||||
],
|
||||
];
|
||||
|
||||
if (can_manage_pins) {
|
||||
|
|
|
@ -548,6 +548,11 @@
|
|||
"{{ community.context.description }}",
|
||||
"textarea",
|
||||
],
|
||||
[
|
||||
["is_nsfw", "Mark as NSFW"],
|
||||
"{{ community.context.is_nsfw }}",
|
||||
"checkbox",
|
||||
],
|
||||
],
|
||||
settings,
|
||||
);
|
||||
|
|
|
@ -157,6 +157,14 @@ show_community and post.community != config.town_square %}
|
|||
{{ components::community_avatar(id=post.community) }}
|
||||
{% endif %}
|
||||
</a>
|
||||
{% endif %} {% if post.context.is_nsfw %}
|
||||
<span
|
||||
title="NSFW post"
|
||||
class="flex items-center"
|
||||
style="color: var(--color-primary)"
|
||||
>
|
||||
{{ icon "square-asterisk" }}
|
||||
</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
|
@ -389,7 +397,7 @@ config.town_square and user %}
|
|||
|
||||
<form
|
||||
class="card flex flex-col gap-2"
|
||||
onsubmit="create_post_from_form(event)"
|
||||
onsubmit="create_post_from_form_town_square(event)"
|
||||
>
|
||||
<div class="flex flex-col gap-1">
|
||||
<label for="content">{{ text "communities:label.content" }}</label>
|
||||
|
@ -409,7 +417,7 @@ config.town_square and user %}
|
|||
</div>
|
||||
|
||||
<script>
|
||||
async function create_post_from_form(e) {
|
||||
async function create_post_from_form_town_square(e) {
|
||||
e.preventDefault();
|
||||
await trigger("atto::debounce", ["posts::create"]);
|
||||
fetch("/api/v1/posts", {
|
||||
|
|
|
@ -133,7 +133,7 @@ impl DataManager {
|
|||
|
||||
let res = query_rows!(
|
||||
&conn,
|
||||
"SELECT * FROM communities ORDER BY member_count DESC LIMIT 12",
|
||||
"SELECT * FROM communities WHERE NOT context LIKE '%\"is_nsfw\":true%' ORDER BY member_count DESC LIMIT 12",
|
||||
empty,
|
||||
|x| { Self::get_community_from_row(x) }
|
||||
);
|
||||
|
|
|
@ -144,7 +144,7 @@ impl DataManager {
|
|||
|
||||
let res = query_rows!(
|
||||
&conn,
|
||||
"SELECT * FROM posts WHERE owner = $1 AND NOT context LIKE '%\"is_profile_pinned\":true%' ORDER BY created DESC LIMIT $2 OFFSET $3",
|
||||
"SELECT * FROM posts WHERE owner = $1 AND NOT context LIKE '%\"is_profile_pinned\":true%' AND NOT context LIKE '%\"is_nsfw\":true%' ORDER BY created DESC LIMIT $2 OFFSET $3",
|
||||
&[&(id as i64), &(batch as i64), &((page * batch) as i64)],
|
||||
|x| { Self::get_post_from_row(x) }
|
||||
);
|
||||
|
@ -248,7 +248,7 @@ impl DataManager {
|
|||
|
||||
let res = query_rows!(
|
||||
&conn,
|
||||
"SELECT * FROM posts WHERE replying_to = 0 ORDER BY likes DESC, created ASC LIMIT $1 OFFSET $2",
|
||||
"SELECT * FROM posts WHERE replying_to = 0 AND NOT context LIKE '%\"is_nsfw\":true%' ORDER BY likes DESC, created ASC LIMIT $1 OFFSET $2",
|
||||
&[&(batch as i64), &((page * batch) as i64)],
|
||||
|x| { Self::get_post_from_row(x) }
|
||||
);
|
||||
|
@ -358,6 +358,9 @@ impl DataManager {
|
|||
return Err(Error::NotAllowed);
|
||||
}
|
||||
|
||||
// mirror nsfw state
|
||||
data.context.is_nsfw = community.context.is_nsfw;
|
||||
|
||||
// check if we're blocked
|
||||
if let Some(replying_to) = data.replying_to {
|
||||
if let Ok(_) = self
|
||||
|
|
|
@ -72,8 +72,12 @@ impl Community {
|
|||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct CommunityContext {
|
||||
#[serde(default)]
|
||||
pub display_name: String,
|
||||
#[serde(default)]
|
||||
pub description: String,
|
||||
#[serde(default)]
|
||||
pub is_nsfw: bool,
|
||||
}
|
||||
|
||||
impl Default for CommunityContext {
|
||||
|
@ -81,6 +85,7 @@ impl Default for CommunityContext {
|
|||
Self {
|
||||
display_name: String::new(),
|
||||
description: String::new(),
|
||||
is_nsfw: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -171,6 +176,8 @@ pub struct PostContext {
|
|||
pub is_profile_pinned: bool,
|
||||
#[serde(default)]
|
||||
pub edited: usize,
|
||||
#[serde(default)]
|
||||
pub is_nsfw: bool,
|
||||
}
|
||||
|
||||
fn default_comments_enabled() -> bool {
|
||||
|
@ -184,6 +191,7 @@ impl Default for PostContext {
|
|||
is_pinned: false,
|
||||
is_profile_pinned: false,
|
||||
edited: 0,
|
||||
is_nsfw: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue