1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-01-14 14:37:44 +00:00

Delete all notifications related with friendship requests

This commit is contained in:
Pierre HUBERT 2021-01-24 17:57:30 +01:00
parent f84f925abc
commit f1525c4cc4
2 changed files with 16 additions and 1 deletions

View File

@ -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!")
}

View File

@ -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<bool> {
database::QueryInfo::new(NOTIFICATIONS_TABLE)