Skip to content

Commit b64b957

Browse files
committed
Also for comments
1 parent 7e22dc0 commit b64b957

File tree

13 files changed

+33
-5
lines changed

13 files changed

+33
-5
lines changed

crates/api_common/src/build_response.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,10 @@ pub async fn send_local_notifs(
228228
.is_err();
229229

230230
// Don't send a notif to yourself
231-
if parent_comment.creator_id != person.id && !check_blocks {
231+
if parent_comment.creator_id != person.id
232+
&& !check_blocks
233+
&& !parent_comment.disable_reply_notifications
234+
{
232235
let user_view = LocalUserView::read_person(&mut context.pool(), parent_creator_id).await;
233236
if let Ok(parent_user_view) = user_view {
234237
// Don't duplicate notif if already mentioned by checking recipient ids

crates/api_common/src/comment.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ pub struct CreateComment {
1818
pub parent_id: Option<CommentId>,
1919
#[cfg_attr(feature = "full", ts(optional))]
2020
pub language_id: Option<LanguageId>,
21+
/// If false the author doesnt get notified about new replies
22+
#[cfg_attr(feature = "full", ts(optional))]
23+
pub disable_reply_notifications: Option<bool>,
2124
}
2225

2326
#[skip_serializing_none]
@@ -40,6 +43,8 @@ pub struct EditComment {
4043
pub content: Option<String>,
4144
#[cfg_attr(feature = "full", ts(optional))]
4245
pub language_id: Option<LanguageId>,
46+
#[cfg_attr(feature = "full", ts(optional))]
47+
pub disable_reply_notifications: Option<bool>,
4348
}
4449

4550
#[skip_serializing_none]

crates/api_common/src/post.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ 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
43+
/// If false the post creator doesnt get notified about new top-level comments
4444
#[cfg_attr(feature = "full", ts(optional))]
4545
pub disable_reply_notifications: Option<bool>,
4646
}

crates/api_crud/src/comment/create.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ pub async fn create_comment(
100100
let mut comment_form = CommentInsertForm {
101101
language_id: Some(language_id),
102102
federation_pending: Some(community_use_pending(&post_view.community, &context).await),
103+
disable_reply_notifications: data.disable_reply_notifications,
103104
..CommentInsertForm::new(local_user_view.person.id, data.post_id, content.clone())
104105
};
105106
comment_form = plugin_hook_before("before_create_local_comment", comment_form).await?;

crates/api_crud/src/comment/update.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ pub async fn update_comment(
6767
let mut form = CommentUpdateForm {
6868
content,
6969
language_id: Some(language_id),
70+
disable_reply_notifications: data.disable_reply_notifications,
7071
updated: Some(Some(Utc::now())),
7172
..Default::default()
7273
};

crates/apub/src/objects/comment.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ impl Object for ApubComment {
212212
local: Some(false),
213213
language_id,
214214
federation_pending: Some(false),
215+
disable_reply_notifications: None,
215216
};
216217
form = plugin_hook_before("before_receive_federated_comment", form).await?;
217218
let parent_comment_path = parent_comment.map(|t| t.0.path);

crates/db_schema/src/impls/comment.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ mod tests {
347347
report_count: 0,
348348
unresolved_report_count: 0,
349349
federation_pending: false,
350+
disable_reply_notifications: false,
350351
};
351352

352353
let child_comment_form = CommentInsertForm::new(

crates/db_schema/src/source/comment.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ pub struct Comment {
6363
/// If a local user comments in a remote community, the comment is hidden until it is confirmed
6464
/// accepted by the community (by receiving it back via federation).
6565
pub federation_pending: bool,
66+
/// If false the author doesnt get notified about new replies
67+
pub disable_reply_notifications: bool,
6668
}
6769

6870
#[derive(Debug, Clone, derive_new::new)]
@@ -93,6 +95,8 @@ pub struct CommentInsertForm {
9395
pub language_id: Option<LanguageId>,
9496
#[new(default)]
9597
pub federation_pending: Option<bool>,
98+
#[new(default)]
99+
pub disable_reply_notifications: Option<bool>,
96100
}
97101

98102
#[derive(Debug, Clone, Default)]
@@ -109,6 +113,7 @@ pub struct CommentUpdateForm {
109113
pub distinguished: Option<bool>,
110114
pub language_id: Option<LanguageId>,
111115
pub federation_pending: Option<bool>,
116+
pub disable_reply_notifications: Option<bool>,
112117
}
113118

114119
#[skip_serializing_none]

crates/db_schema/src/source/post.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ 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
97+
/// If false the post creator doesnt get notified about new top-level comments
9898
pub disable_reply_notifications: bool,
9999
}
100100

crates/db_schema_file/src/schema.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ diesel::table! {
139139
report_count -> Int2,
140140
unresolved_report_count -> Int2,
141141
federation_pending -> Bool,
142+
disable_reply_notifications -> Bool
142143
}
143144
}
144145

crates/db_views/src/utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ pub(crate) fn comment_select_remove_deletes() -> _ {
180180
comment::report_count,
181181
comment::unresolved_report_count,
182182
comment::federation_pending,
183+
comment::disable_reply_notifications,
183184
)
184185
}
185186

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
alter table post drop column disable_reply_notifications;
1+
ALTER TABLE post
2+
DROP COLUMN disable_reply_notifications;
3+
4+
ALTER TABLE comment
5+
DROP COLUMN disable_reply_notifications
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
alter table post add column disable_reply_notifications bool not null default false;
1+
ALTER TABLE post
2+
ADD COLUMN disable_reply_notifications bool NOT NULL DEFAULT FALSE;
3+
4+
ALTER TABLE comment
5+
ADD COLUMN disable_reply_notifications bool NOT NULL DEFAULT FALSE;
6+

0 commit comments

Comments
 (0)