2021-04-12 10:31:53 +02:00
|
|
|
//
|
|
|
|
// NotificationItem.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by sxiaojian on 2021/4/13.
|
|
|
|
//
|
|
|
|
|
|
|
|
import CoreData
|
2021-04-15 04:16:30 +02:00
|
|
|
import Foundation
|
2021-04-12 10:31:53 +02:00
|
|
|
|
|
|
|
enum NotificationItem {
|
2021-04-20 07:18:27 +02:00
|
|
|
case notification(objectID: NSManagedObjectID, attribute: Item.StatusAttribute)
|
2021-04-12 10:31:53 +02:00
|
|
|
|
|
|
|
case bottomLoader
|
|
|
|
}
|
|
|
|
|
|
|
|
extension NotificationItem: Equatable {
|
|
|
|
static func == (lhs: NotificationItem, rhs: NotificationItem) -> Bool {
|
|
|
|
switch (lhs, rhs) {
|
2021-04-20 07:18:27 +02:00
|
|
|
case (.notification(let idLeft, _), .notification(let idRight, _)):
|
2021-04-12 10:31:53 +02:00
|
|
|
return idLeft == idRight
|
2021-04-16 07:45:54 +02:00
|
|
|
case (.bottomLoader, .bottomLoader):
|
|
|
|
return true
|
2021-04-12 10:31:53 +02:00
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension NotificationItem: Hashable {
|
|
|
|
func hash(into hasher: inout Hasher) {
|
|
|
|
switch self {
|
2021-04-20 07:18:27 +02:00
|
|
|
case .notification(let id, _):
|
2021-04-12 10:31:53 +02:00
|
|
|
hasher.combine(id)
|
|
|
|
case .bottomLoader:
|
|
|
|
hasher.combine(String(describing: NotificationItem.bottomLoader.self))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-07-15 03:56:26 +02:00
|
|
|
|
|
|
|
extension NotificationItem {
|
|
|
|
var statusObjectItem: StatusObjectItem? {
|
|
|
|
switch self {
|
|
|
|
case .notification(let objectID, _):
|
|
|
|
return .mastodonNotification(objectID: objectID)
|
|
|
|
case .bottomLoader:
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|