diff --git a/Tusker/InstanceFeatures.swift b/Tusker/InstanceFeatures.swift index 809d3b5868..99d279a143 100644 --- a/Tusker/InstanceFeatures.swift +++ b/Tusker/InstanceFeatures.swift @@ -10,8 +10,11 @@ import Foundation import Pachyderm struct InstanceFeatures { + private static let pleromaVersionRegex = try! NSRegularExpression(pattern: "\\(compatible; Pleroma (.*)\\)") + private(set) var instanceType = InstanceType.mastodon private(set) var version: Version? + private(set) var pleromaVersion: Version? private(set) var maxStatusChars = 500 var localOnlyPosts: Bool { @@ -43,7 +46,8 @@ struct InstanceFeatures { } var reblogVisibility: Bool { - instanceType == .mastodon && hasVersion(2, 8, 0) + (instanceType == .mastodon && hasVersion(2, 8, 0)) + || (instanceType == .pleroma && hasVersion(2, 0, 0)) } mutating func update(instance: Instance, nodeInfo: NodeInfo?) { @@ -62,6 +66,10 @@ struct InstanceFeatures { version = Version(string: ver) + if let match = InstanceFeatures.pleromaVersionRegex.firstMatch(in: ver, range: NSRange(location: 0, length: ver.utf16.count)) { + pleromaVersion = Version(string: (ver as NSString).substring(with: match.range(at: 1))) + } + maxStatusChars = instance.maxStatusCharacters ?? 500 } @@ -95,6 +103,8 @@ extension InstanceFeatures { extension InstanceFeatures { struct Version: Equatable, Comparable { + private static let regex = try! NSRegularExpression(pattern: "^(\\d+)\\.(\\d+)\\.(\\d+).*$") + let major: Int let minor: Int let patch: Int @@ -106,8 +116,7 @@ extension InstanceFeatures { } init?(string: String) { - let regex = try! NSRegularExpression(pattern: "^(\\d+)\\.(\\d+)\\.(\\d+).*$") - guard let match = regex.firstMatch(in: string, range: NSRange(location: 0, length: string.utf16.count)), + guard let match = Version.regex.firstMatch(in: string, range: NSRange(location: 0, length: string.utf16.count)), match.numberOfRanges == 4 else { return nil }