2020-07-29 23:50:30 +00:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
2020-08-04 20:26:09 +00:00
|
|
|
struct Identity: Codable, Hashable, Identifiable {
|
2020-08-07 23:19:13 +00:00
|
|
|
let id: UUID
|
2020-07-29 23:50:30 +00:00
|
|
|
let url: URL
|
2020-08-04 20:26:09 +00:00
|
|
|
let lastUsedAt: Date
|
2020-08-07 01:41:59 +00:00
|
|
|
let preferences: Identity.Preferences
|
2020-07-29 23:50:30 +00:00
|
|
|
let instance: Identity.Instance?
|
|
|
|
let account: Identity.Account?
|
2020-08-12 07:24:39 +00:00
|
|
|
let pushSubscriptionAlerts: PushSubscription.Alerts?
|
2020-07-29 23:50:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extension Identity {
|
|
|
|
struct Instance: Codable, Hashable {
|
|
|
|
let uri: String
|
|
|
|
let streamingAPI: URL
|
|
|
|
let title: String
|
|
|
|
let thumbnail: URL?
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Account: Codable, Hashable {
|
|
|
|
let id: String
|
2020-08-07 23:19:13 +00:00
|
|
|
let identityID: UUID
|
2020-07-29 23:50:30 +00:00
|
|
|
let username: String
|
2020-08-08 09:10:05 +00:00
|
|
|
let displayName: String
|
2020-07-29 23:50:30 +00:00
|
|
|
let url: URL
|
|
|
|
let avatar: URL
|
|
|
|
let avatarStatic: URL
|
|
|
|
let header: URL
|
|
|
|
let headerStatic: URL
|
2020-08-08 09:10:05 +00:00
|
|
|
let emojis: [Emoji]
|
2020-07-29 23:50:30 +00:00
|
|
|
}
|
2020-08-07 01:41:59 +00:00
|
|
|
|
|
|
|
struct Preferences: Codable, Hashable {
|
2020-08-07 10:59:48 +00:00
|
|
|
var useServerPostingReadingPreferences = true
|
2020-08-07 01:41:59 +00:00
|
|
|
var postingDefaultVisibility = Status.Visibility.public
|
|
|
|
var postingDefaultSensitive = false
|
|
|
|
var postingDefaultLanguage: String?
|
|
|
|
var readingExpandMedia = MastodonPreferences.ExpandMedia.default
|
|
|
|
var readingExpandSpoilers = false
|
|
|
|
}
|
2020-07-29 23:50:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extension Identity {
|
|
|
|
var handle: String {
|
|
|
|
if let account = account, let host = account.url.host {
|
|
|
|
return account.url.lastPathComponent + "@" + host
|
|
|
|
}
|
|
|
|
|
|
|
|
return instance?.title ?? url.host ?? url.absoluteString
|
|
|
|
}
|
2020-08-03 15:20:51 +00:00
|
|
|
|
|
|
|
var image: URL? { account?.avatar ?? instance?.thumbnail }
|
2020-07-29 23:50:30 +00:00
|
|
|
}
|
2020-08-07 10:14:14 +00:00
|
|
|
|
|
|
|
extension Identity.Preferences {
|
|
|
|
func updated(from serverPreferences: MastodonPreferences) -> Self {
|
|
|
|
var mutable = self
|
2020-08-07 10:59:48 +00:00
|
|
|
|
|
|
|
if useServerPostingReadingPreferences {
|
2020-08-07 10:14:14 +00:00
|
|
|
mutable.postingDefaultVisibility = serverPreferences.postingDefaultVisibility
|
|
|
|
mutable.postingDefaultSensitive = serverPreferences.postingDefaultSensitive
|
|
|
|
mutable.readingExpandMedia = serverPreferences.readingExpandMedia
|
|
|
|
mutable.readingExpandSpoilers = serverPreferences.readingExpandSpoilers
|
|
|
|
}
|
|
|
|
|
|
|
|
return mutable
|
|
|
|
}
|
|
|
|
}
|