2021-02-04 07:45:44 +01:00
|
|
|
//
|
2021-04-01 08:39:15 +02:00
|
|
|
// Status.swift
|
2021-02-04 07:45:44 +01:00
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021/2/4.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import CoreDataStack
|
|
|
|
import MastodonSDK
|
|
|
|
|
2021-04-01 08:39:15 +02:00
|
|
|
extension Status.Property {
|
2021-02-04 07:45:44 +01:00
|
|
|
init(entity: Mastodon.Entity.Status, domain: String, networkDate: Date) {
|
|
|
|
self.init(
|
|
|
|
domain: domain,
|
|
|
|
id: entity.id,
|
|
|
|
uri: entity.uri,
|
|
|
|
createdAt: entity.createdAt,
|
|
|
|
content: entity.content,
|
|
|
|
visibility: entity.visibility?.rawValue,
|
|
|
|
sensitive: entity.sensitive ?? false,
|
|
|
|
spoilerText: entity.spoilerText,
|
|
|
|
reblogsCount: NSNumber(value: entity.reblogsCount),
|
|
|
|
favouritesCount: NSNumber(value: entity.favouritesCount),
|
2021-02-04 07:57:16 +01:00
|
|
|
repliesCount: entity.repliesCount.flatMap { NSNumber(value: $0) },
|
2021-02-04 07:45:44 +01:00
|
|
|
url: entity.uri,
|
|
|
|
inReplyToID: entity.inReplyToID,
|
|
|
|
inReplyToAccountID: entity.inReplyToAccountID,
|
|
|
|
language: entity.language,
|
|
|
|
text: entity.text,
|
|
|
|
networkDate: networkDate
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2021-04-16 14:06:36 +02:00
|
|
|
|
|
|
|
extension Status {
|
|
|
|
|
|
|
|
enum SensitiveType {
|
|
|
|
case none
|
|
|
|
case all
|
|
|
|
case media(isSensitive: Bool)
|
|
|
|
}
|
|
|
|
|
|
|
|
var sensitiveType: SensitiveType {
|
|
|
|
let spoilerText = self.spoilerText ?? ""
|
|
|
|
|
|
|
|
// cast .all sensitive when has spoiter text
|
|
|
|
if !spoilerText.isEmpty {
|
|
|
|
return .all
|
|
|
|
}
|
|
|
|
|
|
|
|
if let firstAttachment = mediaAttachments?.first {
|
|
|
|
// cast .media when has non audio media
|
|
|
|
if firstAttachment.type != .audio {
|
|
|
|
return .media(isSensitive: sensitive)
|
|
|
|
} else {
|
|
|
|
return .none
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// not sensitive
|
|
|
|
return .none
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-04-29 04:50:10 +02:00
|
|
|
|
|
|
|
extension Status {
|
|
|
|
var authorForUserProvider: MastodonUser {
|
|
|
|
let author = (reblog ?? self).author
|
|
|
|
return author
|
|
|
|
}
|
|
|
|
}
|
2021-04-29 05:03:21 +02:00
|
|
|
|
|
|
|
extension Status {
|
|
|
|
|
|
|
|
var statusURL: URL {
|
|
|
|
return URL(string: "https://\(self.domain)/web/statuses/\(self.id)")!
|
|
|
|
}
|
|
|
|
|
|
|
|
var activityItems: [Any] {
|
|
|
|
var items: [Any] = []
|
|
|
|
items.append(statusURL)
|
|
|
|
return items
|
|
|
|
}
|
|
|
|
}
|