1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-26 15:29:21 +00:00

Isolate conversations server settings

This commit is contained in:
Pierre HUBERT 2021-03-12 16:02:54 +01:00
parent 158b2caf98
commit 7d2d26f75b
3 changed files with 53 additions and 43 deletions

View File

@ -3,7 +3,8 @@
//! @author Pierre Hubert //! @author Pierre Hubert
use serde::Serialize; use serde::Serialize;
use crate::constants::{ALLOWED_CONVERSATION_FILES_TYPES, conservation_policy, CONVERSATION_FILES_MAX_SIZE, CONVERSATION_WRITING_EVENT_INTERVAL, CONVERSATION_WRITING_EVENT_LIFETIME, MAX_CONVERSATION_MESSAGE_LENGTH, MIN_CONVERSATION_MESSAGE_LENGTH, MIN_SUPPORTED_MOBILE_VERSION, password_policy}; 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_CONVERSATION_MESSAGE_LENGTH, MIN_CONVERSATION_MESSAGE_LENGTH};
use crate::data::config::conf; use crate::data::config::conf;
#[derive(Serialize)] #[derive(Serialize)]
@ -28,6 +29,16 @@ struct DataConservationPolicy {
min_likes_lifetime: u64, min_likes_lifetime: u64,
} }
#[derive(Serialize)]
struct ConversationsPolicy {
min_conversation_message_len: usize,
max_conversation_message_len: usize,
allowed_conversation_files_type: [&'static str; 17],
conversation_files_max_size: usize,
conversation_writing_event_interval: u64,
conversation_writing_event_lifetime: u64,
}
#[derive(Serialize)] #[derive(Serialize)]
pub struct ServerConfig { pub struct ServerConfig {
min_supported_mobile_version: &'static str, min_supported_mobile_version: &'static str,
@ -37,13 +48,7 @@ pub struct ServerConfig {
android_direct_download_url: String, android_direct_download_url: String,
password_policy: PasswordPolicy, password_policy: PasswordPolicy,
data_conservation_policy: DataConservationPolicy, data_conservation_policy: DataConservationPolicy,
conversations_policy: ConversationsPolicy,
min_conversation_message_len: usize,
max_conversation_message_len: usize,
allowed_conversation_files_type: [&'static str; 17],
conversation_files_max_size: usize,
conversation_writing_event_interval: u64,
conversation_writing_event_lifetime: u64,
} }
impl ServerConfig { impl ServerConfig {
@ -55,13 +60,6 @@ impl ServerConfig {
play_store_url: &conf().play_store_url, play_store_url: &conf().play_store_url,
android_direct_download_url: conf().android_direct_download_url.clone(), android_direct_download_url: conf().android_direct_download_url.clone(),
min_conversation_message_len: MIN_CONVERSATION_MESSAGE_LENGTH,
max_conversation_message_len: MAX_CONVERSATION_MESSAGE_LENGTH,
allowed_conversation_files_type: ALLOWED_CONVERSATION_FILES_TYPES,
conversation_files_max_size: CONVERSATION_FILES_MAX_SIZE,
conversation_writing_event_interval: CONVERSATION_WRITING_EVENT_INTERVAL,
conversation_writing_event_lifetime: CONVERSATION_WRITING_EVENT_LIFETIME,
password_policy: PasswordPolicy { password_policy: PasswordPolicy {
allow_email_in_password: password_policy::ALLOW_EMAIL_IN_PASSWORD, allow_email_in_password: password_policy::ALLOW_EMAIL_IN_PASSWORD,
allow_name_in_password: password_policy::ALLOW_NAME_IN_PASSWORD, allow_name_in_password: password_policy::ALLOW_NAME_IN_PASSWORD,
@ -81,6 +79,15 @@ impl ServerConfig {
min_conversation_messages_lifetime: conservation_policy::MIN_CONVERSATION_MESSAGES_LIFETIME.as_secs(), min_conversation_messages_lifetime: conservation_policy::MIN_CONVERSATION_MESSAGES_LIFETIME.as_secs(),
min_likes_lifetime: conservation_policy::MIN_LIKES_LIFETIME.as_secs(), min_likes_lifetime: conservation_policy::MIN_LIKES_LIFETIME.as_secs(),
}, },
conversations_policy: ConversationsPolicy {
min_conversation_message_len: MIN_CONVERSATION_MESSAGE_LENGTH,
max_conversation_message_len: MAX_CONVERSATION_MESSAGE_LENGTH,
allowed_conversation_files_type: ALLOWED_CONVERSATION_FILES_TYPES,
conversation_files_max_size: CONVERSATION_FILES_MAX_SIZE,
conversation_writing_event_interval: CONVERSATION_WRITING_EVENT_INTERVAL,
conversation_writing_event_lifetime: CONVERSATION_WRITING_EVENT_LIFETIME,
},
} }
} }
} }

View File

@ -164,6 +164,8 @@ pub const CLEAN_UP_INTERVAL: Duration = Duration::from_secs(60 * 60);
/// Minimal mobile version supported /// Minimal mobile version supported
pub const MIN_SUPPORTED_MOBILE_VERSION: &str = "1.1.2"; pub const MIN_SUPPORTED_MOBILE_VERSION: &str = "1.1.2";
/// Conversations constants
pub mod conversations {
/// Minimum message length /// Minimum message length
pub const MIN_CONVERSATION_MESSAGE_LENGTH: usize = 1; pub const MIN_CONVERSATION_MESSAGE_LENGTH: usize = 1;
pub const MAX_CONVERSATION_MESSAGE_LENGTH: usize = 16000; pub const MAX_CONVERSATION_MESSAGE_LENGTH: usize = 16000;
@ -198,3 +200,4 @@ pub const CONVERSATION_WRITING_EVENT_INTERVAL: u64 = 1;
/// Lifetime of conversation writing event /// Lifetime of conversation writing event
pub const CONVERSATION_WRITING_EVENT_LIFETIME: u64 = 3; pub const CONVERSATION_WRITING_EVENT_LIFETIME: u64 = 3;
}

View File

@ -12,7 +12,7 @@ use crate::api_data::res_count_unread_conversations::ResultCountUnreadConversati
use crate::api_data::res_create_conversation::ResCreateConversation; use crate::api_data::res_create_conversation::ResCreateConversation;
use crate::api_data::res_find_private_conversations::ResFindPrivateConversations; use crate::api_data::res_find_private_conversations::ResFindPrivateConversations;
use crate::api_data::user_is_writing_message_in_conversation::UserIsWritingMessageInConversation; use crate::api_data::user_is_writing_message_in_conversation::UserIsWritingMessageInConversation;
use crate::constants::{ALLOWED_CONVERSATION_FILES_TYPES, CONVERSATION_FILES_MAX_SIZE, MAX_CONVERSATION_MESSAGE_LENGTH, MIN_CONVERSATION_MESSAGE_LENGTH}; use crate::constants::conversations::{ALLOWED_CONVERSATION_FILES_TYPES, CONVERSATION_FILES_MAX_SIZE, MAX_CONVERSATION_MESSAGE_LENGTH, MIN_CONVERSATION_MESSAGE_LENGTH};
use crate::controllers::user_ws_controller; use crate::controllers::user_ws_controller;
use crate::data::base_request_handler::{BaseRequestHandler, RequestValue}; use crate::data::base_request_handler::{BaseRequestHandler, RequestValue};
use crate::data::conversation::NewConversationSettings; use crate::data::conversation::NewConversationSettings;