kopia lustrzana https://gitlab.com/mysocialportal/relatica
Add ability for version check to have max bounds as well.
rodzic
4ee0756bb8
commit
3ca4a76792
|
@ -0,0 +1,32 @@
|
|||
import 'friendica_version.dart';
|
||||
|
||||
final FriendicaVersionRequirement unknownRequirement =
|
||||
FriendicaVersionRequirement(unknown);
|
||||
|
||||
class FriendicaVersionRequirement {
|
||||
final FriendicaVersion minimumVersion;
|
||||
final FriendicaVersion? maxVersion;
|
||||
|
||||
const FriendicaVersionRequirement(this.minimumVersion, {this.maxVersion});
|
||||
|
||||
bool versionMeetsRequirement(FriendicaVersion version) {
|
||||
if (version < minimumVersion) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (maxVersion == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return version <= maxVersion!;
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
if (maxVersion == null) {
|
||||
return 'requires at least Friendica $minimumVersion';
|
||||
}
|
||||
|
||||
return 'works only on Friendica $minimumVersion to $maxVersion';
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ import 'package:result_monad/result_monad.dart';
|
|||
import '../globals.dart';
|
||||
import '../models/exec_error.dart';
|
||||
import '../models/friendica_version.dart';
|
||||
import '../models/friendica_version_requirement.dart';
|
||||
|
||||
enum RelaticaFeatures {
|
||||
diasporaReshare('Resharing Diaspora Posts'),
|
||||
|
@ -29,8 +30,8 @@ class FriendicaVersionChecker {
|
|||
const FriendicaVersionChecker();
|
||||
|
||||
bool canUseFeature(RelaticaFeatures feature) {
|
||||
final neededVersion = featureVersionRequirement[feature];
|
||||
if (neededVersion == null) {
|
||||
final requirement = featureVersionRequirement[feature];
|
||||
if (requirement == null) {
|
||||
_logger.severe(
|
||||
'Return false since no minimum version data in table for: $feature',
|
||||
);
|
||||
|
@ -39,7 +40,9 @@ class FriendicaVersionChecker {
|
|||
|
||||
return getIt<ActiveProfileSelector<InstanceInfo>>()
|
||||
.activeEntry
|
||||
.andThenSuccess((info) => info.friendicaVersion >= neededVersion)
|
||||
.andThenSuccess(
|
||||
(info) => requirement.versionMeetsRequirement(info.friendicaVersion),
|
||||
)
|
||||
.fold(
|
||||
onSuccess: (versionMet) => versionMet,
|
||||
onError: (error) {
|
||||
|
@ -61,17 +64,20 @@ class FriendicaVersionChecker {
|
|||
);
|
||||
}
|
||||
|
||||
FriendicaVersion getVersionRequirement(RelaticaFeatures feature) =>
|
||||
featureVersionRequirement[feature] ?? unknown;
|
||||
FriendicaVersionRequirement getVersionRequirement(RelaticaFeatures feature) =>
|
||||
featureVersionRequirement[feature] ?? unknownRequirement;
|
||||
|
||||
String versionErrorString(RelaticaFeatures feature) =>
|
||||
"${feature.label} requires at least Friendica ${getVersionRequirement(feature).toVersionString()}";
|
||||
"${feature.label} ${getVersionRequirement(feature)}";
|
||||
|
||||
static final featureVersionRequirement = <RelaticaFeatures, FriendicaVersion>{
|
||||
RelaticaFeatures.diasporaReshare: v2023_04,
|
||||
RelaticaFeatures.directMessageCreation: v2023_04,
|
||||
RelaticaFeatures.postSpoilerText: v2023_04,
|
||||
RelaticaFeatures.statusEditing: v2023_04,
|
||||
RelaticaFeatures.usingActualFollowRequests: v2023_04,
|
||||
static final featureVersionRequirement =
|
||||
<RelaticaFeatures, FriendicaVersionRequirement>{
|
||||
RelaticaFeatures.diasporaReshare: FriendicaVersionRequirement(v2023_04),
|
||||
RelaticaFeatures.directMessageCreation:
|
||||
FriendicaVersionRequirement(v2023_04),
|
||||
RelaticaFeatures.postSpoilerText: FriendicaVersionRequirement(v2023_04),
|
||||
RelaticaFeatures.statusEditing: FriendicaVersionRequirement(v2023_04),
|
||||
RelaticaFeatures.usingActualFollowRequests:
|
||||
FriendicaVersionRequirement(v2023_04),
|
||||
};
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue