Fix Hometown versions not being parsed correctly

This commit is contained in:
Shadowfacts 2022-11-13 17:05:08 -05:00
parent 1a767ff910
commit 77dece36d0
1 changed files with 13 additions and 5 deletions

View File

@ -15,6 +15,7 @@ struct InstanceFeatures {
private(set) var instanceType = InstanceType.mastodon private(set) var instanceType = InstanceType.mastodon
private(set) var version: Version? private(set) var version: Version?
private(set) var pleromaVersion: Version? private(set) var pleromaVersion: Version?
private(set) var hometownVersion: Version?
private(set) var maxStatusChars = 500 private(set) var maxStatusChars = 500
var localOnlyPosts: Bool { var localOnlyPosts: Bool {
@ -55,24 +56,31 @@ struct InstanceFeatures {
} }
mutating func update(instance: Instance, nodeInfo: NodeInfo?) { mutating func update(instance: Instance, nodeInfo: NodeInfo?) {
var version: Version?
let ver = instance.version.lowercased() let ver = instance.version.lowercased()
if ver.contains("glitch") { if ver.contains("glitch") {
instanceType = .glitch instanceType = .glitch
} else if nodeInfo?.software.name == "hometown" { } else if nodeInfo?.software.name == "hometown" {
instanceType = .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") { } else if ver.contains("pleroma") {
instanceType = .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") { } else if ver.contains("pixelfed") {
instanceType = .pixelfed instanceType = .pixelfed
} else { } else {
instanceType = .mastodon instanceType = .mastodon
} }
version = Version(string: ver) self.version = 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 maxStatusChars = instance.maxStatusCharacters ?? 500
} }