mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-26 07:19:22 +00:00
Can get notification settings
This commit is contained in:
parent
7ec2c500e3
commit
2b2b1c9755
@ -69,3 +69,4 @@ pub mod res_check_password_token;
|
||||
pub mod removed_user_from_conv_message;
|
||||
pub mod user_is_writing_message_in_conversation;
|
||||
pub mod res_create_conversation_for_group;
|
||||
pub mod notification_settings_api;
|
20
src/api_data/notification_settings_api.rs
Normal file
20
src/api_data/notification_settings_api.rs
Normal file
@ -0,0 +1,20 @@
|
||||
//! # Notification settings API
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::data::user::User;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct NotificationSettingsAPI {
|
||||
allow_conversations: bool,
|
||||
}
|
||||
|
||||
impl NotificationSettingsAPI {
|
||||
pub fn new(user: &User) -> Self {
|
||||
Self {
|
||||
allow_conversations: user.allow_notif_conv
|
||||
}
|
||||
}
|
||||
}
|
@ -2,8 +2,6 @@
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use webrtc_sdp::attribute_type::SdpAttribute;
|
||||
|
||||
use crate::api_data::call_member_info::CallMemberInfo;
|
||||
@ -19,7 +17,6 @@ use crate::data::call_signal::{CallSignal, CloseCallStream, IceCandidate, NewUse
|
||||
use crate::data::config::conf;
|
||||
use crate::data::conversation::ConvID;
|
||||
use crate::data::error::{ExecError, Res};
|
||||
use crate::data::http_request_handler::HttpRequestHandler;
|
||||
use crate::data::user::UserID;
|
||||
use crate::data::user_ws_connection::{ActiveCall, UserWsConnection};
|
||||
use crate::data::user_ws_message::UserWsMessage;
|
||||
@ -90,13 +87,6 @@ impl UserWsRequestHandler {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get legacy call configuration
|
||||
pub fn get_legacy_config(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let mut map = HashMap::new();
|
||||
map.insert("enabled", false);
|
||||
r.set_response(map)
|
||||
}
|
||||
|
||||
/// Get calls configuration
|
||||
pub fn get_config(r: &mut UserWsRequestHandler) -> RequestResult {
|
||||
// Check whether the user is the member of a call or not
|
||||
|
@ -6,6 +6,7 @@ use crate::api_data::account_image_settings_api::AccountImageSettingsAPI;
|
||||
use crate::api_data::data_conservation_settings_api::DataConservationSettingsAPI;
|
||||
use crate::api_data::general_settings_api::GeneralSettingsAPI;
|
||||
use crate::api_data::language_settings_api::LanguageSettingsAPI;
|
||||
use crate::api_data::notification_settings_api::NotificationSettingsAPI;
|
||||
use crate::api_data::res_create_custom_emoji::ResCreateCustomEmoji;
|
||||
use crate::api_data::security_settings_api::SecuritySettingsAPI;
|
||||
use crate::constants::{conservation_policy, SUPPORTED_LANGUAGES};
|
||||
@ -257,3 +258,10 @@ pub fn set_data_conservation_policy(r: &mut HttpRequestHandler) -> RequestResult
|
||||
|
||||
r.success("Successfully updated data conservation policy!")
|
||||
}
|
||||
|
||||
/// Get notification 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))
|
||||
}
|
@ -129,6 +129,9 @@ pub struct User {
|
||||
pub delete_posts_after: Option<u64>,
|
||||
pub delete_conversation_messages_after: Option<u64>,
|
||||
pub delete_likes_after: Option<u64>,
|
||||
|
||||
/// Notifications settings
|
||||
pub allow_notif_conv: bool,
|
||||
}
|
||||
|
||||
impl User {
|
||||
|
@ -79,12 +79,17 @@ fn db_to_user(res: &database::RowResult) -> ResultBoxError<User> {
|
||||
security_answer_1: res.get_optional_str("reponse1")?,
|
||||
security_question_2: res.get_optional_str("question2")?,
|
||||
security_answer_2: res.get_optional_str("reponse2")?,
|
||||
|
||||
// Data cleanup
|
||||
delete_account_after: res.get_optional_positive_u64("delete_account_after")?,
|
||||
delete_notifications_after: res.get_optional_positive_u64("delete_notifications_after")?,
|
||||
delete_comments_after: res.get_optional_positive_u64("delete_comments_after")?,
|
||||
delete_posts_after: res.get_optional_positive_u64("delete_posts_after")?,
|
||||
delete_conversation_messages_after: res.get_optional_positive_u64("delete_conversation_messages_after")?,
|
||||
delete_likes_after: res.get_optional_positive_u64("delete_likes_after")?,
|
||||
|
||||
// Conversation settings
|
||||
allow_notif_conv: res.get_legacy_bool("allow_notif_conv")?,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::error::Error;
|
||||
|
||||
use crate::controllers::{account_controller, calls_controller, comments_controller, conversations_controller, friends_controller, groups_controller, likes_controller, notifications_controller, posts_controller, search_controller, server_controller, settings_controller, surveys_controller, user_controller, user_ws_controller, virtual_directory_controller, web_app_controller};
|
||||
use crate::controllers::{account_controller, comments_controller, conversations_controller, friends_controller, groups_controller, likes_controller, notifications_controller, posts_controller, search_controller, server_controller, settings_controller, surveys_controller, user_controller, user_ws_controller, virtual_directory_controller, web_app_controller};
|
||||
use crate::data::http_request_handler::HttpRequestHandler;
|
||||
use crate::routes::Method::{GET, POST};
|
||||
|
||||
@ -174,6 +174,7 @@ pub fn get_routes() -> Vec<Route> {
|
||||
Route::post("/settings/delete_custom_emoji", Box::new(settings_controller::delete_custom_emoji)),
|
||||
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)),
|
||||
|
||||
|
||||
// Friends controller
|
||||
@ -291,8 +292,5 @@ pub fn get_routes() -> Vec<Route> {
|
||||
|
||||
// Web application controller
|
||||
Route::post("/webApp/getMemberships", Box::new(web_app_controller::get_memberships)),
|
||||
|
||||
// Calls controller
|
||||
Route::post("/calls/config", Box::new(calls_controller::get_legacy_config)),
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user