mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-02-17 06:02:39 +00:00
45 lines
1.4 KiB
Dart
45 lines
1.4 KiB
Dart
|
import 'package:comunic/models/api_request.dart';
|
||
|
import 'package:comunic/models/server_config.dart';
|
||
|
|
||
|
/// 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();
|
||
|
|
||
|
final dataConservationPolicy = response["data_conservation_policy"];
|
||
|
|
||
|
_config = ServerConfig(
|
||
|
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"],
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
|
||
|
/// 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;
|
||
|
}
|
||
|
}
|