forked from shadowfacts/Tusker
53 lines
1.7 KiB
Swift
53 lines
1.7 KiB
Swift
//
|
|
// ActiveInstance.swift
|
|
// Tusker
|
|
//
|
|
// Created by Shadowfacts on 5/28/23.
|
|
// Copyright © 2023 Shadowfacts. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import CoreData
|
|
import Pachyderm
|
|
import InstanceFeatures
|
|
|
|
@objc(ActiveInstance)
|
|
public final class ActiveInstance: NSManagedObject {
|
|
|
|
@nonobjc class public func fetchRequest() -> NSFetchRequest<ActiveInstance> {
|
|
return NSFetchRequest(entityName: "ActiveInstance")
|
|
}
|
|
|
|
@NSManaged public var version: String
|
|
@NSManaged public var maxStatusCharacters: Int
|
|
@NSManaged private var configurationData: Data?
|
|
@NSManaged private var pollsConfigurationData: Data?
|
|
@NSManaged public var translation: Bool
|
|
|
|
@LazilyDecoding(from: \ActiveInstance.configurationData, fallback: nil)
|
|
public var configuration: InstanceV1.Configuration?
|
|
|
|
@LazilyDecoding(from: \ActiveInstance.pollsConfigurationData, fallback: nil)
|
|
public var pollsConfiguration: InstanceV1.PollsConfiguration?
|
|
|
|
func update(from info: InstanceInfo) {
|
|
self.version = info.version
|
|
self.maxStatusCharacters = info.maxStatusCharacters ?? 500
|
|
self.configuration = info.configuration
|
|
self.pollsConfiguration = info.pollsConfiguration
|
|
self.translation = info.translation
|
|
}
|
|
}
|
|
|
|
extension InstanceInfo {
|
|
init(activeInstance: ActiveInstance) {
|
|
self.init(
|
|
version: activeInstance.version,
|
|
maxStatusCharacters: activeInstance.maxStatusCharacters,
|
|
configuration: activeInstance.configuration,
|
|
pollsConfiguration: activeInstance.pollsConfiguration,
|
|
translation: activeInstance.translation
|
|
)
|
|
}
|
|
}
|