From 297af7b9053fc3c462e3c4ac101c008e1521e8ae Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 24 Jul 2023 22:42:17 -0700 Subject: [PATCH] Tweak instance type matching, add iceshrimp --- .../InstanceFeatures/InstanceFeatures.swift | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/Packages/InstanceFeatures/Sources/InstanceFeatures/InstanceFeatures.swift b/Packages/InstanceFeatures/Sources/InstanceFeatures/InstanceFeatures.swift index c86e0266..ab2bc49b 100644 --- a/Packages/InstanceFeatures/Sources/InstanceFeatures/InstanceFeatures.swift +++ b/Packages/InstanceFeatures/Sources/InstanceFeatures/InstanceFeatures.swift @@ -11,8 +11,7 @@ import Combine import Pachyderm public class InstanceFeatures: ObservableObject { - private static let pleromaVersionRegex = try! NSRegularExpression(pattern: "\\(compatible; pleroma (.*)\\)", options: .caseInsensitive) - private static let akkomaVersionRegex = try! NSRegularExpression(pattern: "\\(compatible; akkoma (.*)\\)", options: .caseInsensitive) + private static let pleromaVersionRegex = try! NSRegularExpression(pattern: "\\(compatible; (pleroma|akkoma) (.*)\\)", options: .caseInsensitive) private let _featuresUpdated = PassthroughSubject() public var featuresUpdated: some Publisher { _featuresUpdated } @@ -179,23 +178,20 @@ public class InstanceFeatures: ObservableObject { mastoVersion = Version(string: ver) } instanceType = .mastodon(.hometown(hometownVersion), mastoVersion) - } else if ver.contains("pleroma") { + } else if let match = InstanceFeatures.pleromaVersionRegex.firstMatch(in: ver, range: NSRange(location: 0, length: ver.utf16.count)) { var pleromaVersion: Version? - 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))) + let type = (ver as NSString).substring(with: match.range(at: 1)) + pleromaVersion = Version(string: (ver as NSString).substring(with: match.range(at: 2))) + if type == "akkoma" { + instanceType = .pleroma(.akkoma(pleromaVersion)) + } else { + instanceType = .pleroma(.vanilla(pleromaVersion)) } - instanceType = .pleroma(.vanilla(pleromaVersion)) - } else if ver.contains("akkoma") { - var akkomaVersion: Version? - if let match = InstanceFeatures.akkomaVersionRegex.firstMatch(in: ver, range: NSRange(location: 0, length: ver.utf16.count)) { - akkomaVersion = Version(string: (ver as NSString).substring(with: match.range(at: 1))) - } - instanceType = .pleroma(.akkoma(akkomaVersion)) } else if ver.contains("pixelfed") { instanceType = .pixelfed } else if nodeInfo?.software.name == "gotosocial" { instanceType = .gotosocial - } else if ver.contains("firefish") || ver.contains("calckey") { + } else if ver.contains("firefish") || ver.contains("iceshrimp") || ver.contains("calckey") { instanceType = .firefish(nodeInfo?.software.version) } else { instanceType = .mastodon(.vanilla, Version(string: ver))