diff --git a/src/controllers/settings_controller.rs b/src/controllers/settings_controller.rs index b9bc646..3dbc01c 100644 --- a/src/controllers/settings_controller.rs +++ b/src/controllers/settings_controller.rs @@ -16,6 +16,7 @@ use crate::data::http_request_handler::HttpRequestHandler; use crate::data::lang_settings::LangSettings; use crate::data::new_custom_emoji::NewCustomEmoji; use crate::data::new_data_conservation_policy::NewDataConservationPolicy; +use crate::data::new_notifications_settings::NewNotificationsSettings; use crate::data::security_settings::{SecurityQuestion, SecuritySettings}; use crate::data::user::{AccountImageVisibility, UserPageStatus}; use crate::helpers::{account_helper, custom_emojies_helper, user_helper}; @@ -259,9 +260,20 @@ pub fn set_data_conservation_policy(r: &mut HttpRequestHandler) -> RequestResult r.success("Successfully updated data conservation policy!") } -/// Get notification settings +/// Get notifications settings pub fn get_notifications(r: &mut HttpRequestHandler) -> RequestResult { let user = user_helper::find_user_by_id(r.user_id_ref()?)?; r.set_response(NotificationSettingsAPI::new(&user)) +} + +/// Set (update) notifications settings +pub fn set_notifications(r: &mut HttpRequestHandler) -> RequestResult { + account_helper::set_notifications_settings(NewNotificationsSettings { + user_id: r.user_id()?, + allow_notifications_sound: r.post_bool("allow_notifications_sound")?, + allow_conversations: r.post_bool("allow_conversations")?, + })?; + + r.ok() } \ No newline at end of file diff --git a/src/data/mod.rs b/src/data/mod.rs index 3a43cbe..40cc9b9 100644 --- a/src/data/mod.rs +++ b/src/data/mod.rs @@ -37,4 +37,5 @@ pub mod new_data_conservation_policy; pub mod new_custom_emoji; pub mod user_ws_message; pub mod user_ws_connection; -pub mod call_signal; \ No newline at end of file +pub mod call_signal; +pub mod new_notifications_settings; \ No newline at end of file diff --git a/src/data/new_notifications_settings.rs b/src/data/new_notifications_settings.rs new file mode 100644 index 0000000..83fb211 --- /dev/null +++ b/src/data/new_notifications_settings.rs @@ -0,0 +1,11 @@ +//! # New conversation settings +//! +//! @author Pierre Hubert + +use crate::data::user::UserID; + +pub struct NewNotificationsSettings { + pub user_id: UserID, + pub allow_notifications_sound: bool, + pub allow_conversations: bool, +} \ No newline at end of file diff --git a/src/helpers/account_helper.rs b/src/helpers/account_helper.rs index ba7d9bc..4b1db65 100644 --- a/src/helpers/account_helper.rs +++ b/src/helpers/account_helper.rs @@ -10,6 +10,7 @@ use crate::data::general_settings::GeneralSettings; use crate::data::lang_settings::LangSettings; use crate::data::new_account::NewAccount; use crate::data::new_data_conservation_policy::NewDataConservationPolicy; +use crate::data::new_notifications_settings::NewNotificationsSettings; use crate::data::security_settings::SecuritySettings; use crate::data::user::{AccountImageVisibility, User, UserID, UserPageStatus}; use crate::data::user_token::UserAccessToken; @@ -294,6 +295,15 @@ pub fn set_data_conservation_policy(new_policy: NewDataConservationPolicy) -> Re .exec() } +/// Set new notifications settings +pub fn set_notifications_settings(new_settings: NewNotificationsSettings) -> Res { + database::UpdateInfo::new(USERS_TABLE) + .cond_user_id("ID", &new_settings.user_id) + .set_legacy_bool("allow_notif_sound", new_settings.allow_notifications_sound) + .set_legacy_bool("allow_notif_conv", new_settings.allow_conversations) + .exec() +} + /// Export an account's data pub fn export(user_id: &UserID) -> ResultBoxError { let mut data = AccountExport { diff --git a/src/routes.rs b/src/routes.rs index 2f4edb3..8a97daf 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -175,6 +175,7 @@ pub fn get_routes() -> Vec { Route::post("/settings/get_data_conservation_policy", Box::new(settings_controller::get_data_conservation_policy)), Route::limited_post("/settings/set_data_conservation_policy", Box::new(settings_controller::set_data_conservation_policy), LimitPolicy::FAILURE(10)), Route::post("/settings/get_notifications", Box::new(settings_controller::get_notifications)), + Route::post("/settings/set_notifications", Box::new(settings_controller::set_notifications)), // Friends controller