From c94e60d49b05a1f8f36a3e224079506bb623471d Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 14 May 2023 13:55:28 -0400 Subject: [PATCH] Enable editing on Pleroma 2.5+ --- .../InstanceFeatures/InstanceFeatures.swift | 18 +++++++++++++----- .../Sources/InstanceFeatures/Version.swift | 16 ++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/Packages/InstanceFeatures/Sources/InstanceFeatures/InstanceFeatures.swift b/Packages/InstanceFeatures/Sources/InstanceFeatures/InstanceFeatures.swift index 8eea65ba..e3c7aef4 100644 --- a/Packages/InstanceFeatures/Sources/InstanceFeatures/InstanceFeatures.swift +++ b/Packages/InstanceFeatures/Sources/InstanceFeatures/InstanceFeatures.swift @@ -88,7 +88,7 @@ public class InstanceFeatures: ObservableObject { } public var needsWideColorGamutHack: Bool { - if case .mastodon(_, .some(let version)) = instanceType { + if case .mastodon(_, let version) = instanceType { return version < Version(4, 0, 0) } else { return true @@ -116,8 +116,16 @@ public class InstanceFeatures: ObservableObject { } public var editStatuses: Bool { - // todo: does this require a particular akkoma version? - hasMastodonVersion(3, 5, 0) || instanceType.isPleroma(.akkoma(nil)) + switch instanceType { + case .mastodon(_, let v) where v >= Version(3, 5, 0): + return true + case .pleroma(.vanilla(let v)) where v >= Version(2, 5, 0): + return true + case .pleroma(.akkoma(nil)): + return true + default: + return false + } } public var needsEditAttachmentsInSeparateRequest: Bool { @@ -188,7 +196,7 @@ public class InstanceFeatures: ObservableObject { } public func hasMastodonVersion(_ major: Int, _ minor: Int, _ patch: Int) -> Bool { - if case .mastodon(_, .some(let version)) = instanceType { + if case .mastodon(_, let version) = instanceType { return version >= Version(major, minor, patch) } else { return false @@ -197,7 +205,7 @@ public class InstanceFeatures: ObservableObject { func hasPleromaVersion(_ major: Int, _ minor: Int, _ patch: Int) -> Bool { switch instanceType { - case .pleroma(.vanilla(.some(let version))), .pleroma(.akkoma(.some(let version))): + case .pleroma(.vanilla(let version)), .pleroma(.akkoma(let version)): return version >= Version(major, minor, patch) default: return false diff --git a/Packages/InstanceFeatures/Sources/InstanceFeatures/Version.swift b/Packages/InstanceFeatures/Sources/InstanceFeatures/Version.swift index b5056008..3ce16236 100644 --- a/Packages/InstanceFeatures/Sources/InstanceFeatures/Version.swift +++ b/Packages/InstanceFeatures/Sources/InstanceFeatures/Version.swift @@ -62,3 +62,19 @@ import Foundation } } } + +func <(lhs: Version?, rhs: Version) -> Bool { + guard let lhs else { + // nil is less than or equal to everything + return true + } + return lhs < rhs +} + +func >=(lhs: Version?, rhs: Version) -> Bool { + guard let lhs else { + // nil is less than or equal to everything + return false + } + return lhs >= rhs +}