mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-26 07:19:22 +00:00
Can set (update) notifications settings
This commit is contained in:
parent
138142f52d
commit
c6306eee7f
@ -16,6 +16,7 @@ use crate::data::http_request_handler::HttpRequestHandler;
|
|||||||
use crate::data::lang_settings::LangSettings;
|
use crate::data::lang_settings::LangSettings;
|
||||||
use crate::data::new_custom_emoji::NewCustomEmoji;
|
use crate::data::new_custom_emoji::NewCustomEmoji;
|
||||||
use crate::data::new_data_conservation_policy::NewDataConservationPolicy;
|
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::security_settings::{SecurityQuestion, SecuritySettings};
|
||||||
use crate::data::user::{AccountImageVisibility, UserPageStatus};
|
use crate::data::user::{AccountImageVisibility, UserPageStatus};
|
||||||
use crate::helpers::{account_helper, custom_emojies_helper, user_helper};
|
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!")
|
r.success("Successfully updated data conservation policy!")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get notification settings
|
/// Get notifications settings
|
||||||
pub fn get_notifications(r: &mut HttpRequestHandler) -> RequestResult {
|
pub fn get_notifications(r: &mut HttpRequestHandler) -> RequestResult {
|
||||||
let user = user_helper::find_user_by_id(r.user_id_ref()?)?;
|
let user = user_helper::find_user_by_id(r.user_id_ref()?)?;
|
||||||
|
|
||||||
r.set_response(NotificationSettingsAPI::new(&user))
|
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()
|
||||||
}
|
}
|
@ -37,4 +37,5 @@ pub mod new_data_conservation_policy;
|
|||||||
pub mod new_custom_emoji;
|
pub mod new_custom_emoji;
|
||||||
pub mod user_ws_message;
|
pub mod user_ws_message;
|
||||||
pub mod user_ws_connection;
|
pub mod user_ws_connection;
|
||||||
pub mod call_signal;
|
pub mod call_signal;
|
||||||
|
pub mod new_notifications_settings;
|
11
src/data/new_notifications_settings.rs
Normal file
11
src/data/new_notifications_settings.rs
Normal file
@ -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,
|
||||||
|
}
|
@ -10,6 +10,7 @@ use crate::data::general_settings::GeneralSettings;
|
|||||||
use crate::data::lang_settings::LangSettings;
|
use crate::data::lang_settings::LangSettings;
|
||||||
use crate::data::new_account::NewAccount;
|
use crate::data::new_account::NewAccount;
|
||||||
use crate::data::new_data_conservation_policy::NewDataConservationPolicy;
|
use crate::data::new_data_conservation_policy::NewDataConservationPolicy;
|
||||||
|
use crate::data::new_notifications_settings::NewNotificationsSettings;
|
||||||
use crate::data::security_settings::SecuritySettings;
|
use crate::data::security_settings::SecuritySettings;
|
||||||
use crate::data::user::{AccountImageVisibility, User, UserID, UserPageStatus};
|
use crate::data::user::{AccountImageVisibility, User, UserID, UserPageStatus};
|
||||||
use crate::data::user_token::UserAccessToken;
|
use crate::data::user_token::UserAccessToken;
|
||||||
@ -294,6 +295,15 @@ pub fn set_data_conservation_policy(new_policy: NewDataConservationPolicy) -> Re
|
|||||||
.exec()
|
.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
|
/// Export an account's data
|
||||||
pub fn export(user_id: &UserID) -> ResultBoxError<AccountExport> {
|
pub fn export(user_id: &UserID) -> ResultBoxError<AccountExport> {
|
||||||
let mut data = AccountExport {
|
let mut data = AccountExport {
|
||||||
|
@ -175,6 +175,7 @@ pub fn get_routes() -> Vec<Route> {
|
|||||||
Route::post("/settings/get_data_conservation_policy", Box::new(settings_controller::get_data_conservation_policy)),
|
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::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/get_notifications", Box::new(settings_controller::get_notifications)),
|
||||||
|
Route::post("/settings/set_notifications", Box::new(settings_controller::set_notifications)),
|
||||||
|
|
||||||
|
|
||||||
// Friends controller
|
// Friends controller
|
||||||
|
Loading…
Reference in New Issue
Block a user