diff --git a/src/helpers/notifications_helper.rs b/src/helpers/notifications_helper.rs index 58e9c66..668e86e 100644 --- a/src/helpers/notifications_helper.rs +++ b/src/helpers/notifications_helper.rs @@ -39,7 +39,8 @@ pub fn create_friends_notification(from_user: &UserID, dest_user: &UserID, actio /// Create & push a group membership notification pub fn create_group_membership_notification(user_id: &UserID, moderator_id: Option<&UserID>, group_id: &GroupID, kind: NotifEventType) -> ResultBoxError { - // TODO : Delete related group membership notifications + // Delete related group membership notifications + delete_all_related_to_group_membership_notifications(user_id, group_id)?; let mut n = PartialNotification::new() .set_on_elem_id(group_id.id()) @@ -267,6 +268,23 @@ pub fn delete_all_related_with_group(group_id: &GroupID) -> ResultBoxError { ) } +/// Delete all the notifications related to a group membership +pub fn delete_all_related_to_group_membership_notifications(user_id: &UserID, group_id: &GroupID) -> ResultBoxError { + let mut n = PartialNotification::new() + .set_on_elem_type(NotifElemType::GROUP_MEMBERSHIP) + .set_on_elem_id(group_id.id()); + + n.dest_user_id = Some(user_id.clone()); + n.from_user_id = None; + delete(&n)?; + + n.dest_user_id = None; + n.from_user_id = Some(user_id.clone()); + delete(&n)?; + + Ok(()) +} + /// Check out whether a similar notification exists for given specifications pub fn similar_exists(n: &PartialNotification) -> ResultBoxError { database::QueryInfo::new(NOTIFICATIONS_TABLE)