diff --git a/crates/app/src/public/html/communities/create_post.html b/crates/app/src/public/html/communities/create_post.html index 306de5d..13bdac2 100644 --- a/crates/app/src/public/html/communities/create_post.html +++ b/crates/app/src/public/html/communities/create_post.html @@ -65,6 +65,15 @@ {{ components::emoji_picker(element_id="content", render_dialog=true) }} + + @@ -89,13 +98,35 @@ }), }) .then((res) => res.json()) - .then((res) => { + .then(async (res) => { trigger("atto::toast", [ res.ok ? "success" : "error", res.message, ]); if (res.ok) { + // update settings + if ( + JSON.stringify( + window.POST_INITIAL_SETTINGS, + ) !== window.BLANK_INITIAL_SETTINGS + ) { + await fetch( + `/api/v1/posts/${res.payload}/context`, + { + method: "POST", + headers: { + "Content-Type": + "application/json", + }, + body: JSON.stringify({ + context: + window.POST_INITIAL_SETTINGS, + }), + }, + ); + } + setTimeout(() => { window.location.href = `/post/${res.payload}`; }, 100); @@ -137,4 +168,85 @@ window.history.back(); } + + +
+
+ +
+ +
+
+ +
+ +
+
+ + +
+
{% endblock %} diff --git a/crates/app/src/public/html/components.html b/crates/app/src/public/html/components.html index 40ed72a..c57660f 100644 --- a/crates/app/src/public/html/components.html +++ b/crates/app/src/public/html/components.html @@ -227,9 +227,24 @@ and show_community and community.id != config.town_square or question %} {% endif %} + {% if not post.context.content_warning %} {{ post.content|markdown|safe }} + {% else %} +
+ + {{ icon "triangle-alert" }} + {{ post.context.content_warning }} + + + {{ post.content|markdown|safe }} +
+ {% endif %} diff --git a/crates/app/src/public/html/post/post.html b/crates/app/src/public/html/post/post.html index 1d2cc7f..b904bd8 100644 --- a/crates/app/src/public/html/post/post.html +++ b/crates/app/src/public/html/post/post.html @@ -159,10 +159,15 @@ "checkbox", ], [ - ["is_nsfw", "Mark as NSFW"], + ["is_nsfw", "Hide from public timelines"], "{{ community.context.is_nsfw }}", "checkbox", ], + [ + ["content_warning", "Content warning"], + settings.content_warning, + "textarea", + ], ]; if (can_manage_pins) { diff --git a/crates/core/src/database/auth.rs b/crates/core/src/database/auth.rs index 5d72940..948d673 100644 --- a/crates/core/src/database/auth.rs +++ b/crates/core/src/database/auth.rs @@ -654,18 +654,18 @@ impl DataManager { auto_method!(update_user_stripe_id(&str)@get_user_by_id -> "UPDATE users SET stripe_id = $1 WHERE id = $2" --cache-key-tmpl=cache_clear_user); auto_method!(incr_user_notifications()@get_user_by_id -> "UPDATE users SET notification_count = notification_count + 1 WHERE id = $1" --cache-key-tmpl=cache_clear_user --incr); - auto_method!(decr_user_notifications()@get_user_by_id -> "UPDATE users SET notification_count = notification_count - 1 WHERE id = $1" --cache-key-tmpl=cache_clear_user --decr); + auto_method!(decr_user_notifications()@get_user_by_id -> "UPDATE users SET notification_count = notification_count - 1 WHERE id = $1" --cache-key-tmpl=cache_clear_user --decr=notification_count); auto_method!(incr_user_follower_count()@get_user_by_id -> "UPDATE users SET follower_count = follower_count + 1 WHERE id = $1" --cache-key-tmpl=cache_clear_user --incr); - auto_method!(decr_user_follower_count()@get_user_by_id -> "UPDATE users SET follower_count = follower_count - 1 WHERE id = $1" --cache-key-tmpl=cache_clear_user --decr); + auto_method!(decr_user_follower_count()@get_user_by_id -> "UPDATE users SET follower_count = follower_count - 1 WHERE id = $1" --cache-key-tmpl=cache_clear_user --decr=follower_count); auto_method!(incr_user_following_count()@get_user_by_id -> "UPDATE users SET following_count = following_count + 1 WHERE id = $1" --cache-key-tmpl=cache_clear_user --incr); - auto_method!(decr_user_following_count()@get_user_by_id -> "UPDATE users SET following_count = following_count - 1 WHERE id = $1" --cache-key-tmpl=cache_clear_user --decr); + auto_method!(decr_user_following_count()@get_user_by_id -> "UPDATE users SET following_count = following_count - 1 WHERE id = $1" --cache-key-tmpl=cache_clear_user --decr=following_count); auto_method!(incr_user_post_count()@get_user_by_id -> "UPDATE users SET post_count = post_count + 1 WHERE id = $1" --cache-key-tmpl=cache_clear_user --incr); - auto_method!(decr_user_post_count()@get_user_by_id -> "UPDATE users SET post_count = post_count - 1 WHERE id = $1" --cache-key-tmpl=cache_clear_user --decr); + auto_method!(decr_user_post_count()@get_user_by_id -> "UPDATE users SET post_count = post_count - 1 WHERE id = $1" --cache-key-tmpl=cache_clear_user --decr=post_count); auto_method!(update_user_request_count(i32)@get_user_by_id -> "UPDATE users SET request_count = $1 WHERE id = $2" --cache-key-tmpl=cache_clear_user); auto_method!(incr_user_request_count()@get_user_by_id -> "UPDATE users SET request_count = request_count + 1 WHERE id = $1" --cache-key-tmpl=cache_clear_user --incr); - auto_method!(decr_user_request_count()@get_user_by_id -> "UPDATE users SET request_count = request_count - 1 WHERE id = $1" --cache-key-tmpl=cache_clear_user --decr); + auto_method!(decr_user_request_count()@get_user_by_id -> "UPDATE users SET request_count = request_count - 1 WHERE id = $1" --cache-key-tmpl=cache_clear_user --decr=request_count); } diff --git a/crates/core/src/database/common.rs b/crates/core/src/database/common.rs index 0272ed9..1001e34 100644 --- a/crates/core/src/database/common.rs +++ b/crates/core/src/database/common.rs @@ -667,10 +667,14 @@ macro_rules! auto_method { } }; - ($name:ident()@$select_fn:ident -> $query:literal --cache-key-tmpl=$cache_key_tmpl:ident --decr) => { + ($name:ident()@$select_fn:ident -> $query:literal --cache-key-tmpl=$cache_key_tmpl:ident --decr=$field:ident) => { pub async fn $name(&self, id: usize) -> Result<()> { let y = self.$select_fn(id).await?; + if (y.$field as isize) - 1 < 0 { + return Ok(()); + } + let conn = match self.connect().await { Ok(c) => c, Err(e) => return Err(Error::DatabaseConnection(e.to_string())), diff --git a/crates/core/src/database/communities.rs b/crates/core/src/database/communities.rs index 1dc8ee7..2b2087e 100644 --- a/crates/core/src/database/communities.rs +++ b/crates/core/src/database/communities.rs @@ -471,9 +471,9 @@ impl DataManager { auto_method!(incr_community_likes()@get_community_by_id_no_void -> "UPDATE communities SET likes = likes + 1 WHERE id = $1" --cache-key-tmpl=cache_clear_community --incr); auto_method!(incr_community_dislikes()@get_community_by_id_no_void -> "UPDATE communities SET dislikes = dislikes + 1 WHERE id = $1" --cache-key-tmpl=cache_clear_community --incr); - auto_method!(decr_community_likes()@get_community_by_id_no_void -> "UPDATE communities SET likes = likes - 1 WHERE id = $1" --cache-key-tmpl=cache_clear_community --decr); - auto_method!(decr_community_dislikes()@get_community_by_id_no_void -> "UPDATE communities SET dislikes = dislikes - 1 WHERE id = $1" --cache-key-tmpl=cache_clear_community --decr); + auto_method!(decr_community_likes()@get_community_by_id_no_void -> "UPDATE communities SET likes = likes - 1 WHERE id = $1" --cache-key-tmpl=cache_clear_community --decr=likes); + auto_method!(decr_community_dislikes()@get_community_by_id_no_void -> "UPDATE communities SET dislikes = dislikes - 1 WHERE id = $1" --cache-key-tmpl=cache_clear_community --decr=dislikes); auto_method!(incr_community_member_count()@get_community_by_id_no_void -> "UPDATE communities SET member_count = member_count + 1 WHERE id = $1" --cache-key-tmpl=cache_clear_community --incr); - auto_method!(decr_community_member_count()@get_community_by_id_no_void -> "UPDATE communities SET member_count = member_count - 1 WHERE id = $1" --cache-key-tmpl=cache_clear_community --decr); + auto_method!(decr_community_member_count()@get_community_by_id_no_void -> "UPDATE communities SET member_count = member_count - 1 WHERE id = $1" --cache-key-tmpl=cache_clear_community --decr=member_count); } diff --git a/crates/core/src/database/posts.rs b/crates/core/src/database/posts.rs index 4e2d559..41e4828 100644 --- a/crates/core/src/database/posts.rs +++ b/crates/core/src/database/posts.rs @@ -584,7 +584,7 @@ impl DataManager { let res = query_rows!( &conn, &format!( - "SELECT * FROM posts WHERE (community = {} {query_string}) AND replying_to = 0 ORDER BY created DESC LIMIT $1 OFFSET $2", + "SELECT * FROM posts WHERE (community = {} {query_string}) AND NOT context LIKE '%\"is_nsfw\":true%' AND replying_to = 0 ORDER BY created DESC LIMIT $1 OFFSET $2", first.community ), &[&(batch as i64), &((page * batch) as i64)], diff --git a/crates/core/src/model/communities.rs b/crates/core/src/model/communities.rs index b333cc4..5528b71 100644 --- a/crates/core/src/model/communities.rs +++ b/crates/core/src/model/communities.rs @@ -178,6 +178,8 @@ pub struct PostContext { pub answering: usize, #[serde(default = "default_reactions_enabled")] pub reactions_enabled: bool, + #[serde(default)] + pub content_warning: String, } fn default_comments_enabled() -> bool { @@ -204,6 +206,7 @@ impl Default for PostContext { repost: None, answering: 0, reactions_enabled: default_reactions_enabled(), + content_warning: String::new(), } } }