diff --git a/src/helpers/conversations_helper.rs b/src/helpers/conversations_helper.rs index 59d832d..9f11924 100644 --- a/src/helpers/conversations_helper.rs +++ b/src/helpers/conversations_helper.rs @@ -258,6 +258,15 @@ pub fn delete_all_user_messages(user_id: &UserID) -> ResultBoxError { delete_message(msg)?; } + // Remove all server messages related with the user + database::DeleteQuery::new(CONV_MESSAGES_TABLE) + .set_custom_where(&format!( + "user_id IS NULL AND ((message LIKE \"%-{}-%\") OR (message LIKE \"%-{}\"))", + user_id.id(), + user_id.id() + )) + .exec()?; + Ok(()) } diff --git a/src/helpers/database.rs b/src/helpers/database.rs index de6a0e1..d0e3383 100644 --- a/src/helpers/database.rs +++ b/src/helpers/database.rs @@ -9,10 +9,10 @@ use mysql::{Binary, Pool, ResultSet, Value}; use mysql::prelude::Queryable; use crate::data::config::{conf, DatabaseConfig}; +use crate::data::conversation::ConvID; use crate::data::error::{ExecError, ResultBoxError}; use crate::data::group_id::GroupID; use crate::data::user::UserID; -use crate::data::conversation::ConvID; /// Database access helper /// @@ -662,7 +662,6 @@ impl InsertQuery { } - /// Legacy database boolean (1 = true / 0 = false) pub fn add_legacy_bool(mut self, key: &str, value: bool) -> InsertQuery { let num = match value { @@ -814,7 +813,7 @@ impl DeleteQuery { /// Delete an entry from the database pub fn delete(query: DeleteQuery) -> ResultBoxError<()> { - if query.conditions.is_empty() { + if query.conditions.is_empty() && query.custom_where.is_none() { return Err(ExecError::boxed_new("DELETE without WHERE condition blocked for security reasons!")); }