2022-12-21 04:37:12 +00:00
|
|
|
//
|
|
|
|
// AccountPreferences.swift
|
|
|
|
// Tusker
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 12/19/22.
|
|
|
|
// Copyright © 2022 Shadowfacts. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import CoreData
|
|
|
|
import Pachyderm
|
2023-03-05 19:35:25 +00:00
|
|
|
import UserAccounts
|
2022-12-21 04:37:12 +00:00
|
|
|
|
|
|
|
@objc(AccountPreferences)
|
|
|
|
public final class AccountPreferences: NSManagedObject {
|
|
|
|
|
2023-03-05 19:35:25 +00:00
|
|
|
@nonobjc class func fetchRequest(account: UserAccountInfo) -> NSFetchRequest<AccountPreferences> {
|
2022-12-21 04:37:12 +00:00
|
|
|
let req = NSFetchRequest<AccountPreferences>(entityName: "AccountPreferences")
|
|
|
|
req.predicate = NSPredicate(format: "accountID = %@", account.id)
|
2023-01-01 17:58:44 +00:00
|
|
|
req.sortDescriptors = [NSSortDescriptor(key: "createdAt", ascending: true)]
|
2022-12-21 04:37:12 +00:00
|
|
|
return req
|
|
|
|
}
|
|
|
|
|
|
|
|
@NSManaged public var accountID: String
|
2023-01-01 17:58:44 +00:00
|
|
|
@NSManaged var createdAt: Date
|
2022-12-21 04:37:12 +00:00
|
|
|
@NSManaged var pinnedTimelinesData: Data?
|
2023-10-27 19:58:15 +00:00
|
|
|
@NSManaged var serverDefaultLanguage: String?
|
|
|
|
@NSManaged private var serverDefaultVisibilityString: String?
|
2022-12-21 04:37:12 +00:00
|
|
|
|
2023-03-01 03:42:28 +00:00
|
|
|
@LazilyDecoding(from: \AccountPreferences.pinnedTimelinesData, fallback: AccountPreferences.defaultPinnedTimelines)
|
2023-01-27 23:12:54 +00:00
|
|
|
var pinnedTimelines: [PinnedTimeline]
|
2022-12-21 04:37:12 +00:00
|
|
|
|
2023-10-27 19:58:15 +00:00
|
|
|
var serverDefaultVisibility: Visibility? {
|
|
|
|
get {
|
|
|
|
serverDefaultVisibilityString.flatMap(Visibility.init(rawValue:))
|
|
|
|
}
|
|
|
|
set {
|
|
|
|
serverDefaultVisibilityString = newValue?.rawValue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-05 19:35:25 +00:00
|
|
|
static func `default`(account: UserAccountInfo, context: NSManagedObjectContext) -> AccountPreferences {
|
2022-12-21 04:37:12 +00:00
|
|
|
let prefs = AccountPreferences(context: context)
|
|
|
|
prefs.accountID = account.id
|
2023-01-01 17:58:44 +00:00
|
|
|
prefs.createdAt = Date()
|
2023-03-01 03:42:28 +00:00
|
|
|
prefs.pinnedTimelines = Self.defaultPinnedTimelines
|
2022-12-21 04:37:12 +00:00
|
|
|
return prefs
|
|
|
|
}
|
|
|
|
|
2023-03-01 03:42:28 +00:00
|
|
|
private static let defaultPinnedTimelines = [PinnedTimeline.home, .public(local: true), .public(local: false)]
|
|
|
|
|
2022-12-21 04:37:12 +00:00
|
|
|
}
|