1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-22 21:39: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
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;
#[derive(Serialize)]
@ -28,6 +29,16 @@ struct DataConservationPolicy {
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)]
pub struct ServerConfig {
min_supported_mobile_version: &'static str,
@ -37,13 +48,7 @@ pub struct ServerConfig {
android_direct_download_url: String,
password_policy: PasswordPolicy,
data_conservation_policy: DataConservationPolicy,
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,
conversations_policy: ConversationsPolicy,
}
impl ServerConfig {
@ -55,13 +60,6 @@ impl ServerConfig {
play_store_url: &conf().play_store_url,
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 {
allow_email_in_password: password_policy::ALLOW_EMAIL_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_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,37 +164,40 @@ pub const CLEAN_UP_INTERVAL: Duration = Duration::from_secs(60 * 60);
/// Minimal mobile version supported
pub const MIN_SUPPORTED_MOBILE_VERSION: &str = "1.1.2";
/// Minimum message length
pub const MIN_CONVERSATION_MESSAGE_LENGTH: usize = 1;
pub const MAX_CONVERSATION_MESSAGE_LENGTH: usize = 16000;
/// Conversations constants
pub mod conversations {
/// Minimum message length
pub const MIN_CONVERSATION_MESSAGE_LENGTH: usize = 1;
pub const MAX_CONVERSATION_MESSAGE_LENGTH: usize = 16000;
/// Allowed files type in conversations
pub const ALLOWED_CONVERSATION_FILES_TYPES: [&str; 17] = [
"image/png", "image/jpeg", "image/gif", "image/bmp",
"application/pdf",
"audio/mpeg",
"video/mp4",
"application/zip",
/// Allowed files type in conversations
pub const ALLOWED_CONVERSATION_FILES_TYPES: [&str; 17] = [
"image/png", "image/jpeg", "image/gif", "image/bmp",
"application/pdf",
"audio/mpeg",
"video/mp4",
"application/zip",
// MS Office docs
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
// MS Office docs
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
// Open Office docs
"application/vnd.oasis.opendocument.text",
"application/vnd.oasis.opendocument.presentation",
"application/vnd.oasis.opendocument.spreadsheet",
// Open Office docs
"application/vnd.oasis.opendocument.text",
"application/vnd.oasis.opendocument.presentation",
"application/vnd.oasis.opendocument.spreadsheet",
// Source code docs (UTF-8 encoded)
"text/x-csrc", "text/plain", "text/x-c++src"
];
// Source code docs (UTF-8 encoded)
"text/x-csrc", "text/plain", "text/x-c++src"
];
/// File maximum size in conversations (10 Mb)
pub const CONVERSATION_FILES_MAX_SIZE: usize = 10 * 1024 * 1024;
/// File maximum size in conversations (10 Mb)
pub const CONVERSATION_FILES_MAX_SIZE: usize = 10 * 1024 * 1024;
/// Minimum interval before notifying again that someone is writing
pub const CONVERSATION_WRITING_EVENT_INTERVAL: u64 = 1;
/// Minimum interval before notifying again that someone is writing
pub const CONVERSATION_WRITING_EVENT_INTERVAL: u64 = 1;
/// Lifetime of conversation writing event
pub const CONVERSATION_WRITING_EVENT_LIFETIME: u64 = 3;
/// Lifetime of conversation writing event
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_find_private_conversations::ResFindPrivateConversations;
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::data::base_request_handler::{BaseRequestHandler, RequestValue};
use crate::data::conversation::NewConversationSettings;