From f1525c4cc4e01d0211f8e11cf888ab58a9ffe1b9 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sun, 24 Jan 2021 17:57:30 +0100 Subject: [PATCH] Delete all notifications related with friendship requests --- src/controllers/friends_controller.rs | 3 ++- src/helpers/notifications_helper.rs | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/controllers/friends_controller.rs b/src/controllers/friends_controller.rs index 777adbf..8f74b8e 100644 --- a/src/controllers/friends_controller.rs +++ b/src/controllers/friends_controller.rs @@ -102,7 +102,8 @@ pub fn cancel_request(r: &mut HttpRequestHandler) -> RequestResult { friends_helper::remove_request(&r.user_id()?, &friend_id)?; - // TODO : delete related notifications + // Delete related notifications + notifications_helper::delete_all_related_with_friendship_request(r.user_id_ref()?, &friend_id)?; r.success("Friendship request removed!") } diff --git a/src/helpers/notifications_helper.rs b/src/helpers/notifications_helper.rs index 0ab5378..1a9d30b 100644 --- a/src/helpers/notifications_helper.rs +++ b/src/helpers/notifications_helper.rs @@ -294,6 +294,20 @@ pub fn delete_all_related_with_post(post_id: PostID) -> ResultBoxError { delete(&n) } +/// Delete all the notifications related with a friendship request +pub fn delete_all_related_with_friendship_request(user_one: &UserID, user_two: &UserID) -> ResultBoxError { + let mut n = PartialNotification::new() + .set_on_elem_type(NotifElemType::FRIENDSHIP_REQUEST); + + n.from_user_id = Some(user_one.clone()); + n.dest_user_id = Some(user_two.clone()); + delete(&n)?; + + n.from_user_id = Some(user_two.clone()); + n.dest_user_id = Some(user_one.clone()); + delete(&n) +} + /// Check out whether a similar notification exists for given specifications pub fn similar_exists(n: &PartialNotification) -> ResultBoxError { database::QueryInfo::new(NOTIFICATIONS_TABLE)