Compare commits
No commits in common. "c94e60d49b05a1f8f36a3e224079506bb623471d" and "b37e5fffbfcaff51c3c90b7567845ed259cfe105" have entirely different histories.
c94e60d49b
...
b37e5fffbf
|
@ -88,7 +88,7 @@ public class InstanceFeatures: ObservableObject {
|
|||
}
|
||||
|
||||
public var needsWideColorGamutHack: Bool {
|
||||
if case .mastodon(_, let version) = instanceType {
|
||||
if case .mastodon(_, .some(let version)) = instanceType {
|
||||
return version < Version(4, 0, 0)
|
||||
} else {
|
||||
return true
|
||||
|
@ -116,16 +116,8 @@ public class InstanceFeatures: ObservableObject {
|
|||
}
|
||||
|
||||
public var editStatuses: Bool {
|
||||
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
|
||||
}
|
||||
// todo: does this require a particular akkoma version?
|
||||
hasMastodonVersion(3, 5, 0) || instanceType.isPleroma(.akkoma(nil))
|
||||
}
|
||||
|
||||
public var needsEditAttachmentsInSeparateRequest: Bool {
|
||||
|
@ -196,7 +188,7 @@ public class InstanceFeatures: ObservableObject {
|
|||
}
|
||||
|
||||
public func hasMastodonVersion(_ major: Int, _ minor: Int, _ patch: Int) -> Bool {
|
||||
if case .mastodon(_, let version) = instanceType {
|
||||
if case .mastodon(_, .some(let version)) = instanceType {
|
||||
return version >= Version(major, minor, patch)
|
||||
} else {
|
||||
return false
|
||||
|
@ -205,7 +197,7 @@ public class InstanceFeatures: ObservableObject {
|
|||
|
||||
func hasPleromaVersion(_ major: Int, _ minor: Int, _ patch: Int) -> Bool {
|
||||
switch instanceType {
|
||||
case .pleroma(.vanilla(let version)), .pleroma(.akkoma(let version)):
|
||||
case .pleroma(.vanilla(.some(let version))), .pleroma(.akkoma(.some(let version))):
|
||||
return version >= Version(major, minor, patch)
|
||||
default:
|
||||
return false
|
||||
|
@ -291,3 +283,61 @@ extension InstanceFeatures {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension InstanceFeatures {
|
||||
@_spi(InstanceType) public struct Version: Equatable, Comparable, CustomStringConvertible {
|
||||
private static let regex = try! NSRegularExpression(pattern: "^(\\d+)\\.(\\d+)\\.(\\d+).*$")
|
||||
|
||||
let major: Int
|
||||
let minor: Int
|
||||
let patch: Int
|
||||
|
||||
init(_ major: Int, _ minor: Int, _ patch: Int) {
|
||||
self.major = major
|
||||
self.minor = minor
|
||||
self.patch = patch
|
||||
}
|
||||
|
||||
init?(string: String) {
|
||||
guard let match = Version.regex.firstMatch(in: string, range: NSRange(location: 0, length: string.utf16.count)),
|
||||
match.numberOfRanges == 4 else {
|
||||
return nil
|
||||
}
|
||||
let majorStr = (string as NSString).substring(with: match.range(at: 1))
|
||||
let minorStr = (string as NSString).substring(with: match.range(at: 2))
|
||||
let patchStr = (string as NSString).substring(with: match.range(at: 3))
|
||||
guard let major = Int(majorStr),
|
||||
let minor = Int(minorStr),
|
||||
let patch = Int(patchStr) else {
|
||||
return nil
|
||||
}
|
||||
self.major = major
|
||||
self.minor = minor
|
||||
self.patch = patch
|
||||
}
|
||||
|
||||
public var description: String {
|
||||
"\(major).\(minor).\(patch)"
|
||||
}
|
||||
|
||||
public static func ==(lhs: Version, rhs: Version) -> Bool {
|
||||
return lhs.major == rhs.major && lhs.minor == rhs.minor && lhs.patch == rhs.patch
|
||||
}
|
||||
|
||||
public static func < (lhs: InstanceFeatures.Version, rhs: InstanceFeatures.Version) -> Bool {
|
||||
if lhs.major < rhs.major {
|
||||
return true
|
||||
} else if lhs.major > rhs.major {
|
||||
return false
|
||||
} else if lhs.minor < rhs.minor {
|
||||
return true
|
||||
} else if lhs.minor > rhs.minor {
|
||||
return false
|
||||
} else if lhs.patch < rhs.patch {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,80 +0,0 @@
|
|||
//
|
||||
// Version.swift
|
||||
// InstanceFeatures
|
||||
//
|
||||
// Created by Shadowfacts on 5/14/23.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
@_spi(InstanceType) public struct Version: Equatable, Comparable, CustomStringConvertible {
|
||||
private static let regex = try! NSRegularExpression(pattern: "^(\\d+)\\.(\\d+)\\.(\\d+).*$")
|
||||
|
||||
let major: Int
|
||||
let minor: Int
|
||||
let patch: Int
|
||||
|
||||
init(_ major: Int, _ minor: Int, _ patch: Int) {
|
||||
self.major = major
|
||||
self.minor = minor
|
||||
self.patch = patch
|
||||
}
|
||||
|
||||
init?(string: String) {
|
||||
guard let match = Version.regex.firstMatch(in: string, range: NSRange(location: 0, length: string.utf16.count)),
|
||||
match.numberOfRanges == 4 else {
|
||||
return nil
|
||||
}
|
||||
let majorStr = (string as NSString).substring(with: match.range(at: 1))
|
||||
let minorStr = (string as NSString).substring(with: match.range(at: 2))
|
||||
let patchStr = (string as NSString).substring(with: match.range(at: 3))
|
||||
guard let major = Int(majorStr),
|
||||
let minor = Int(minorStr),
|
||||
let patch = Int(patchStr) else {
|
||||
return nil
|
||||
}
|
||||
self.major = major
|
||||
self.minor = minor
|
||||
self.patch = patch
|
||||
}
|
||||
|
||||
public var description: String {
|
||||
"\(major).\(minor).\(patch)"
|
||||
}
|
||||
|
||||
public static func ==(lhs: Version, rhs: Version) -> Bool {
|
||||
return lhs.major == rhs.major && lhs.minor == rhs.minor && lhs.patch == rhs.patch
|
||||
}
|
||||
|
||||
public static func <(lhs: Version, rhs: Version) -> Bool {
|
||||
if lhs.major < rhs.major {
|
||||
return true
|
||||
} else if lhs.major > rhs.major {
|
||||
return false
|
||||
} else if lhs.minor < rhs.minor {
|
||||
return true
|
||||
} else if lhs.minor > rhs.minor {
|
||||
return false
|
||||
} else if lhs.patch < rhs.patch {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
Loading…
Reference in New Issue