2021-12-30 11:02:18 +00:00
|
|
|
import 'package:comunic/utils/date_utils.dart';
|
2021-02-20 08:24:51 +00:00
|
|
|
import 'package:version/version.dart';
|
2021-02-16 18:30:06 +00:00
|
|
|
|
|
|
|
/// Server static configuration
|
|
|
|
///
|
|
|
|
/// @author Pierre Hubert
|
|
|
|
|
2021-04-12 17:26:05 +00:00
|
|
|
class NotificationsPolicy {
|
|
|
|
final bool hasFirebase;
|
|
|
|
final bool hasIndependent;
|
|
|
|
|
|
|
|
const NotificationsPolicy({
|
2022-03-10 18:39:57 +00:00
|
|
|
required this.hasFirebase,
|
|
|
|
required this.hasIndependent,
|
2021-04-12 17:26:05 +00:00
|
|
|
}) : assert(hasFirebase != null),
|
|
|
|
assert(hasIndependent != null);
|
|
|
|
}
|
|
|
|
|
2021-02-18 17:20:50 +00:00
|
|
|
class PasswordPolicy {
|
|
|
|
final bool allowMailInPassword;
|
|
|
|
final bool allowNameInPassword;
|
|
|
|
final int minPasswordLength;
|
|
|
|
final int minNumberUpperCaseLetters;
|
|
|
|
final int minNumberLowerCaseLetters;
|
|
|
|
final int minNumberDigits;
|
|
|
|
final int minNumberSpecialCharacters;
|
|
|
|
final int minCategoriesPresence;
|
|
|
|
|
|
|
|
const PasswordPolicy({
|
2022-03-10 18:39:57 +00:00
|
|
|
required this.allowMailInPassword,
|
|
|
|
required this.allowNameInPassword,
|
|
|
|
required this.minPasswordLength,
|
|
|
|
required this.minNumberUpperCaseLetters,
|
|
|
|
required this.minNumberLowerCaseLetters,
|
|
|
|
required this.minNumberDigits,
|
|
|
|
required this.minNumberSpecialCharacters,
|
|
|
|
required this.minCategoriesPresence,
|
2021-02-18 17:20:50 +00:00
|
|
|
}) : assert(allowMailInPassword != null),
|
|
|
|
assert(allowNameInPassword != null),
|
|
|
|
assert(minPasswordLength != null),
|
|
|
|
assert(minNumberUpperCaseLetters != null),
|
|
|
|
assert(minNumberLowerCaseLetters != null),
|
|
|
|
assert(minNumberDigits != null),
|
|
|
|
assert(minNumberSpecialCharacters != null),
|
|
|
|
assert(minCategoriesPresence != null);
|
|
|
|
}
|
|
|
|
|
2021-02-16 18:30:06 +00:00
|
|
|
class ServerDataConservationPolicy {
|
|
|
|
final int minInactiveAccountLifetime;
|
|
|
|
final int minNotificationLifetime;
|
|
|
|
final int minCommentsLifetime;
|
|
|
|
final int minPostsLifetime;
|
|
|
|
final int minConversationMessagesLifetime;
|
|
|
|
final int minLikesLifetime;
|
|
|
|
|
|
|
|
const ServerDataConservationPolicy({
|
2022-03-10 18:39:57 +00:00
|
|
|
required this.minInactiveAccountLifetime,
|
|
|
|
required this.minNotificationLifetime,
|
|
|
|
required this.minCommentsLifetime,
|
|
|
|
required this.minPostsLifetime,
|
|
|
|
required this.minConversationMessagesLifetime,
|
|
|
|
required this.minLikesLifetime,
|
2021-02-16 18:30:06 +00:00
|
|
|
}) : assert(minInactiveAccountLifetime != null),
|
|
|
|
assert(minNotificationLifetime != null),
|
|
|
|
assert(minCommentsLifetime != null),
|
|
|
|
assert(minPostsLifetime != null),
|
|
|
|
assert(minConversationMessagesLifetime != null),
|
|
|
|
assert(minLikesLifetime != null);
|
|
|
|
}
|
|
|
|
|
2021-03-12 15:19:07 +00:00
|
|
|
class ConversationsPolicy {
|
2021-04-06 15:04:55 +00:00
|
|
|
final int maxConversationNameLen;
|
2021-03-12 15:19:07 +00:00
|
|
|
final int minMessageLen;
|
|
|
|
final int maxMessageLen;
|
|
|
|
final List<String> allowedFilesType;
|
|
|
|
final int filesMaxSize;
|
|
|
|
final int writingEventInterval;
|
|
|
|
final int writingEventLifetime;
|
2021-03-12 18:36:42 +00:00
|
|
|
final int maxMessageImageWidth;
|
|
|
|
final int maxMessageImageHeight;
|
|
|
|
final int maxThumbnailWidth;
|
|
|
|
final int maxThumbnailHeight;
|
2021-03-13 10:33:25 +00:00
|
|
|
final int maxLogoWidth;
|
|
|
|
final int maxLogoHeight;
|
2021-03-12 15:19:07 +00:00
|
|
|
|
|
|
|
const ConversationsPolicy({
|
2022-03-10 18:39:57 +00:00
|
|
|
required this.maxConversationNameLen,
|
|
|
|
required this.minMessageLen,
|
|
|
|
required this.maxMessageLen,
|
|
|
|
required this.allowedFilesType,
|
|
|
|
required this.filesMaxSize,
|
|
|
|
required this.writingEventInterval,
|
|
|
|
required this.writingEventLifetime,
|
|
|
|
required this.maxMessageImageWidth,
|
|
|
|
required this.maxMessageImageHeight,
|
|
|
|
required this.maxThumbnailWidth,
|
|
|
|
required this.maxThumbnailHeight,
|
|
|
|
required this.maxLogoWidth,
|
|
|
|
required this.maxLogoHeight,
|
2021-04-06 15:04:55 +00:00
|
|
|
}) : assert(maxConversationNameLen != null),
|
|
|
|
assert(minMessageLen != null),
|
2021-03-12 15:19:07 +00:00
|
|
|
assert(maxMessageLen != null),
|
|
|
|
assert(allowedFilesType != null),
|
|
|
|
assert(filesMaxSize != null),
|
|
|
|
assert(writingEventInterval != null),
|
2021-03-12 18:36:42 +00:00
|
|
|
assert(writingEventLifetime != null),
|
|
|
|
assert(maxMessageImageWidth != null),
|
|
|
|
assert(maxMessageImageHeight != null),
|
|
|
|
assert(maxThumbnailWidth != null),
|
2021-03-13 10:33:25 +00:00
|
|
|
assert(maxThumbnailHeight != null),
|
|
|
|
assert(maxLogoWidth != null),
|
|
|
|
assert(maxLogoHeight != null);
|
2021-03-12 15:19:07 +00:00
|
|
|
}
|
|
|
|
|
2021-04-16 06:14:19 +00:00
|
|
|
class AccountInformationPolicy {
|
|
|
|
final int minFirstNameLength;
|
|
|
|
final int maxFirstNameLength;
|
|
|
|
final int minLastNameLength;
|
|
|
|
final int maxLastNameLength;
|
2021-04-17 06:30:00 +00:00
|
|
|
final int maxLocationLength;
|
2021-04-16 06:14:19 +00:00
|
|
|
|
|
|
|
const AccountInformationPolicy({
|
2022-03-10 18:39:57 +00:00
|
|
|
required this.minFirstNameLength,
|
|
|
|
required this.maxFirstNameLength,
|
|
|
|
required this.minLastNameLength,
|
|
|
|
required this.maxLastNameLength,
|
|
|
|
required this.maxLocationLength,
|
2021-04-16 06:14:19 +00:00
|
|
|
}) : assert(minFirstNameLength != null),
|
|
|
|
assert(maxFirstNameLength != null),
|
|
|
|
assert(minLastNameLength != null),
|
2021-04-17 06:30:00 +00:00
|
|
|
assert(maxLastNameLength != null),
|
|
|
|
assert(maxLocationLength != null);
|
2021-04-16 06:14:19 +00:00
|
|
|
}
|
|
|
|
|
2021-12-30 11:02:18 +00:00
|
|
|
enum BannerNature { Information, Warning, Success }
|
|
|
|
|
|
|
|
extension BannerNatureExt on BannerNature {
|
2022-03-10 18:39:57 +00:00
|
|
|
static BannerNature fromStr(String? s) {
|
2021-12-30 11:02:18 +00:00
|
|
|
switch (s) {
|
|
|
|
case "information":
|
|
|
|
return BannerNature.Information;
|
|
|
|
case "success":
|
|
|
|
return BannerNature.Success;
|
|
|
|
case "warning":
|
|
|
|
default:
|
|
|
|
return BannerNature.Warning;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Banner {
|
|
|
|
final bool enabled;
|
2022-03-10 18:39:57 +00:00
|
|
|
final int? expire;
|
2021-12-30 11:02:18 +00:00
|
|
|
final BannerNature nature;
|
|
|
|
final Map<String, String> message;
|
2022-03-10 18:39:57 +00:00
|
|
|
final String? link;
|
2021-12-30 11:02:18 +00:00
|
|
|
|
|
|
|
const Banner({
|
2022-03-10 18:39:57 +00:00
|
|
|
required this.enabled,
|
|
|
|
required this.expire,
|
|
|
|
required this.nature,
|
|
|
|
required this.message,
|
|
|
|
required this.link,
|
2021-12-30 11:02:18 +00:00
|
|
|
}) : assert(enabled != null),
|
|
|
|
assert(nature != null),
|
|
|
|
assert(message != null);
|
|
|
|
|
2022-03-10 18:39:57 +00:00
|
|
|
bool get visible => enabled && (expire == null || expire! > time());
|
2021-12-30 11:02:18 +00:00
|
|
|
}
|
|
|
|
|
2021-02-16 18:30:06 +00:00
|
|
|
class ServerConfig {
|
2021-02-20 08:24:51 +00:00
|
|
|
final Version minSupportedMobileVersion;
|
2021-02-20 08:35:03 +00:00
|
|
|
final String termsURL;
|
2021-04-17 07:09:03 +00:00
|
|
|
final String privacyPolicyURL;
|
2021-04-30 16:50:46 +00:00
|
|
|
final String contactEmail;
|
2021-02-20 08:59:21 +00:00
|
|
|
final String playStoreURL;
|
|
|
|
final String androidDirectDownloadURL;
|
2022-03-10 18:39:57 +00:00
|
|
|
final Banner? banner;
|
2021-04-12 17:26:05 +00:00
|
|
|
final NotificationsPolicy notificationsPolicy;
|
2021-02-18 17:20:50 +00:00
|
|
|
final PasswordPolicy passwordPolicy;
|
2021-02-16 18:30:06 +00:00
|
|
|
final ServerDataConservationPolicy dataConservationPolicy;
|
2021-03-12 15:19:07 +00:00
|
|
|
final ConversationsPolicy conversationsPolicy;
|
2021-04-16 06:14:19 +00:00
|
|
|
final AccountInformationPolicy accountInformationPolicy;
|
2021-02-16 18:30:06 +00:00
|
|
|
|
|
|
|
const ServerConfig({
|
2022-03-10 18:39:57 +00:00
|
|
|
required this.minSupportedMobileVersion,
|
|
|
|
required this.termsURL,
|
|
|
|
required this.privacyPolicyURL,
|
|
|
|
required this.contactEmail,
|
|
|
|
required this.playStoreURL,
|
|
|
|
required this.androidDirectDownloadURL,
|
|
|
|
required this.banner,
|
|
|
|
required this.notificationsPolicy,
|
|
|
|
required this.passwordPolicy,
|
|
|
|
required this.dataConservationPolicy,
|
|
|
|
required this.conversationsPolicy,
|
|
|
|
required this.accountInformationPolicy,
|
2021-02-20 08:24:51 +00:00
|
|
|
}) : assert(minSupportedMobileVersion != null),
|
2021-02-20 08:35:03 +00:00
|
|
|
assert(termsURL != null),
|
2021-04-17 07:09:03 +00:00
|
|
|
assert(privacyPolicyURL != null),
|
2021-04-30 16:50:46 +00:00
|
|
|
assert(contactEmail != null),
|
2021-02-20 08:59:21 +00:00
|
|
|
assert(playStoreURL != null),
|
|
|
|
assert(androidDirectDownloadURL != null),
|
2021-04-12 17:26:05 +00:00
|
|
|
assert(notificationsPolicy != null),
|
2021-02-20 08:24:51 +00:00
|
|
|
assert(passwordPolicy != null),
|
2021-03-12 15:19:07 +00:00
|
|
|
assert(dataConservationPolicy != null),
|
2021-04-16 06:14:19 +00:00
|
|
|
assert(conversationsPolicy != null),
|
|
|
|
assert(accountInformationPolicy != null);
|
2021-02-16 18:30:06 +00:00
|
|
|
}
|