-
-
Notifications
You must be signed in to change notification settings - Fork 298
Expand file tree
/
Copy pathPickServerItem.swift
More file actions
87 lines (73 loc) · 2.45 KB
/
PickServerItem.swift
File metadata and controls
87 lines (73 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
// PickServerItem.swift
// Mastodon
//
// Created by Cirno MainasuK on 2021/3/5.
//
import Foundation
import Combine
import MastodonSDK
/// Note: update Equatable when change case
enum PickServerItem {
case server(server: Mastodon.Entity.Server, attribute: ServerItemAttribute)
case loader(attribute: LoaderItemAttribute)
case message(attribute: MessageItemAttribute)
}
extension PickServerItem {
final class ServerItemAttribute: Equatable, Hashable {
var isLast: CurrentValueSubject<Bool, Never>
var isExpand: Bool
init(isLast: Bool, isExpand: Bool) {
self.isLast = CurrentValueSubject(isLast)
self.isExpand = isExpand
}
static func == (lhs: PickServerItem.ServerItemAttribute, rhs: PickServerItem.ServerItemAttribute) -> Bool {
return lhs.isExpand == rhs.isExpand
}
func hash(into hasher: inout Hasher) {
hasher.combine(isExpand)
}
}
final class LoaderItemAttribute: Equatable, Hashable {
let id = UUID()
var isLast: Bool
var isNoResult: Bool
init(isLast: Bool, isEmptyResult: Bool) {
self.isLast = isLast
self.isNoResult = isEmptyResult
}
static func == (lhs: PickServerItem.LoaderItemAttribute, rhs: PickServerItem.LoaderItemAttribute) -> Bool {
return lhs.id == rhs.id
}
func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
}
enum MessageItemAttribute: Equatable, Hashable {
case categoryIgnored(category: Mastodon.Entity.Category.Kind)
}
}
extension PickServerItem: Equatable {
static func == (lhs: PickServerItem, rhs: PickServerItem) -> Bool {
switch (lhs, rhs) {
case (.server(let serverLeft, _), .server(let serverRight, _)):
return serverLeft.domain == serverRight.domain
case (.loader(let attributeLeft), loader(let attributeRight)):
return attributeLeft == attributeRight
default:
return false
}
}
}
extension PickServerItem: Hashable {
func hash(into hasher: inout Hasher) {
switch self {
case .server(let server, _):
hasher.combine(server.domain)
case .loader(let attribute):
hasher.combine(attribute)
case .message(let attribute):
hasher.combine(attribute)
}
}
}