2017-07-03 19:29:44 +02:00
|
|
|
//
|
|
|
|
// ArticleStatus.swift
|
|
|
|
// DataModel
|
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 7/1/17.
|
|
|
|
// Copyright © 2017 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
public enum ArticleStatusKey: String {
|
|
|
|
|
|
|
|
case read = "read"
|
|
|
|
case starred = "starred"
|
|
|
|
case userDeleted = "userDeleted"
|
|
|
|
}
|
|
|
|
|
2017-07-03 20:20:14 +02:00
|
|
|
public final class ArticleStatus: Hashable {
|
2017-07-03 19:29:44 +02:00
|
|
|
|
|
|
|
public var read = false
|
|
|
|
public var starred = false
|
|
|
|
public var userDeleted = false
|
|
|
|
public var dateArrived: Date
|
|
|
|
var accountInfo: AccountInfo?
|
2017-07-03 20:20:14 +02:00
|
|
|
public let hashValue: Int
|
2017-07-03 19:29:44 +02:00
|
|
|
|
|
|
|
init(read: Bool, starred: Bool, userDeleted: Bool, dateArrived: Date, accountInfo: AccountInfo?) {
|
|
|
|
|
|
|
|
self.read = read
|
|
|
|
self.starred = starred
|
|
|
|
self.userDeleted = userDeleted
|
|
|
|
self.dateArrived = dateArrived
|
|
|
|
self.accountInfo = accountInfo
|
2017-07-03 20:20:14 +02:00
|
|
|
self.hashValue = dateArrived.hashValue
|
2017-07-03 19:29:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func boolStatusForKey(_ key: String) -> Bool {
|
|
|
|
|
|
|
|
if let articleStatusKey = ArticleStatusKey(rawValue: key) {
|
|
|
|
switch articleStatusKey {
|
|
|
|
case .read:
|
|
|
|
return read
|
|
|
|
case .starred:
|
|
|
|
return starred
|
|
|
|
case .userDeleted:
|
|
|
|
return userDeleted
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if let flag = accountInfo?[key] as? Bool {
|
|
|
|
return flag
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func setBoolStatusForKey(_ status: Bool, key: String) {
|
|
|
|
|
|
|
|
if let articleStatusKey = ArticleStatusKey(rawValue: key) {
|
|
|
|
switch articleStatusKey {
|
|
|
|
case .read:
|
|
|
|
read = status
|
|
|
|
case .starred:
|
|
|
|
starred = status
|
|
|
|
case .userDeleted:
|
|
|
|
userDeleted = status
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if accountInfo == nil {
|
|
|
|
accountInfo = AccountInfo()
|
|
|
|
}
|
|
|
|
accountInfo![key] = status
|
|
|
|
}
|
|
|
|
}
|
2017-07-03 20:20:14 +02:00
|
|
|
|
|
|
|
public class func ==(lhs: ArticleStatus, rhs: ArticleStatus) -> Bool {
|
|
|
|
|
|
|
|
return lhs.dateArrived == rhs.dateArrived && lhs.read == rhs.read && lhs.starred == rhs.starred
|
|
|
|
}
|
2017-07-03 19:29:44 +02:00
|
|
|
}
|