From c177c2c2f6ed918775ecc2d38419c25d75577525 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 21 Apr 2021 18:43:32 +0200 Subject: [PATCH] Delete all forez presence of a group when deleting a group --- src/helpers/forez_presence_helper.rs | 7 +++++++ src/helpers/groups_helper.rs | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/helpers/forez_presence_helper.rs b/src/helpers/forez_presence_helper.rs index f89a221..f891b65 100644 --- a/src/helpers/forez_presence_helper.rs +++ b/src/helpers/forez_presence_helper.rs @@ -31,6 +31,13 @@ pub fn delete_all_user(user_id: &UserID) -> Res { .exec() } +/// Delete all the presences of a given group +pub fn delete_all_group(group_id: &GroupID) -> Res { + database::DeleteQuery::new(FOREZ_PRESENCE_TABLE) + .cond_group_id("group_id", group_id) + .exec() +} + /// Update the presences of a user pub fn update(group_id: &GroupID, user_id: &UserID, list: Vec) -> Res { let previous_presences = get_user_presences(group_id, user_id)?; diff --git a/src/helpers/groups_helper.rs b/src/helpers/groups_helper.rs index 60a3980..942c0be 100644 --- a/src/helpers/groups_helper.rs +++ b/src/helpers/groups_helper.rs @@ -9,7 +9,7 @@ use crate::data::group_id::GroupID; use crate::data::group_member::{GroupMember, GroupMembershipLevel}; use crate::data::new_group::NewGroup; use crate::data::user::UserID; -use crate::helpers::{conversations_helper, database, likes_helper, notifications_helper, posts_helper}; +use crate::helpers::{conversations_helper, database, forez_presence_helper, likes_helper, notifications_helper, posts_helper}; use crate::helpers::likes_helper::LikeType; use crate::utils::date_utils::time; @@ -505,6 +505,9 @@ pub fn delete(group_id: &GroupID) -> ResultBoxError { // Delete all conversations related with the group conversations_helper::delete_all_group_conversations(group_id)?; + // Delete all Forez presences related with the group + forez_presence_helper::delete_all_group(group_id)?; + // Delete all group members database::DeleteQuery::new(GROUPS_MEMBERS_TABLE) .cond_group_id("groups_id", group_id)