From 5a704f5c59016f7e20d288c8869cc8f205f83876 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 21 Jan 2021 18:41:27 +0100 Subject: [PATCH] Can remove the user from all its conversations --- src/helpers/account_helper.rs | 3 +++ src/helpers/conversations_helper.rs | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/src/helpers/account_helper.rs b/src/helpers/account_helper.rs index fbe999a..7edbdd3 100644 --- a/src/helpers/account_helper.rs +++ b/src/helpers/account_helper.rs @@ -324,6 +324,9 @@ pub fn delete(user_id: &UserID) -> ResultBoxError { // Delete all conversation messages conversations_helper::delete_all_user_messages(user_id)?; + // Remove the user from all its conversations + conversations_helper::delete_all_user_conversations(user_id)?; + // TODO : continue work here Ok(()) diff --git a/src/helpers/conversations_helper.rs b/src/helpers/conversations_helper.rs index b3e82a4..9f73766 100644 --- a/src/helpers/conversations_helper.rs +++ b/src/helpers/conversations_helper.rs @@ -269,6 +269,15 @@ pub fn delete_all_user_messages(user_id: &UserID) -> ResultBoxError { Ok(()) } +/// Remove the user from all the conversations he belongs to +pub fn delete_all_user_conversations(user_id: &UserID) -> ResultBoxError { + for conversation in &get_list_user(user_id)? { + remove_user_from_conversation(user_id, conversation.id)?; + } + + Ok(()) +} + /// Get the entire list of messages of a given conversation pub fn get_all_messages(conv_id: u64) -> ResultBoxError> { database::QueryInfo::new(CONV_MESSAGES_TABLE)