mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 21:09:21 +00:00
211 lines
6.6 KiB
Dart
211 lines
6.6 KiB
Dart
import 'package:comunic/utils/date_utils.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:version/version.dart';
|
|
|
|
/// Server static configuration
|
|
///
|
|
/// @author Pierre Hubert
|
|
|
|
class NotificationsPolicy {
|
|
final bool hasFirebase;
|
|
final bool hasIndependent;
|
|
|
|
const NotificationsPolicy({
|
|
@required this.hasFirebase,
|
|
@required this.hasIndependent,
|
|
}) : assert(hasFirebase != null),
|
|
assert(hasIndependent != null);
|
|
}
|
|
|
|
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({
|
|
@required this.allowMailInPassword,
|
|
@required this.allowNameInPassword,
|
|
@required this.minPasswordLength,
|
|
@required this.minNumberUpperCaseLetters,
|
|
@required this.minNumberLowerCaseLetters,
|
|
@required this.minNumberDigits,
|
|
@required this.minNumberSpecialCharacters,
|
|
@required this.minCategoriesPresence,
|
|
}) : assert(allowMailInPassword != null),
|
|
assert(allowNameInPassword != null),
|
|
assert(minPasswordLength != null),
|
|
assert(minNumberUpperCaseLetters != null),
|
|
assert(minNumberLowerCaseLetters != null),
|
|
assert(minNumberDigits != null),
|
|
assert(minNumberSpecialCharacters != null),
|
|
assert(minCategoriesPresence != null);
|
|
}
|
|
|
|
class ServerDataConservationPolicy {
|
|
final int minInactiveAccountLifetime;
|
|
final int minNotificationLifetime;
|
|
final int minCommentsLifetime;
|
|
final int minPostsLifetime;
|
|
final int minConversationMessagesLifetime;
|
|
final int minLikesLifetime;
|
|
|
|
const ServerDataConservationPolicy({
|
|
@required this.minInactiveAccountLifetime,
|
|
@required this.minNotificationLifetime,
|
|
@required this.minCommentsLifetime,
|
|
@required this.minPostsLifetime,
|
|
@required this.minConversationMessagesLifetime,
|
|
@required this.minLikesLifetime,
|
|
}) : assert(minInactiveAccountLifetime != null),
|
|
assert(minNotificationLifetime != null),
|
|
assert(minCommentsLifetime != null),
|
|
assert(minPostsLifetime != null),
|
|
assert(minConversationMessagesLifetime != null),
|
|
assert(minLikesLifetime != null);
|
|
}
|
|
|
|
class ConversationsPolicy {
|
|
final int maxConversationNameLen;
|
|
final int minMessageLen;
|
|
final int maxMessageLen;
|
|
final List<String> allowedFilesType;
|
|
final int filesMaxSize;
|
|
final int writingEventInterval;
|
|
final int writingEventLifetime;
|
|
final int maxMessageImageWidth;
|
|
final int maxMessageImageHeight;
|
|
final int maxThumbnailWidth;
|
|
final int maxThumbnailHeight;
|
|
final int maxLogoWidth;
|
|
final int maxLogoHeight;
|
|
|
|
const ConversationsPolicy({
|
|
@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,
|
|
}) : assert(maxConversationNameLen != null),
|
|
assert(minMessageLen != null),
|
|
assert(maxMessageLen != null),
|
|
assert(allowedFilesType != null),
|
|
assert(filesMaxSize != null),
|
|
assert(writingEventInterval != null),
|
|
assert(writingEventLifetime != null),
|
|
assert(maxMessageImageWidth != null),
|
|
assert(maxMessageImageHeight != null),
|
|
assert(maxThumbnailWidth != null),
|
|
assert(maxThumbnailHeight != null),
|
|
assert(maxLogoWidth != null),
|
|
assert(maxLogoHeight != null);
|
|
}
|
|
|
|
class AccountInformationPolicy {
|
|
final int minFirstNameLength;
|
|
final int maxFirstNameLength;
|
|
final int minLastNameLength;
|
|
final int maxLastNameLength;
|
|
final int maxLocationLength;
|
|
|
|
const AccountInformationPolicy({
|
|
@required this.minFirstNameLength,
|
|
@required this.maxFirstNameLength,
|
|
@required this.minLastNameLength,
|
|
@required this.maxLastNameLength,
|
|
@required this.maxLocationLength,
|
|
}) : assert(minFirstNameLength != null),
|
|
assert(maxFirstNameLength != null),
|
|
assert(minLastNameLength != null),
|
|
assert(maxLastNameLength != null),
|
|
assert(maxLocationLength != null);
|
|
}
|
|
|
|
enum BannerNature { Information, Warning, Success }
|
|
|
|
extension BannerNatureExt on BannerNature {
|
|
static BannerNature fromStr(String s) {
|
|
switch (s) {
|
|
case "information":
|
|
return BannerNature.Information;
|
|
case "success":
|
|
return BannerNature.Success;
|
|
case "warning":
|
|
default:
|
|
return BannerNature.Warning;
|
|
}
|
|
}
|
|
}
|
|
|
|
class Banner {
|
|
final bool enabled;
|
|
final int expire;
|
|
final BannerNature nature;
|
|
final Map<String, String> message;
|
|
final String link;
|
|
|
|
const Banner({
|
|
@required this.enabled,
|
|
@required this.expire,
|
|
@required this.nature,
|
|
@required this.message,
|
|
@required this.link,
|
|
}) : assert(enabled != null),
|
|
assert(nature != null),
|
|
assert(message != null);
|
|
|
|
bool get visible => enabled && (expire == null || expire > time());
|
|
}
|
|
|
|
class ServerConfig {
|
|
final Version minSupportedMobileVersion;
|
|
final String termsURL;
|
|
final String privacyPolicyURL;
|
|
final String contactEmail;
|
|
final String playStoreURL;
|
|
final String androidDirectDownloadURL;
|
|
final Banner banner;
|
|
final NotificationsPolicy notificationsPolicy;
|
|
final PasswordPolicy passwordPolicy;
|
|
final ServerDataConservationPolicy dataConservationPolicy;
|
|
final ConversationsPolicy conversationsPolicy;
|
|
final AccountInformationPolicy accountInformationPolicy;
|
|
|
|
const ServerConfig({
|
|
@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,
|
|
}) : assert(minSupportedMobileVersion != null),
|
|
assert(termsURL != null),
|
|
assert(privacyPolicyURL != null),
|
|
assert(contactEmail != null),
|
|
assert(playStoreURL != null),
|
|
assert(androidDirectDownloadURL != null),
|
|
assert(notificationsPolicy != null),
|
|
assert(passwordPolicy != null),
|
|
assert(dataConservationPolicy != null),
|
|
assert(conversationsPolicy != null),
|
|
assert(accountInformationPolicy != null);
|
|
}
|