2021-02-16 18:30:06 +00:00
|
|
|
import 'package:comunic/models/api_request.dart';
|
|
|
|
import 'package:comunic/models/server_config.dart';
|
2021-02-20 08:24:51 +00:00
|
|
|
import 'package:version/version.dart';
|
2021-02-16 18:30:06 +00:00
|
|
|
|
|
|
|
/// Server configuration helper
|
|
|
|
///
|
|
|
|
/// @author Pierre Hubert
|
|
|
|
|
|
|
|
class ServerConfigurationHelper {
|
|
|
|
static ServerConfig _config;
|
|
|
|
|
|
|
|
/// Make sure the configuration has been correctly loaded
|
|
|
|
static Future<void> ensureLoaded() async {
|
|
|
|
if (_config != null) return;
|
|
|
|
|
|
|
|
final response =
|
|
|
|
(await APIRequest.withoutLogin("server/config").execWithThrow())
|
|
|
|
.getObject();
|
|
|
|
|
2021-04-12 17:26:05 +00:00
|
|
|
final pushNotificationsPolicy = response["push_notifications"];
|
2021-02-18 17:20:50 +00:00
|
|
|
final passwordPolicy = response["password_policy"];
|
2021-02-16 18:30:06 +00:00
|
|
|
final dataConservationPolicy = response["data_conservation_policy"];
|
2021-03-12 15:19:07 +00:00
|
|
|
final conversationsPolicy = response["conversations_policy"];
|
2021-02-16 18:30:06 +00:00
|
|
|
|
|
|
|
_config = ServerConfig(
|
2021-03-12 15:19:07 +00:00
|
|
|
minSupportedMobileVersion:
|
|
|
|
Version.parse(response["min_supported_mobile_version"]),
|
|
|
|
termsURL: response["terms_url"],
|
|
|
|
playStoreURL: response["play_store_url"],
|
|
|
|
androidDirectDownloadURL: response["android_direct_download_url"],
|
2021-04-12 17:26:05 +00:00
|
|
|
notificationsPolicy: NotificationsPolicy(
|
|
|
|
hasFirebase: pushNotificationsPolicy["has_firebase"],
|
|
|
|
hasIndependent: pushNotificationsPolicy["has_independent"],
|
|
|
|
),
|
2021-03-12 15:19:07 +00:00
|
|
|
passwordPolicy: PasswordPolicy(
|
|
|
|
allowMailInPassword: passwordPolicy["allow_email_in_password"],
|
|
|
|
allowNameInPassword: passwordPolicy["allow_name_in_password"],
|
|
|
|
minPasswordLength: passwordPolicy["min_password_length"],
|
|
|
|
minNumberUpperCaseLetters:
|
|
|
|
passwordPolicy["min_number_upper_case_letters"],
|
|
|
|
minNumberLowerCaseLetters:
|
|
|
|
passwordPolicy["min_number_lower_case_letters"],
|
|
|
|
minNumberDigits: passwordPolicy["min_number_digits"],
|
|
|
|
minNumberSpecialCharacters:
|
|
|
|
passwordPolicy["min_number_special_characters"],
|
|
|
|
minCategoriesPresence: passwordPolicy["min_categories_presence"],
|
|
|
|
),
|
|
|
|
dataConservationPolicy: ServerDataConservationPolicy(
|
|
|
|
minInactiveAccountLifetime:
|
|
|
|
dataConservationPolicy["min_inactive_account_lifetime"],
|
|
|
|
minNotificationLifetime:
|
|
|
|
dataConservationPolicy["min_notification_lifetime"],
|
|
|
|
minCommentsLifetime: dataConservationPolicy["min_comments_lifetime"],
|
|
|
|
minPostsLifetime: dataConservationPolicy["min_posts_lifetime"],
|
|
|
|
minConversationMessagesLifetime:
|
|
|
|
dataConservationPolicy["min_conversation_messages_lifetime"],
|
|
|
|
minLikesLifetime: dataConservationPolicy["min_likes_lifetime"],
|
|
|
|
),
|
|
|
|
conversationsPolicy: ConversationsPolicy(
|
2021-04-06 15:04:55 +00:00
|
|
|
maxConversationNameLen:
|
|
|
|
conversationsPolicy["max_conversation_name_len"],
|
2021-03-12 15:19:07 +00:00
|
|
|
minMessageLen: conversationsPolicy["min_message_len"],
|
|
|
|
maxMessageLen: conversationsPolicy["max_message_len"],
|
2021-03-12 18:36:42 +00:00
|
|
|
allowedFilesType:
|
|
|
|
conversationsPolicy["allowed_files_type"].cast<String>(),
|
2021-03-12 15:19:07 +00:00
|
|
|
filesMaxSize: conversationsPolicy["files_max_size"],
|
|
|
|
writingEventInterval: conversationsPolicy["writing_event_interval"],
|
|
|
|
writingEventLifetime: conversationsPolicy["writing_event_lifetime"],
|
2021-03-12 18:36:42 +00:00
|
|
|
maxMessageImageWidth: conversationsPolicy["max_message_image_width"],
|
|
|
|
maxMessageImageHeight:
|
|
|
|
conversationsPolicy["max_message_image_height"],
|
|
|
|
maxThumbnailWidth: conversationsPolicy["max_thumbnail_width"],
|
|
|
|
maxThumbnailHeight: conversationsPolicy["max_thumbnail_height"],
|
2021-03-13 10:33:25 +00:00
|
|
|
maxLogoWidth: conversationsPolicy["max_logo_width"],
|
|
|
|
maxLogoHeight: conversationsPolicy["max_logo_height"],
|
2021-03-12 15:19:07 +00:00
|
|
|
));
|
2021-02-16 18:30:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Get current server configuration, throwing if it is not loaded yet
|
|
|
|
static ServerConfig get config {
|
|
|
|
if (_config == null)
|
|
|
|
throw Exception(
|
|
|
|
"Trying to access server configuration but it is not loaded yet!");
|
|
|
|
|
|
|
|
return _config;
|
|
|
|
}
|
|
|
|
}
|
2021-03-12 17:54:15 +00:00
|
|
|
|
|
|
|
/// Shortcut for server configuration
|
2021-03-12 18:36:42 +00:00
|
|
|
ServerConfig get srvConfig => ServerConfigurationHelper.config;
|