64 lines
1.5 KiB
Swift
64 lines
1.5 KiB
Swift
//
|
|
// InstanceFeatures.swift
|
|
// Tusker
|
|
//
|
|
// Created by Shadowfacts on 1/23/22.
|
|
// Copyright © 2022 Shadowfacts. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import Pachyderm
|
|
|
|
struct InstanceFeatures {
|
|
private(set) var instanceType = InstanceType.mastodon
|
|
private(set) var maxStatusChars = 500
|
|
|
|
var localOnlyPosts: Bool {
|
|
instanceType == .hometown || instanceType == .glitch
|
|
}
|
|
|
|
var mastodonAttachmentRestrictions: Bool {
|
|
instanceType.isMastodon
|
|
}
|
|
|
|
var pollsAndAttachments: Bool {
|
|
instanceType == .pleroma
|
|
}
|
|
|
|
var boostToOriginalAudience: Bool {
|
|
instanceType == .pleroma
|
|
}
|
|
|
|
mutating func update(instance: Instance, nodeInfo: NodeInfo?) {
|
|
if instance.version.contains("glitch") {
|
|
instanceType = .glitch
|
|
} else if nodeInfo?.software.name == "hometown" {
|
|
instanceType = .hometown
|
|
} else if instance.version.contains("pleroma") {
|
|
instanceType = .pleroma
|
|
} else {
|
|
instanceType = .mastodon
|
|
}
|
|
|
|
maxStatusChars = instance.maxStatusCharacters ?? 500
|
|
}
|
|
}
|
|
|
|
extension InstanceFeatures {
|
|
enum InstanceType: Equatable {
|
|
case mastodon // vanilla
|
|
case pleroma
|
|
case hometown
|
|
case glitch
|
|
|
|
var isMastodon: Bool {
|
|
switch self {
|
|
case .mastodon, .hometown, .glitch:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
}
|