diff --git a/Frameworks/Data/Data.xcodeproj/project.pbxproj b/Frameworks/Data/Data.xcodeproj/project.pbxproj index d2f5dc8ba..233b3b586 100644 --- a/Frameworks/Data/Data.xcodeproj/project.pbxproj +++ b/Frameworks/Data/Data.xcodeproj/project.pbxproj @@ -85,6 +85,7 @@ 844BEE971F0AB4F8004AB7CD /* UnreadCountProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UnreadCountProvider.swift; sourceTree = ""; }; 844BEE9C1F0AB512004AB7CD /* RSCore.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RSCore.xcodeproj; path = ../RSCore/RSCore.xcodeproj; sourceTree = ""; }; 84BB4B7C1F1177AD00858766 /* ArticleCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArticleCache.swift; sourceTree = ""; }; + 84BB4B801F1178E400858766 /* StatusesManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusesManager.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -191,6 +192,7 @@ isa = PBXGroup; children = ( 84BB4B7C1F1177AD00858766 /* ArticleCache.swift */, + 84BB4B801F1178E400858766 /* StatusesManager.swift */, ); path = Database; sourceTree = ""; diff --git a/Frameworks/LocalAccount/LocalStatusesManager.swift b/Frameworks/Data/Database/StatusesManager.swift similarity index 81% rename from Frameworks/LocalAccount/LocalStatusesManager.swift rename to Frameworks/Data/Database/StatusesManager.swift index db6f5c790..fec2913ba 100644 --- a/Frameworks/LocalAccount/LocalStatusesManager.swift +++ b/Frameworks/Data/Database/StatusesManager.swift @@ -1,5 +1,5 @@ - // -// LocalStatusesManager.swift +// +// StatusesManager.swift // Evergreen // // Created by Brent Simmons on 5/8/16. @@ -10,11 +10,10 @@ import Foundation import RSCore import RSDatabase import RSParser -import Data -final class LocalStatusesManager { +final class StatusesManager { - var cachedStatuses = [String: LocalArticleStatus]() + var cachedStatuses = [String: ArticleStatus]() let queue: RSDatabaseQueue init(queue: RSDatabaseQueue) { @@ -22,22 +21,22 @@ final class LocalStatusesManager { self.queue = queue } - func markArticles(_ articles: Set, statusKey: ArticleStatusKey, flag: Bool) { + func markArticles(_ articles: Set
, statusKey: ArticleStatusKey, flag: Bool) { assertNoMissingStatuses(articles) - let statusArray = articles.map { $0.status! as! LocalArticleStatus } + let statusArray = articles.map { $0.status! as! ArticleStatus } let statuses = Set(statusArray) markArticleStatuses(statuses, statusKey: statusKey, flag: flag) } - func attachCachedUniqueStatuses(_ articles: Set) { + func attachCachedUniqueStatuses(_ articles: Set
) { articles.forEach { (oneLocalArticle) in if let cachedStatus = cachedStatusForArticleID(oneLocalArticle.articleID) { oneLocalArticle.status = cachedStatus } - else if let oneLocalArticleStatus = oneLocalArticle.status as? LocalArticleStatus { + else if let oneLocalArticleStatus = oneLocalArticle.status as? ArticleStatus { cacheStatus(oneLocalArticleStatus) } } @@ -82,11 +81,11 @@ final class LocalStatusesManager { private let statusesTableName = "statuses" -private extension LocalStatusesManager { +private extension StatusesManager { // MARK: Marking - func markArticleStatuses(_ statuses: Set, statusKey: ArticleStatusKey, flag: Bool) { + func markArticleStatuses(_ statuses: Set, statusKey: ArticleStatusKey, flag: Bool) { // Ignore the statuses where status.[statusKey] == flag. Update the remainder and save in database. @@ -107,22 +106,22 @@ private extension LocalStatusesManager { // MARK: Fetching - func fetchStatusesForArticleIDs(_ articleIDs: Set, database: FMDatabase) -> Set { + func fetchStatusesForArticleIDs(_ articleIDs: Set, database: FMDatabase) -> Set { guard !articleIDs.isEmpty else { - return Set() + return Set() } guard let resultSet = database.rs_selectRowsWhereKey(articleIDKey, inValues: Array(articleIDs), tableName: statusesTableName) else { - return Set() + return Set() } return localArticleStatusesWithResultSet(resultSet) } - func localArticleStatusesWithResultSet(_ resultSet: FMResultSet) -> Set { + func localArticleStatusesWithResultSet(_ resultSet: FMResultSet) -> Set { - var statuses = Set() + var statuses = Set() while(resultSet.next()) { if let oneArticleStatus = LocalArticleStatus(row: resultSet) { @@ -135,7 +134,7 @@ private extension LocalStatusesManager { // MARK: Saving - func saveStatuses(_ statuses: Set) { + func saveStatuses(_ statuses: Set) { let statusArray = statuses.map { (oneStatus) -> NSDictionary in return oneStatus.databaseDictionary @@ -163,7 +162,7 @@ private extension LocalStatusesManager { func createStatusForNewArticleIDs(_ articleIDs: Set) { let now = Date() - let statuses = articleIDs.map { (oneArticleID) -> LocalArticleStatus in + let statuses = articleIDs.map { (oneArticleID) -> ArticleStatus in return LocalArticleStatus(articleID: oneArticleID, read: false, starred: false, userDeleted: false, dateArrived: now) } cacheStatuses(Set(statuses)) @@ -181,17 +180,17 @@ private extension LocalStatusesManager { // MARK: Cache - func cachedStatusForArticleID(_ articleID: String) -> LocalArticleStatus? { + func cachedStatusForArticleID(_ articleID: String) -> ArticleStatus? { return cachedStatuses[articleID] } - func cacheStatus(_ status: LocalArticleStatus) { + func cacheStatus(_ status: ArticleStatus) { cacheStatuses(Set([status])) } - func cacheStatuses(_ statuses: Set) { + func cacheStatuses(_ statuses: Set) { statuses.forEach { (oneStatus) in if let _ = cachedStatuses[oneStatus.articleID] { diff --git a/Frameworks/LocalAccount/LocalAccount.xcodeproj/project.pbxproj b/Frameworks/LocalAccount/LocalAccount.xcodeproj/project.pbxproj index a3603d34a..458100b14 100644 --- a/Frameworks/LocalAccount/LocalAccount.xcodeproj/project.pbxproj +++ b/Frameworks/LocalAccount/LocalAccount.xcodeproj/project.pbxproj @@ -15,7 +15,6 @@ 8471A2E71ED4D012008F099E /* LocalArticleStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8471A2E61ED4D012008F099E /* LocalArticleStatus.swift */; }; 8471A2E91ED4D01B008F099E /* DiskDictionaryConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8471A2E81ED4D01B008F099E /* DiskDictionaryConstants.swift */; }; 8471A2FC1ED4D0A1008F099E /* LocalDatabase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8471A2FB1ED4D0A1008F099E /* LocalDatabase.swift */; }; - 8471A2FE1ED4D0AD008F099E /* LocalStatusesManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8471A2FD1ED4D0AD008F099E /* LocalStatusesManager.swift */; }; 8471A3001ED4D0B8008F099E /* LocalCreateStatements.sql in Resources */ = {isa = PBXBuildFile; fileRef = 8471A2FF1ED4D0B8008F099E /* LocalCreateStatements.sql */; }; 84C7AEB11D68C79A009FB883 /* LocalAccount.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84C7AEA71D68C79A009FB883 /* LocalAccount.framework */; }; 84C7AEB61D68C79A009FB883 /* LocalAccountTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C7AEB51D68C79A009FB883 /* LocalAccountTests.swift */; }; @@ -47,7 +46,6 @@ 8471A2E81ED4D01B008F099E /* DiskDictionaryConstants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DiskDictionaryConstants.swift; sourceTree = ""; }; 8471A2EA1ED4D02F008F099E /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 8471A2FB1ED4D0A1008F099E /* LocalDatabase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocalDatabase.swift; sourceTree = ""; }; - 8471A2FD1ED4D0AD008F099E /* LocalStatusesManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocalStatusesManager.swift; sourceTree = ""; }; 8471A2FF1ED4D0B8008F099E /* LocalCreateStatements.sql */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LocalCreateStatements.sql; sourceTree = ""; }; 84C7AEA71D68C79A009FB883 /* LocalAccount.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = LocalAccount.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 84C7AEB01D68C79A009FB883 /* LocalAccountTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = LocalAccountTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -90,7 +88,6 @@ isa = PBXGroup; children = ( 8471A2FB1ED4D0A1008F099E /* LocalDatabase.swift */, - 8471A2FD1ED4D0AD008F099E /* LocalStatusesManager.swift */, 8471A2FF1ED4D0B8008F099E /* LocalCreateStatements.sql */, ); name = Database; @@ -263,7 +260,6 @@ 8471A2E71ED4D012008F099E /* LocalArticleStatus.swift in Sources */, 8471A2FC1ED4D0A1008F099E /* LocalDatabase.swift in Sources */, 8471A2E31ED4CFFB008F099E /* LocalFeed.swift in Sources */, - 8471A2FE1ED4D0AD008F099E /* LocalStatusesManager.swift in Sources */, 8471A2DD1ED4CFE4008F099E /* LocalAccount.swift in Sources */, 8471A2DF1ED4CFEB008F099E /* LocalAccountRefresher.swift in Sources */, 84F4665B1F07321400225386 /* LocalAuthor.swift in Sources */,