Kurdtvs-Live-Kurdish-TV-Kur.../Mastodon/Diffiable/Compose/ComposeStatusItem.swift

67 lines
2.1 KiB
Swift
Raw Normal View History

2021-03-11 08:41:27 +01:00
//
// ComposeStatusItem.swift
// Mastodon
//
// Created by MainasuK Cirno on 2021-3-11.
//
import Foundation
import Combine
2021-03-11 08:41:27 +01:00
import CoreData
2021-07-23 13:10:27 +02:00
import MastodonMeta
import CoreDataStack
2021-03-11 08:41:27 +01:00
2021-03-23 11:47:21 +01:00
/// Note: update Equatable when change case
2021-03-11 08:41:27 +01:00
enum ComposeStatusItem {
case replyTo(record: ManagedObjectRecord<Status>)
case input(replyTo: ManagedObjectRecord<Status>?, attribute: ComposeStatusAttribute)
2021-06-29 10:41:58 +02:00
case attachment(attachmentAttribute: ComposeStatusAttachmentAttribute)
case pollOption(pollOptionAttributes: [ComposeStatusPollItem.PollOptionAttribute], pollExpiresOptionAttribute: ComposeStatusPollItem.PollExpiresOptionAttribute)
2021-03-11 08:41:27 +01:00
}
extension ComposeStatusItem: Hashable { }
extension ComposeStatusItem {
final class ComposeStatusAttribute: Hashable {
private let id = UUID()
@Published var author: ManagedObjectRecord<MastodonUser>?
@Published var composeContent: String?
@Published var isContentWarningComposing = false
@Published var contentWarningContent = ""
2021-03-16 04:23:19 +01:00
static func == (lhs: ComposeStatusAttribute, rhs: ComposeStatusAttribute) -> Bool {
return lhs.author == rhs.author
&& lhs.composeContent == rhs.composeContent
&& lhs.isContentWarningComposing == rhs.isContentWarningComposing
&& lhs.contentWarningContent == rhs.contentWarningContent
}
func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
}
}
2021-03-23 11:47:21 +01:00
extension ComposeStatusItem {
2021-06-29 10:41:58 +02:00
final class ComposeStatusAttachmentAttribute: Hashable {
2021-03-23 11:47:21 +01:00
private let id = UUID()
2021-06-29 10:41:58 +02:00
var attachmentServices: [MastodonAttachmentService]
2021-06-29 10:41:58 +02:00
init(attachmentServices: [MastodonAttachmentService]) {
self.attachmentServices = attachmentServices
}
2021-06-29 10:41:58 +02:00
static func == (lhs: ComposeStatusAttachmentAttribute, rhs: ComposeStatusAttachmentAttribute) -> Bool {
return lhs.attachmentServices == rhs.attachmentServices
}
2021-06-29 10:41:58 +02:00
func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
}
}