2021-02-03 09:01:08 +01:00
|
|
|
//
|
|
|
|
// MastodonUser.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021/2/3.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import CoreDataStack
|
|
|
|
import MastodonSDK
|
|
|
|
|
|
|
|
extension MastodonUser.Property {
|
|
|
|
init(entity: Mastodon.Entity.Account, domain: String, networkDate: Date) {
|
|
|
|
self.init(
|
|
|
|
id: entity.id,
|
|
|
|
domain: domain,
|
|
|
|
acct: entity.acct,
|
|
|
|
username: entity.username,
|
|
|
|
displayName: entity.displayName,
|
|
|
|
avatar: entity.avatar,
|
|
|
|
avatarStatic: entity.avatarStatic,
|
2021-04-01 08:39:15 +02:00
|
|
|
header: entity.header,
|
|
|
|
headerStatic: entity.headerStatic,
|
|
|
|
note: entity.note,
|
|
|
|
url: entity.url,
|
|
|
|
statusesCount: entity.statusesCount,
|
|
|
|
followingCount: entity.followingCount,
|
|
|
|
followersCount: entity.followersCount,
|
2021-04-02 12:13:45 +02:00
|
|
|
locked: entity.locked,
|
|
|
|
bot: entity.bot,
|
2021-04-08 10:53:32 +02:00
|
|
|
suspended: entity.suspended,
|
2021-02-03 09:01:08 +01:00
|
|
|
createdAt: entity.createdAt,
|
|
|
|
networkDate: networkDate
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2021-02-04 12:37:38 +01:00
|
|
|
|
|
|
|
extension MastodonUser {
|
2021-04-01 08:39:15 +02:00
|
|
|
|
|
|
|
var displayNameWithFallback: String {
|
|
|
|
return !displayName.isEmpty ? displayName : username
|
|
|
|
}
|
|
|
|
|
|
|
|
var acctWithDomain: String {
|
2021-04-02 12:13:45 +02:00
|
|
|
if !acct.contains("@") {
|
|
|
|
// Safe concat due to username cannot contains "@"
|
|
|
|
return username + "@" + domain
|
|
|
|
} else {
|
|
|
|
return acct
|
|
|
|
}
|
2021-04-01 08:39:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
extension MastodonUser {
|
|
|
|
|
|
|
|
public func headerImageURL() -> URL? {
|
|
|
|
return URL(string: header)
|
|
|
|
}
|
|
|
|
|
2021-02-04 12:37:38 +01:00
|
|
|
public func avatarImageURL() -> URL? {
|
|
|
|
return URL(string: avatar)
|
|
|
|
}
|
2021-04-01 08:39:15 +02:00
|
|
|
|
2021-02-04 12:37:38 +01:00
|
|
|
}
|
2021-04-08 12:52:35 +02:00
|
|
|
|
|
|
|
extension MastodonUser {
|
|
|
|
|
|
|
|
var profileURL: URL {
|
|
|
|
if let urlString = self.url,
|
|
|
|
let url = URL(string: urlString) {
|
|
|
|
return url
|
|
|
|
} else {
|
|
|
|
return URL(string: "https://\(self.domain)/@\(username)")!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var activityItems: [Any] {
|
|
|
|
var items: [Any] = []
|
|
|
|
items.append(profileURL)
|
|
|
|
return items
|
|
|
|
}
|
|
|
|
}
|