diff --git a/config.yaml b/config.yaml index b67b99d..f67c67d 100644 --- a/config.yaml +++ b/config.yaml @@ -28,6 +28,16 @@ android-direct-download-url: https://files.communiquons.org/comunic/mobile/lates # Print more information to the console verbose-mode: true +# Independent push notification service information +independent-push-service: + # Server access (to create clients and push notifications) + control-url: http://localhost:4500/ + control-token: BADTOKENTOCHANGE + + # Public access URL pattern (for clients access) {TOKEN_URL} will be replaced by client token + public-url: http://localhost:4500/ws/{TOKEN_URL} + + # Database configuration database: host: localhost diff --git a/src/api_data/server_config.rs b/src/api_data/server_config.rs index e36dc8e..c895228 100644 --- a/src/api_data/server_config.rs +++ b/src/api_data/server_config.rs @@ -6,6 +6,13 @@ use serde::Serialize; use crate::constants::{conservation_policy, MIN_SUPPORTED_MOBILE_VERSION, password_policy}; use crate::constants::conversations::{ALLOWED_CONVERSATION_FILES_TYPES, CONVERSATION_FILES_MAX_SIZE, CONVERSATION_WRITING_EVENT_INTERVAL, CONVERSATION_WRITING_EVENT_LIFETIME, MAX_CONV_IMAGE_MESSAGE_WIDTH, MAX_CONV_LOGO_HEIGHT, MAX_CONV_LOGO_WIDTH, MAX_CONV_MESSAGE_THUMBNAIL_HEIGHT, MAX_CONV_MESSAGE_THUMBNAIL_WIDTH, MAX_CONVERSATION_MESSAGE_LENGTH, MAX_CONVERSATION_NAME_LENGTH, MIN_CONVERSATION_MESSAGE_LENGTH}; use crate::data::config::conf; +use crate::data::api_client::APIClient; + +#[derive(Serialize)] +struct NotificationsConfig { + has_firebase: bool, + has_independent: bool, +} #[derive(Serialize)] struct PasswordPolicy { @@ -53,13 +60,15 @@ pub struct ServerConfig { privacy_policy_url: &'static str, play_store_url: &'static str, android_direct_download_url: String, + + notifications: NotificationsConfig, password_policy: PasswordPolicy, data_conservation_policy: DataConservationPolicy, conversations_policy: ConversationsPolicy, } impl ServerConfig { - pub fn new() -> Self { + pub fn new(c: &APIClient) -> Self { ServerConfig { min_supported_mobile_version: MIN_SUPPORTED_MOBILE_VERSION, terms_url: &conf().terms_url, @@ -67,6 +76,11 @@ impl ServerConfig { play_store_url: &conf().play_store_url, android_direct_download_url: conf().android_direct_download_url.clone(), + notifications: NotificationsConfig { + has_firebase: c.firebase_token.is_some(), + has_independent: conf().independent_push_service.is_some(), + }, + password_policy: PasswordPolicy { allow_email_in_password: password_policy::ALLOW_EMAIL_IN_PASSWORD, allow_name_in_password: password_policy::ALLOW_NAME_IN_PASSWORD, diff --git a/src/controllers/server_controller.rs b/src/controllers/server_controller.rs index de8c15f..31445e6 100644 --- a/src/controllers/server_controller.rs +++ b/src/controllers/server_controller.rs @@ -14,5 +14,5 @@ pub fn main_index(request: &mut HttpRequestHandler) -> RequestResult { /// Get server configuration pub fn get_config(request: &mut HttpRequestHandler) -> RequestResult { - request.set_response(ServerConfig::new()) + request.set_response(ServerConfig::new(request.api_client())) } \ No newline at end of file diff --git a/src/data/config.rs b/src/data/config.rs index f3dfa0b..ac72d1e 100644 --- a/src/data/config.rs +++ b/src/data/config.rs @@ -24,6 +24,13 @@ pub struct RtcRelayConfig { pub max_users_per_video_calls: u64, } +#[derive(Debug)] +pub struct IndependentPushService { + pub control_url: String, + pub control_token: String, + pub public_url: String, +} + #[derive(Debug)] pub struct Config { pub port: i32, @@ -36,6 +43,7 @@ pub struct Config { pub android_direct_download_url: String, pub proxy: Option, pub verbose_mode: bool, + pub independent_push_service: Option, pub database: DatabaseConfig, pub rtc_relay: Option, } @@ -97,6 +105,16 @@ impl Config { let proxy = Config::yaml_str(parsed, "proxy"); + let parsed_independent_push_service = &parsed["independent-push-service"]; + let independent_push_service = match parsed_independent_push_service.is_badvalue() { + true => None, + false => Some(IndependentPushService { + control_url: Config::yaml_str(parsed_independent_push_service, "control-url"), + control_token: Config::yaml_str(parsed_independent_push_service, "control-token"), + public_url: Config::yaml_str(parsed_independent_push_service, "public-url"), + }) + }; + let conf = Config { port: Config::yaml_i32(parsed, "server-port") as i32, listen_address: Config::yaml_str(parsed, "server-address"), @@ -117,6 +135,8 @@ impl Config { verbose_mode: Config::yaml_bool(parsed, "verbose-mode"), + independent_push_service, + database: database_conf, rtc_relay: rtc_config,