2017-07-03 10:29:44 -07:00
|
|
|
|
//
|
|
|
|
|
// Account.swift
|
|
|
|
|
// DataModel
|
|
|
|
|
//
|
|
|
|
|
// Created by Brent Simmons on 7/1/17.
|
|
|
|
|
// Copyright © 2017 Ranchero Software, LLC. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
import RSCore
|
2017-09-16 15:25:38 -07:00
|
|
|
|
import Data
|
2017-09-17 12:08:50 -07:00
|
|
|
|
import RSParser
|
2017-09-17 17:03:58 -07:00
|
|
|
|
import Database
|
2017-07-03 10:29:44 -07:00
|
|
|
|
|
|
|
|
|
public enum AccountType: Int {
|
|
|
|
|
|
|
|
|
|
// Raw values should not change since they’re stored on disk.
|
|
|
|
|
case onMyMac = 1
|
|
|
|
|
case feedly = 16
|
|
|
|
|
case feedbin = 17
|
|
|
|
|
case feedWrangler = 18
|
|
|
|
|
case newsBlur = 19
|
|
|
|
|
// TODO: more
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-17 11:32:58 -07:00
|
|
|
|
public final class Account: DisplayNameProvider, Hashable {
|
2017-07-03 10:29:44 -07:00
|
|
|
|
|
2017-09-17 12:08:50 -07:00
|
|
|
|
public let accountID: String
|
2017-07-03 10:29:44 -07:00
|
|
|
|
public let type: AccountType
|
2017-09-17 12:08:50 -07:00
|
|
|
|
public var nameForDisplay = ""
|
2017-07-03 10:29:44 -07:00
|
|
|
|
public let delegate: AccountDelegate
|
|
|
|
|
public let hashValue: Int
|
|
|
|
|
let settingsFile: String
|
|
|
|
|
let dataFolder: String
|
2017-09-17 17:03:58 -07:00
|
|
|
|
let database: Database
|
2017-07-03 10:29:44 -07:00
|
|
|
|
var topLevelObjects = [AnyObject]()
|
|
|
|
|
var feedIDDictionary = [String: Feed]()
|
|
|
|
|
var username: String?
|
2017-09-17 12:20:32 -07:00
|
|
|
|
var refreshInProgress = false
|
|
|
|
|
|
2017-09-17 12:08:50 -07:00
|
|
|
|
init?(dataFolder: String, settingsFile: String, type: AccountType, accountID: String) {
|
|
|
|
|
|
2017-09-17 11:32:58 -07:00
|
|
|
|
switch type {
|
2017-09-17 17:03:58 -07:00
|
|
|
|
|
2017-09-17 12:08:50 -07:00
|
|
|
|
case .onMyMac:
|
2017-09-17 11:32:58 -07:00
|
|
|
|
self.delegate = LocalAccountDelegate()
|
|
|
|
|
default:
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2017-09-17 17:03:58 -07:00
|
|
|
|
|
|
|
|
|
self.accountID = accountID
|
|
|
|
|
self.type = type
|
|
|
|
|
self.settingsFile = settingsFile
|
|
|
|
|
self.dataFolder = dataFolder
|
|
|
|
|
self.hashValue = accountID.hashValue
|
|
|
|
|
|
|
|
|
|
let databaseFilePath = (dataFolder as NSString).appendingPathComponent("DB.sqlite3")
|
|
|
|
|
self.database = Database(databaseFilePath: databaseFilePath, accountID: accountID)
|
2017-07-03 10:29:44 -07:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-17 11:32:58 -07:00
|
|
|
|
// MARK: - API
|
|
|
|
|
|
|
|
|
|
public func refreshAll() {
|
|
|
|
|
|
|
|
|
|
delegate.refreshAll(for: self)
|
2017-07-03 10:29:44 -07:00
|
|
|
|
}
|
2017-09-16 15:30:26 -07:00
|
|
|
|
|
2017-09-17 12:08:50 -07:00
|
|
|
|
func update(_ feed: Feed, with parsedFeed: ParsedFeed, _ completion: RSVoidCompletionBlock) {
|
|
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-17 12:54:08 -07:00
|
|
|
|
public func markArticles(_ articles: Set<Article>, statusKey: String, flag: Bool) {
|
|
|
|
|
|
2017-09-17 17:03:58 -07:00
|
|
|
|
let statuses = database.statuses(for: articles)
|
|
|
|
|
if statuses.isEmpty {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
database.mark(statuses, statusKey: statusKey, flag: flag)
|
2017-09-17 12:54:08 -07:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-17 16:30:45 -07:00
|
|
|
|
public func articleStatus(for article: Article) -> ArticleStatus? {
|
|
|
|
|
|
2017-09-17 17:03:58 -07:00
|
|
|
|
return database.status(for: article)
|
2017-09-17 16:30:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-17 13:07:55 -07:00
|
|
|
|
public func ensureFolder(with name: String) -> Folder? {
|
|
|
|
|
|
|
|
|
|
return nil //TODO
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-17 11:32:58 -07:00
|
|
|
|
// MARK: - Equatable
|
2017-09-16 15:30:26 -07:00
|
|
|
|
|
2017-09-17 11:32:58 -07:00
|
|
|
|
public class func ==(lhs: Account, rhs: Account) -> Bool {
|
2017-09-16 15:30:26 -07:00
|
|
|
|
|
2017-09-17 11:32:58 -07:00
|
|
|
|
return lhs === rhs
|
2017-09-16 15:30:26 -07:00
|
|
|
|
}
|
2017-07-03 10:29:44 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extension Account: PlistProvider {
|
|
|
|
|
|
|
|
|
|
public func plist() -> AnyObject? {
|
|
|
|
|
return nil // TODO
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-16 15:25:38 -07:00
|
|
|
|
extension Account: OPMLRepresentable {
|
|
|
|
|
|
|
|
|
|
public func OPMLString(indentLevel: Int) -> String {
|
|
|
|
|
|
|
|
|
|
var s = ""
|
|
|
|
|
for oneObject in topLevelObjects {
|
|
|
|
|
if let oneOPMLObject = oneObject as? OPMLRepresentable {
|
|
|
|
|
s += oneOPMLObject.OPMLString(indentLevel: indentLevel + 1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return s
|
|
|
|
|
}
|
|
|
|
|
}
|