mastodon-ios/Mastodon/Diffiable/Item/SearchResultItem.swift

59 lines
1.6 KiB
Swift
Raw Normal View History

//
// SearchResultItem.swift
// Mastodon
//
// Created by sxiaojian on 2021/4/6.
//
2021-04-07 13:49:33 +02:00
import CoreData
import Foundation
import MastodonSDK
enum SearchResultItem {
2021-04-07 15:01:32 +02:00
case hashtag(tag: Mastodon.Entity.Tag)
case account(account: Mastodon.Entity.Account)
2021-04-06 09:25:04 +02:00
2021-04-07 13:49:33 +02:00
case accountObjectID(accountObjectID: NSManagedObjectID)
2021-04-07 15:01:32 +02:00
case hashtagObjectID(hashtagObjectID: NSManagedObjectID)
2021-04-07 13:49:33 +02:00
2021-04-06 09:25:04 +02:00
case bottomLoader
}
extension SearchResultItem: Equatable {
static func == (lhs: SearchResultItem, rhs: SearchResultItem) -> Bool {
switch (lhs, rhs) {
2021-04-07 15:01:32 +02:00
case (.hashtag(let tagLeft), .hashtag(let tagRight)):
return tagLeft == tagRight
2021-04-06 09:25:04 +02:00
case (.account(let accountLeft), .account(let accountRight)):
return accountLeft == accountRight
2021-04-06 09:25:04 +02:00
case (.bottomLoader, .bottomLoader):
return true
2021-04-07 13:49:33 +02:00
case (.accountObjectID(let idLeft),.accountObjectID(let idRight)):
return idLeft == idRight
2021-04-07 15:01:32 +02:00
case (.hashtagObjectID(let idLeft),.hashtagObjectID(let idRight)):
2021-04-07 13:49:33 +02:00
return idLeft == idRight
default:
return false
}
}
}
extension SearchResultItem: Hashable {
func hash(into hasher: inout Hasher) {
switch self {
case .account(let account):
hasher.combine(account)
2021-04-07 15:01:32 +02:00
case .hashtag(let tag):
hasher.combine(tag)
2021-04-07 13:49:33 +02:00
case .accountObjectID(let id):
hasher.combine(id)
2021-04-07 15:01:32 +02:00
case .hashtagObjectID(let id):
2021-04-07 13:49:33 +02:00
hasher.combine(id)
2021-04-06 09:25:04 +02:00
case .bottomLoader:
hasher.combine(String(describing: SearchResultItem.bottomLoader.self))
}
}
}