From 42d43ef9d85c76249fabbbaa88383d030de6409d Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 3 Apr 2021 19:14:32 +0200 Subject: [PATCH] Can delete group conversation --- src/controllers/groups_controller.rs | 16 ++++++++++++++++ src/helpers/groups_helper.rs | 4 ++++ src/routes.rs | 1 + 3 files changed, 21 insertions(+) diff --git a/src/controllers/groups_controller.rs b/src/controllers/groups_controller.rs index ae77ffd..1e1e721 100644 --- a/src/controllers/groups_controller.rs +++ b/src/controllers/groups_controller.rs @@ -179,6 +179,20 @@ pub fn create_conversation(r: &mut HttpRequestHandler) -> RequestResult { r.set_response(ResCreateConversationForGroup::new(conv_id)) } +/// Delete a group's conversation +pub fn delete_conversation(r: &mut HttpRequestHandler) -> RequestResult { + let conv_membership = r.post_conv_admin("conv_id")?; + let conv = conversations_helper::get_single(conv_membership.conv_id)?; + + if !conv.is_linked_to_group() { + r.bad_request("This conversation is not linked to a group, it can not deleted this way!".to_string())?; + } + + conversations_helper::delete_conversation(&conv)?; + + r.ok() +} + /// Get the list of members of a group pub fn get_members(r: &mut HttpRequestHandler) -> RequestResult { let group_id = r.post_group_id("id")?; @@ -282,6 +296,8 @@ pub fn send_request(r: &mut HttpRequestHandler) -> RequestResult { following: true, })?; + // TODO : if the user has already the "member" level, gives him access to conversations + // Send a notification, if required if matches!(group.registration_level, GroupRegistrationLevel::MODERATED_REGISTRATION) { notifications_helper::create_group_membership_notification(r.user_id_ref()?, None, diff --git a/src/helpers/groups_helper.rs b/src/helpers/groups_helper.rs index 591a64c..f0c39d7 100644 --- a/src/helpers/groups_helper.rs +++ b/src/helpers/groups_helper.rs @@ -132,6 +132,8 @@ pub fn delete_member(group_id: &GroupID, user_id: &UserID) -> ResultBoxError { .cond_group_id("groups_id", group_id) .cond_user_id("user_id", user_id) .exec() + + // TODO : Update access to group's conversations } /// Update a user's membership level @@ -141,6 +143,8 @@ pub fn update_membership_level(group_id: &GroupID, user_id: &UserID, new_level: .cond_group_id("groups_id", group_id) .set_u32("level", new_level.to_db()) .exec() + + // TODO : Update access to group's conversations } /// Update following status of a user diff --git a/src/routes.rs b/src/routes.rs index f9c5f7a..bea696d 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -228,6 +228,7 @@ pub fn get_routes() -> Vec { Route::post("/groups/upload_logo", Box::new(groups_controller::upload_logo)), Route::post("/groups/delete_logo", Box::new(groups_controller::delete_logo)), Route::post("/groups/create_conversation", Box::new(groups_controller::create_conversation)), + Route::post("/groups/delete_conversation", Box::new(groups_controller::delete_conversation)), Route::post("/groups/get_members", Box::new(groups_controller::get_members)), Route::post("/groups/invite", Box::new(groups_controller::invite_user)), Route::post("/groups/cancel_invitation", Box::new(groups_controller::cancel_invitation)),