parent
22fe1e8ab1
commit
691f1c267a
|
@ -13,6 +13,7 @@ import Pachyderm
|
||||||
public class InstanceFeatures: ObservableObject {
|
public class InstanceFeatures: ObservableObject {
|
||||||
private static let pleromaVersionRegex = try! NSRegularExpression(pattern: "\\(compatible; pleroma (.*)\\)", options: .caseInsensitive)
|
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 akkomaVersionRegex = try! NSRegularExpression(pattern: "\\(compatible; akkoma (.*)\\)", options: .caseInsensitive)
|
||||||
|
private static let calckeyVersionRegex = try! NSRegularExpression(pattern: "(.*) compatible \\((.*) calckey\\)", options: .caseInsensitive)
|
||||||
|
|
||||||
private let _featuresUpdated = PassthroughSubject<Void, Never>()
|
private let _featuresUpdated = PassthroughSubject<Void, Never>()
|
||||||
public var featuresUpdated: some Publisher<Void, Never> { _featuresUpdated }
|
public var featuresUpdated: some Publisher<Void, Never> { _featuresUpdated }
|
||||||
|
@ -153,6 +154,12 @@ public class InstanceFeatures: ObservableObject {
|
||||||
instanceType = .pleroma(.akkoma(akkomaVersion))
|
instanceType = .pleroma(.akkoma(akkomaVersion))
|
||||||
} else if ver.contains("pixelfed") {
|
} else if ver.contains("pixelfed") {
|
||||||
instanceType = .pixelfed
|
instanceType = .pixelfed
|
||||||
|
} else if ver.contains("calckey") {
|
||||||
|
var calckeyMastoVersion: Version?
|
||||||
|
if let match = InstanceFeatures.calckeyVersionRegex.firstMatch(in: ver, range: NSRange(location: 0, length: ver.utf16.count)) {
|
||||||
|
calckeyMastoVersion = Version(string: (ver as NSString).substring(with: match.range(at: 1)))
|
||||||
|
}
|
||||||
|
instanceType = .calckey(mastodonCompatible: calckeyMastoVersion)
|
||||||
} else {
|
} else {
|
||||||
instanceType = .mastodon(.vanilla, Version(string: ver))
|
instanceType = .mastodon(.vanilla, Version(string: ver))
|
||||||
}
|
}
|
||||||
|
@ -190,6 +197,7 @@ extension InstanceFeatures {
|
||||||
case mastodon(MastodonType, Version?)
|
case mastodon(MastodonType, Version?)
|
||||||
case pleroma(PleromaType)
|
case pleroma(PleromaType)
|
||||||
case pixelfed
|
case pixelfed
|
||||||
|
case calckey(mastodonCompatible: Version?)
|
||||||
|
|
||||||
var isMastodon: Bool {
|
var isMastodon: Bool {
|
||||||
if case .mastodon(_, _) = self {
|
if case .mastodon(_, _) = self {
|
||||||
|
|
|
@ -20,6 +20,20 @@ public struct Poll: Codable, Sendable {
|
||||||
public let options: [Option]
|
public let options: [Option]
|
||||||
public let emojis: [Emoji]
|
public let emojis: [Emoji]
|
||||||
|
|
||||||
|
public init(from decoder: Decoder) throws {
|
||||||
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
|
self.id = try container.decode(String.self, forKey: .id)
|
||||||
|
self.expiresAt = try container.decodeIfPresent(Date.self, forKey: .expiresAt)
|
||||||
|
self.expired = try container.decode(Bool.self, forKey: .expired)
|
||||||
|
self.multiple = try container.decode(Bool.self, forKey: .multiple)
|
||||||
|
self.votesCount = try container.decode(Int.self, forKey: .votesCount)
|
||||||
|
self.votersCount = try container.decodeIfPresent(Int.self, forKey: .votersCount)
|
||||||
|
self.voted = try container.decodeIfPresent(Bool.self, forKey: .voted)
|
||||||
|
self.ownVotes = try container.decodeIfPresent([Int].self, forKey: .ownVotes)
|
||||||
|
self.options = try container.decode([Poll.Option].self, forKey: .options)
|
||||||
|
self.emojis = try container.decodeIfPresent([Emoji].self, forKey: .emojis) ?? []
|
||||||
|
}
|
||||||
|
|
||||||
public var effectiveExpired: Bool {
|
public var effectiveExpired: Bool {
|
||||||
expired || (expiresAt != nil && expiresAt! < Date())
|
expired || (expiresAt != nil && expiresAt! < Date())
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ public final class Status: StatusProtocol, Decodable, Sendable {
|
||||||
self.reblog = try container.decodeIfPresent(Status.self, forKey: .reblog)
|
self.reblog = try container.decodeIfPresent(Status.self, forKey: .reblog)
|
||||||
self.content = try container.decode(String.self, forKey: .content)
|
self.content = try container.decode(String.self, forKey: .content)
|
||||||
self.createdAt = try container.decode(Date.self, forKey: .createdAt)
|
self.createdAt = try container.decode(Date.self, forKey: .createdAt)
|
||||||
self.emojis = try container.decode([Emoji].self, forKey: .emojis)
|
self.emojis = try container.decodeIfPresent([Emoji].self, forKey: .emojis) ?? []
|
||||||
self.reblogsCount = try container.decode(Int.self, forKey: .reblogsCount)
|
self.reblogsCount = try container.decode(Int.self, forKey: .reblogsCount)
|
||||||
self.favouritesCount = try container.decode(Int.self, forKey: .favouritesCount)
|
self.favouritesCount = try container.decode(Int.self, forKey: .favouritesCount)
|
||||||
self.reblogged = try container.decodeIfPresent(Bool.self, forKey: .reblogged)
|
self.reblogged = try container.decodeIfPresent(Bool.self, forKey: .reblogged)
|
||||||
|
|
Loading…
Reference in New Issue