Skip to content

Commit 7e22dc0

Browse files
committed
Add option to disable post reply notifications (fixes #1883, fixes #3042)
1 parent 74701af commit 7e22dc0

File tree

9 files changed

+18
-1
lines changed

9 files changed

+18
-1
lines changed

crates/api_common/src/build_response.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ pub async fn send_local_notifs(
274274
.await
275275
.is_err();
276276

277-
if post.creator_id != person.id && !check_blocks {
277+
if post.creator_id != person.id && !check_blocks && !post.disable_reply_notifications {
278278
let creator_id = post.creator_id;
279279
let parent_user = LocalUserView::read_person(&mut context.pool(), creator_id).await;
280280
if let Ok(parent_user_view) = parent_user {

crates/api_common/src/post.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ pub struct CreatePost {
4040
/// Time when this post should be scheduled. Null means publish immediately.
4141
#[cfg_attr(feature = "full", ts(optional))]
4242
pub scheduled_publish_time: Option<i64>,
43+
/// True if the post creator gets notified about new top-level comments
44+
#[cfg_attr(feature = "full", ts(optional))]
45+
pub disable_reply_notifications: Option<bool>,
4346
}
4447

4548
#[derive(Debug, Serialize, Deserialize, Clone)]
@@ -180,6 +183,9 @@ pub struct EditPost {
180183
pub scheduled_publish_time: Option<i64>,
181184
#[cfg_attr(feature = "full", ts(optional))]
182185
pub tags: Option<Vec<TagId>>,
186+
/// True if the post creator gets notified about new top-level comments
187+
#[cfg_attr(feature = "full", ts(optional))]
188+
pub disable_reply_notifications: Option<bool>,
183189
}
184190

185191
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]

crates/api_crud/src/post/create.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ pub async fn create_post(
120120
language_id: Some(language_id),
121121
federation_pending: Some(community_use_pending(community, &context).await),
122122
scheduled_publish_time,
123+
disable_reply_notifications: data.disable_reply_notifications,
123124
..PostInsertForm::new(
124125
data.name.trim().to_string(),
125126
local_user_view.person.id,

crates/api_crud/src/post/update.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ pub async fn update_post(
150150
language_id: Some(language_id),
151151
updated: Some(Some(Utc::now())),
152152
scheduled_publish_time,
153+
disable_reply_notifications: data.disable_reply_notifications,
153154
..Default::default()
154155
};
155156
post_form = plugin_hook_before("before_update_local_post", post_form).await?;

crates/db_schema/src/impls/post.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ mod tests {
578578
scaled_rank: RANK_DEFAULT,
579579
unresolved_report_count: 0,
580580
federation_pending: false,
581+
disable_reply_notifications: false,
581582
};
582583

583584
// Post Like

crates/db_schema/src/source/post.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ pub struct Post {
9494
/// If a local user posts in a remote community, the comment is hidden until it is confirmed
9595
/// accepted by the community (by receiving it back via federation).
9696
pub federation_pending: bool,
97+
/// True if the post creator gets notified about new top-level comments
98+
pub disable_reply_notifications: bool,
9799
}
98100

99101
// TODO: FromBytes, ToBytes are only needed to develop wasm plugin, could be behind feature flag
@@ -149,6 +151,8 @@ pub struct PostInsertForm {
149151
pub scheduled_publish_time: Option<DateTime<Utc>>,
150152
#[new(default)]
151153
pub federation_pending: Option<bool>,
154+
#[new(default)]
155+
pub disable_reply_notifications: Option<bool>,
152156
}
153157

154158
#[derive(Debug, Clone, Default)]
@@ -177,6 +181,7 @@ pub struct PostUpdateForm {
177181
pub alt_text: Option<Option<String>>,
178182
pub scheduled_publish_time: Option<Option<DateTime<Utc>>>,
179183
pub federation_pending: Option<bool>,
184+
pub disable_reply_notifications: Option<bool>,
180185
}
181186

182187
#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)]

crates/db_schema_file/src/schema.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,7 @@ diesel::table! {
862862
report_count -> Int2,
863863
unresolved_report_count -> Int2,
864864
federation_pending -> Bool,
865+
disable_reply_notifications -> Bool
865866
}
866867
}
867868

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
alter table post drop column disable_reply_notifications;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
alter table post add column disable_reply_notifications bool not null default false;

0 commit comments

Comments
 (0)