From c510e6abcec8d15db6feb09d5c0a98913284433a Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 25 Jan 2021 18:46:14 +0100 Subject: [PATCH] Delete all notifications about a post when making it private --- src/controllers/posts_controller.rs | 7 +++++-- src/helpers/posts_helper.rs | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/controllers/posts_controller.rs b/src/controllers/posts_controller.rs index 23cb8fa..6d807f3 100644 --- a/src/controllers/posts_controller.rs +++ b/src/controllers/posts_controller.rs @@ -246,9 +246,12 @@ pub fn set_visibility_level(r: &mut HttpRequestHandler) -> RequestResult { let post = r.post_post_with_access("postID", PostAccessLevel::FULL_ACCESS)?; let new_visibility = PostVisibilityLevel::from_api(&r.post_string("new_level")?); - posts_helper::set_level(post.id, new_visibility)?; + posts_helper::set_level(post.id, &new_visibility)?; - // TODO : Depending on new level, delete (or not) notifications about the post + // Depending on new level, delete (or not) notifications about the post + if matches!(new_visibility, PostVisibilityLevel::VISIBILITY_USER) { + notifications_helper::delete_all_related_with_post(post.id)?; + } r.success("Visibility level updated") } diff --git a/src/helpers/posts_helper.rs b/src/helpers/posts_helper.rs index 64c93cb..5d0eb0c 100644 --- a/src/helpers/posts_helper.rs +++ b/src/helpers/posts_helper.rs @@ -403,7 +403,7 @@ pub fn allow_comments_on_post(p: &Post) -> ResultBoxError { } /// Set a new visibility level to a post -pub fn set_level(post_id: u64, level: PostVisibilityLevel) -> ResultBoxError { +pub fn set_level(post_id: u64, level: &PostVisibilityLevel) -> ResultBoxError { database::UpdateInfo::new(POSTS_TABLE) .cond_u64("ID", post_id) .set_u32("niveau_visibilite", level.to_db())