2019-11-14 22:06:32 +01:00
|
|
|
//
|
|
|
|
// ArticleFetcherType.swift
|
|
|
|
// Account
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 11/13/19.
|
|
|
|
// Copyright © 2019 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
2019-11-15 13:19:14 +01:00
|
|
|
public protocol FeedIdentifiable {
|
|
|
|
var feedID: FeedIdentifier? { get }
|
|
|
|
}
|
|
|
|
|
2019-11-27 18:43:36 +01:00
|
|
|
public enum FeedIdentifier: CustomStringConvertible, Hashable {
|
2019-11-14 22:06:32 +01:00
|
|
|
|
|
|
|
case smartFeed(String) // String is a unique identifier
|
|
|
|
case script(String) // String is a unique identifier
|
2019-11-15 03:11:41 +01:00
|
|
|
case webFeed(String, String) // accountID, webFeedID
|
2019-11-14 22:06:32 +01:00
|
|
|
case folder(String, String) // accountID, folderName
|
|
|
|
|
|
|
|
public var description: String {
|
|
|
|
switch self {
|
|
|
|
case .smartFeed(let id):
|
|
|
|
return "smartFeed: \(id)"
|
|
|
|
case .script(let id):
|
|
|
|
return "script: \(id)"
|
2019-11-15 03:11:41 +01:00
|
|
|
case .webFeed(let accountID, let webFeedID):
|
|
|
|
return "feed: \(accountID)_\(webFeedID)"
|
2019-11-14 22:06:32 +01:00
|
|
|
case .folder(let accountID, let folderName):
|
|
|
|
return "folder: \(accountID)_\(folderName)"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-27 18:43:36 +01:00
|
|
|
public var userInfo: [AnyHashable: AnyHashable] {
|
2019-11-14 22:06:32 +01:00
|
|
|
switch self {
|
|
|
|
case .smartFeed(let id):
|
|
|
|
return [
|
|
|
|
"type": "smartFeed",
|
|
|
|
"id": id
|
|
|
|
]
|
|
|
|
case .script(let id):
|
|
|
|
return [
|
|
|
|
"type": "script",
|
|
|
|
"id": id
|
|
|
|
]
|
2019-11-15 03:11:41 +01:00
|
|
|
case .webFeed(let accountID, let webFeedID):
|
2019-11-14 22:06:32 +01:00
|
|
|
return [
|
|
|
|
"type": "feed",
|
|
|
|
"accountID": accountID,
|
2019-11-15 03:11:41 +01:00
|
|
|
"webFeedID": webFeedID
|
2019-11-14 22:06:32 +01:00
|
|
|
]
|
|
|
|
case .folder(let accountID, let folderName):
|
|
|
|
return [
|
|
|
|
"type": "folder",
|
|
|
|
"accountID": accountID,
|
|
|
|
"folderName": folderName
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-27 18:43:36 +01:00
|
|
|
public init?(userInfo: [AnyHashable: AnyHashable]) {
|
2019-11-14 22:06:32 +01:00
|
|
|
guard let type = userInfo["type"] as? String else { return nil }
|
|
|
|
|
|
|
|
switch type {
|
|
|
|
case "smartFeed":
|
|
|
|
guard let id = userInfo["id"] as? String else { return nil }
|
2019-11-15 13:19:14 +01:00
|
|
|
self = FeedIdentifier.smartFeed(id)
|
2019-11-14 22:06:32 +01:00
|
|
|
case "script":
|
|
|
|
guard let id = userInfo["id"] as? String else { return nil }
|
2019-11-15 13:19:14 +01:00
|
|
|
self = FeedIdentifier.script(id)
|
2019-11-14 22:06:32 +01:00
|
|
|
case "feed":
|
2019-11-15 03:11:41 +01:00
|
|
|
guard let accountID = userInfo["accountID"] as? String, let webFeedID = userInfo["webFeedID"] as? String else { return nil }
|
2019-11-15 13:19:14 +01:00
|
|
|
self = FeedIdentifier.webFeed(accountID, webFeedID)
|
2019-11-14 22:06:32 +01:00
|
|
|
case "folder":
|
|
|
|
guard let accountID = userInfo["accountID"] as? String, let folderName = userInfo["folderName"] as? String else { return nil }
|
2019-11-15 13:19:14 +01:00
|
|
|
self = FeedIdentifier.folder(accountID, folderName)
|
2019-11-14 22:06:32 +01:00
|
|
|
default:
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
2020-02-02 00:00:36 +01:00
|
|
|
|
|
|
|
// MARK: - Hashable
|
|
|
|
|
|
|
|
public func hash(into hasher: inout Hasher) {
|
|
|
|
switch self {
|
|
|
|
case .smartFeed(let id):
|
2020-04-09 18:20:53 +02:00
|
|
|
hasher.combine("smartFeed")
|
2020-02-02 00:00:36 +01:00
|
|
|
hasher.combine(id)
|
|
|
|
case .script(let id):
|
2020-04-09 18:20:53 +02:00
|
|
|
hasher.combine("smartFeed")
|
2020-02-02 00:00:36 +01:00
|
|
|
hasher.combine(id)
|
|
|
|
case .webFeed(_, let webFeedID):
|
2020-04-09 18:20:53 +02:00
|
|
|
hasher.combine("webFeed")
|
2020-02-02 00:00:36 +01:00
|
|
|
hasher.combine(webFeedID)
|
|
|
|
case .folder(_, let folderName):
|
2020-04-09 18:20:53 +02:00
|
|
|
hasher.combine("folder")
|
2020-02-02 00:00:36 +01:00
|
|
|
hasher.combine(folderName)
|
|
|
|
}
|
|
|
|
}
|
2019-11-14 22:06:32 +01:00
|
|
|
}
|