2020-07-30 01:50:30 +02:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
2020-08-04 22:26:09 +02:00
|
|
|
struct Identity: Codable, Hashable, Identifiable {
|
2020-07-30 01:50:30 +02:00
|
|
|
let id: String
|
|
|
|
let url: URL
|
2020-08-04 22:26:09 +02:00
|
|
|
let lastUsedAt: Date
|
2020-07-30 01:50:30 +02:00
|
|
|
let instance: Identity.Instance?
|
|
|
|
let account: Identity.Account?
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
let identityID: String
|
|
|
|
let username: String
|
|
|
|
let url: URL
|
|
|
|
let avatar: URL
|
|
|
|
let avatarStatic: URL
|
|
|
|
let header: URL
|
|
|
|
let headerStatic: URL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 17:20:51 +02:00
|
|
|
|
|
|
|
var image: URL? { account?.avatar ?? instance?.thumbnail }
|
2020-07-30 01:50:30 +02:00
|
|
|
}
|