From 09ef0fc30161151adb17327bb6dad1e38fbe3d0c Mon Sep 17 00:00:00 2001 From: trisua Date: Sun, 13 Apr 2025 00:42:10 -0400 Subject: [PATCH] add: ability to disable reactions on posts --- crates/app/src/public/html/communities/post.html | 7 +++++-- crates/app/src/public/html/components.html | 11 ++++++++--- crates/core/src/model/communities.rs | 9 ++++++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/crates/app/src/public/html/communities/post.html b/crates/app/src/public/html/communities/post.html index 7afdad4..884c115 100644 --- a/crates/app/src/public/html/communities/post.html +++ b/crates/app/src/public/html/communities/post.html @@ -134,8 +134,11 @@ "checkbox", ], [ - ["reposts_enabled", "Allow people to repost your post"], - "{{ post.context.reposts_enabled }}", + [ + "reactions_enabled", + "Allow people to like/dislike your post", + ], + "{{ post.context.reactions_enabled }}", "checkbox", ], [ diff --git a/crates/app/src/public/html/components.html b/crates/app/src/public/html/components.html index 6ecd789..d4b4559 100644 --- a/crates/app/src/public/html/components.html +++ b/crates/app/src/public/html/components.html @@ -235,8 +235,10 @@ and show_community and community.id != config.town_square or question %} hook-arg:id="{{ post.id }}" > - {% if post.content|length > 0 %} - {{ components::likes(id=post.id, asset_type="Post", likes=post.likes, dislikes=post.dislikes) }} + {% if post.context.reactions_enabled %} + {% if post.content|length > 0 %} + {{ components::likes(id=post.id, asset_type="Post", likes=post.likes, dislikes=post.dislikes) }} + {% endif %} {% endif %} {% if post.context.repost and post.context.repost.reposting %} @@ -617,7 +619,10 @@ show_community=true, secondary=false) -%} {% if question.community > 0 and show_community %} - + {{ components::community_avatar(id=question.community, size="24px") }} diff --git a/crates/core/src/model/communities.rs b/crates/core/src/model/communities.rs index ca290e8..ec96876 100644 --- a/crates/core/src/model/communities.rs +++ b/crates/core/src/model/communities.rs @@ -176,6 +176,8 @@ pub struct PostContext { /// The ID of the question this post is answering. #[serde(default)] pub answering: usize, + #[serde(default = "default_reactions_enabled")] + pub reactions_enabled: bool, } fn default_comments_enabled() -> bool { @@ -186,17 +188,22 @@ fn default_reposts_enabled() -> bool { true } +fn default_reactions_enabled() -> bool { + true +} + impl Default for PostContext { fn default() -> Self { Self { comments_enabled: default_comments_enabled(), - reposts_enabled: true, + reposts_enabled: default_reposts_enabled(), is_pinned: false, is_profile_pinned: false, edited: 0, is_nsfw: false, repost: None, answering: 0, + reactions_enabled: default_reactions_enabled(), } } }