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

69 lines
1.6 KiB
Swift
Raw Normal View History

//
// PollItem.swift
// Mastodon
//
// Created by MainasuK Cirno on 2021-3-2.
//
import Foundation
import CoreData
2021-03-23 11:47:21 +01:00
/// Note: update Equatable when change case
enum PollItem {
2021-07-05 10:07:17 +02:00
case option(objectID: NSManagedObjectID, attribute: Attribute)
}
extension PollItem {
class Attribute: Hashable {
enum SelectState: Equatable, Hashable {
case none
case off
case on
}
enum VoteState: Equatable, Hashable {
case hidden
2021-03-05 06:41:48 +01:00
case reveal(voted: Bool, percentage: Double, animated: Bool)
}
var selectState: SelectState
var voteState: VoteState
init(selectState: SelectState, voteState: VoteState) {
self.selectState = selectState
self.voteState = voteState
2021-03-02 12:10:45 +01:00
}
static func == (lhs: PollItem.Attribute, rhs: PollItem.Attribute) -> Bool {
return lhs.selectState == rhs.selectState &&
lhs.voteState == rhs.voteState
}
func hash(into hasher: inout Hasher) {
hasher.combine(selectState)
hasher.combine(voteState)
}
}
}
extension PollItem: Equatable {
static func == (lhs: PollItem, rhs: PollItem) -> Bool {
switch (lhs, rhs) {
2021-07-05 10:07:17 +02:00
case (.option(let objectIDLeft, _), .option(let objectIDRight, _)):
return objectIDLeft == objectIDRight
}
}
}
extension PollItem: Hashable {
func hash(into hasher: inout Hasher) {
switch self {
2021-07-05 10:07:17 +02:00
case .option(let objectID, _):
hasher.combine(objectID)
}
}
}