2021-01-28 09:10:30 +01:00
|
|
|
//
|
|
|
|
// Item.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by sxiaojian on 2021/1/27.
|
|
|
|
//
|
|
|
|
|
|
|
|
import CoreData
|
|
|
|
import CoreDataStack
|
2021-02-03 06:01:50 +01:00
|
|
|
import Foundation
|
|
|
|
import MastodonSDK
|
2021-01-28 09:10:30 +01:00
|
|
|
|
|
|
|
/// Note: update Equatable when change case
|
|
|
|
enum Item {
|
2021-02-24 09:11:48 +01:00
|
|
|
// timeline
|
2021-03-05 06:41:48 +01:00
|
|
|
case homeTimelineIndex(objectID: NSManagedObjectID, attribute: StatusAttribute)
|
2021-02-07 07:42:50 +01:00
|
|
|
|
2021-01-28 09:10:30 +01:00
|
|
|
// normal list
|
2021-03-05 06:41:48 +01:00
|
|
|
case toot(objectID: NSManagedObjectID, attribute: StatusAttribute)
|
2021-02-03 06:01:50 +01:00
|
|
|
|
2021-02-04 08:09:58 +01:00
|
|
|
// loader
|
2021-02-07 07:42:50 +01:00
|
|
|
case homeMiddleLoader(upperTimelineIndexAnchorObjectID: NSManagedObjectID)
|
|
|
|
case publicMiddleLoader(tootID: String)
|
2021-02-03 06:01:50 +01:00
|
|
|
case bottomLoader
|
2021-01-28 09:10:30 +01:00
|
|
|
}
|
|
|
|
|
2021-02-24 09:11:48 +01:00
|
|
|
protocol StatusContentWarningAttribute {
|
|
|
|
var isStatusTextSensitive: Bool { get set }
|
2021-02-25 06:47:30 +01:00
|
|
|
var isStatusSensitive: Bool { get set }
|
2021-02-24 09:11:48 +01:00
|
|
|
}
|
|
|
|
|
2021-02-07 07:42:50 +01:00
|
|
|
extension Item {
|
2021-03-07 15:26:05 +01:00
|
|
|
class StatusAttribute: Equatable, Hashable, StatusContentWarningAttribute {
|
2021-02-25 06:47:30 +01:00
|
|
|
var isStatusTextSensitive: Bool
|
|
|
|
var isStatusSensitive: Bool
|
2021-02-07 07:42:50 +01:00
|
|
|
|
2021-02-24 09:11:48 +01:00
|
|
|
public init(
|
2021-02-25 06:47:30 +01:00
|
|
|
isStatusTextSensitive: Bool,
|
|
|
|
isStatusSensitive: Bool
|
2021-02-24 09:11:48 +01:00
|
|
|
) {
|
|
|
|
self.isStatusTextSensitive = isStatusTextSensitive
|
2021-02-25 06:47:30 +01:00
|
|
|
self.isStatusSensitive = isStatusSensitive
|
2021-02-24 09:11:48 +01:00
|
|
|
}
|
|
|
|
|
2021-03-05 06:41:48 +01:00
|
|
|
static func == (lhs: Item.StatusAttribute, rhs: Item.StatusAttribute) -> Bool {
|
2021-02-25 06:47:30 +01:00
|
|
|
return lhs.isStatusTextSensitive == rhs.isStatusTextSensitive &&
|
|
|
|
lhs.isStatusSensitive == rhs.isStatusSensitive
|
2021-02-07 07:42:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func hash(into hasher: inout Hasher) {
|
2021-02-24 09:11:48 +01:00
|
|
|
hasher.combine(isStatusTextSensitive)
|
2021-02-25 06:47:30 +01:00
|
|
|
hasher.combine(isStatusSensitive)
|
2021-02-07 07:42:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-28 09:10:30 +01:00
|
|
|
extension Item: Equatable {
|
|
|
|
static func == (lhs: Item, rhs: Item) -> Bool {
|
|
|
|
switch (lhs, rhs) {
|
2021-02-07 07:42:50 +01:00
|
|
|
case (.homeTimelineIndex(let objectIDLeft, _), .homeTimelineIndex(let objectIDRight, _)):
|
|
|
|
return objectIDLeft == objectIDRight
|
2021-02-24 09:11:48 +01:00
|
|
|
case (.toot(let objectIDLeft, _), .toot(let objectIDRight, _)):
|
2021-01-28 09:10:30 +01:00
|
|
|
return objectIDLeft == objectIDRight
|
2021-02-04 04:12:17 +01:00
|
|
|
case (.bottomLoader, .bottomLoader):
|
|
|
|
return true
|
2021-02-07 07:42:50 +01:00
|
|
|
case (.publicMiddleLoader(let upperLeft), .publicMiddleLoader(let upperRight)):
|
|
|
|
return upperLeft == upperRight
|
|
|
|
case (.homeMiddleLoader(let upperLeft), .homeMiddleLoader(let upperRight)):
|
2021-02-04 08:09:58 +01:00
|
|
|
return upperLeft == upperRight
|
2021-02-03 06:01:50 +01:00
|
|
|
default:
|
|
|
|
return false
|
2021-01-28 09:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Item: Hashable {
|
|
|
|
func hash(into hasher: inout Hasher) {
|
|
|
|
switch self {
|
2021-02-07 07:42:50 +01:00
|
|
|
case .homeTimelineIndex(let objectID, _):
|
|
|
|
hasher.combine(objectID)
|
2021-02-24 09:11:48 +01:00
|
|
|
case .toot(let objectID, _):
|
2021-01-28 09:10:30 +01:00
|
|
|
hasher.combine(objectID)
|
2021-02-07 07:42:50 +01:00
|
|
|
case .publicMiddleLoader(let upper):
|
|
|
|
hasher.combine(String(describing: Item.publicMiddleLoader.self))
|
|
|
|
hasher.combine(upper)
|
|
|
|
case .homeMiddleLoader(upperTimelineIndexAnchorObjectID: let upper):
|
|
|
|
hasher.combine(String(describing: Item.homeMiddleLoader.self))
|
2021-02-04 08:09:58 +01:00
|
|
|
hasher.combine(upper)
|
2021-02-03 06:01:50 +01:00
|
|
|
case .bottomLoader:
|
|
|
|
hasher.combine(String(describing: Item.bottomLoader.self))
|
2021-01-28 09:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|