From 77dece36d0d57612a383ca35e4d2e350b68ac445 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 13 Nov 2022 17:05:08 -0500 Subject: [PATCH] Fix Hometown versions not being parsed correctly --- Tusker/API/InstanceFeatures.swift | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Tusker/API/InstanceFeatures.swift b/Tusker/API/InstanceFeatures.swift index 95de3ee8f1..debff76aac 100644 --- a/Tusker/API/InstanceFeatures.swift +++ b/Tusker/API/InstanceFeatures.swift @@ -15,6 +15,7 @@ struct InstanceFeatures { private(set) var instanceType = InstanceType.mastodon private(set) var version: Version? private(set) var pleromaVersion: Version? + private(set) var hometownVersion: Version? private(set) var maxStatusChars = 500 var localOnlyPosts: Bool { @@ -55,24 +56,31 @@ struct InstanceFeatures { } mutating func update(instance: Instance, nodeInfo: NodeInfo?) { + var version: Version? + let ver = instance.version.lowercased() if ver.contains("glitch") { instanceType = .glitch } else if nodeInfo?.software.name == "hometown" { instanceType = .hometown + // like "1.0.6+3.5.2" + let parts = ver.split(separator: "+") + if parts.count == 2 { + version = Version(string: String(parts[1])) + hometownVersion = Version(string: String(parts[0])) + } } else if ver.contains("pleroma") { instanceType = .pleroma + 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))) + } } else if ver.contains("pixelfed") { instanceType = .pixelfed } else { instanceType = .mastodon } - 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))) - } + self.version = version ?? Version(string: ver) maxStatusChars = instance.maxStatusCharacters ?? 500 }