85 lines
2.5 KiB
Swift
85 lines
2.5 KiB
Swift
|
//
|
||
|
// StatusItem.swift
|
||
|
// Mastodon
|
||
|
//
|
||
|
// Created by MainasuK on 2022-1-11.
|
||
|
//
|
||
|
|
||
|
import Foundation
|
||
|
import CoreDataStack
|
||
|
|
||
|
enum StatusItem: Hashable {
|
||
|
case feed(record: ManagedObjectRecord<Feed>)
|
||
|
case feedLoader(record: ManagedObjectRecord<Feed>)
|
||
|
case status(record: ManagedObjectRecord<Status>)
|
||
|
// case statusLoader(record: ManagedObjectRecord<Status>, context: StatusLoaderContext)
|
||
|
case thread(Thread)
|
||
|
case topLoader
|
||
|
case bottomLoader
|
||
|
}
|
||
|
|
||
|
//extension StatusItem {
|
||
|
// final class StatusLoaderContext: Hashable {
|
||
|
// let id = UUID()
|
||
|
// @Published var isFetching = false
|
||
|
//
|
||
|
// static func == (
|
||
|
// lhs: StatusItem.StatusLoaderContext,
|
||
|
// rhs: StatusItem.StatusLoaderContext
|
||
|
// ) -> Bool {
|
||
|
// return lhs.id == rhs.id
|
||
|
// }
|
||
|
//
|
||
|
// func hash(into hasher: inout Hasher) {
|
||
|
// hasher.combine(id)
|
||
|
// }
|
||
|
// }
|
||
|
//}
|
||
|
|
||
|
extension StatusItem {
|
||
|
enum Thread: Hashable {
|
||
|
case root(context: Context)
|
||
|
case reply(context: Context)
|
||
|
case leaf(context: Context)
|
||
|
|
||
|
public var record: ManagedObjectRecord<Status> {
|
||
|
switch self {
|
||
|
case .root(let threadContext),
|
||
|
.reply(let threadContext),
|
||
|
.leaf(let threadContext):
|
||
|
return threadContext.status
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
extension StatusItem.Thread {
|
||
|
class Context: Hashable {
|
||
|
let status: ManagedObjectRecord<Status>
|
||
|
var displayUpperConversationLink: Bool
|
||
|
var displayBottomConversationLink: Bool
|
||
|
|
||
|
init(
|
||
|
status: ManagedObjectRecord<Status>,
|
||
|
displayUpperConversationLink: Bool = false,
|
||
|
displayBottomConversationLink: Bool = false
|
||
|
) {
|
||
|
self.status = status
|
||
|
self.displayUpperConversationLink = displayUpperConversationLink
|
||
|
self.displayBottomConversationLink = displayBottomConversationLink
|
||
|
}
|
||
|
|
||
|
static func == (lhs: StatusItem.Thread.Context, rhs: StatusItem.Thread.Context) -> Bool {
|
||
|
return lhs.status == rhs.status
|
||
|
&& lhs.displayUpperConversationLink == rhs.displayUpperConversationLink
|
||
|
&& lhs.displayBottomConversationLink == rhs.displayBottomConversationLink
|
||
|
}
|
||
|
|
||
|
func hash(into hasher: inout Hasher) {
|
||
|
hasher.combine(status)
|
||
|
hasher.combine(displayUpperConversationLink)
|
||
|
hasher.combine(displayBottomConversationLink)
|
||
|
}
|
||
|
}
|
||
|
}
|