Move LocalStatusesManager to Data.framework.
This commit is contained in:
parent
d0a4effe07
commit
2e862de338
|
@ -85,6 +85,7 @@
|
|||
844BEE971F0AB4F8004AB7CD /* UnreadCountProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UnreadCountProvider.swift; sourceTree = "<group>"; };
|
||||
844BEE9C1F0AB512004AB7CD /* RSCore.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RSCore.xcodeproj; path = ../RSCore/RSCore.xcodeproj; sourceTree = "<group>"; };
|
||||
84BB4B7C1F1177AD00858766 /* ArticleCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArticleCache.swift; sourceTree = "<group>"; };
|
||||
84BB4B801F1178E400858766 /* StatusesManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusesManager.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
|
@ -191,6 +192,7 @@
|
|||
isa = PBXGroup;
|
||||
children = (
|
||||
84BB4B7C1F1177AD00858766 /* ArticleCache.swift */,
|
||||
84BB4B801F1178E400858766 /* StatusesManager.swift */,
|
||||
);
|
||||
path = Database;
|
||||
sourceTree = "<group>";
|
||||
|
|
|
@ -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<LocalArticle>, statusKey: ArticleStatusKey, flag: Bool) {
|
||||
func markArticles(_ articles: Set<Article>, 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<LocalArticle>) {
|
||||
func attachCachedUniqueStatuses(_ articles: Set<Article>) {
|
||||
|
||||
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<LocalArticleStatus>, statusKey: ArticleStatusKey, flag: Bool) {
|
||||
func markArticleStatuses(_ statuses: Set<ArticleStatus>, 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<String>, database: FMDatabase) -> Set<LocalArticleStatus> {
|
||||
func fetchStatusesForArticleIDs(_ articleIDs: Set<String>, database: FMDatabase) -> Set<ArticleStatus> {
|
||||
|
||||
guard !articleIDs.isEmpty else {
|
||||
return Set<LocalArticleStatus>()
|
||||
return Set<ArticleStatus>()
|
||||
}
|
||||
|
||||
guard let resultSet = database.rs_selectRowsWhereKey(articleIDKey, inValues: Array(articleIDs), tableName: statusesTableName) else {
|
||||
return Set<LocalArticleStatus>()
|
||||
return Set<ArticleStatus>()
|
||||
}
|
||||
|
||||
return localArticleStatusesWithResultSet(resultSet)
|
||||
}
|
||||
|
||||
func localArticleStatusesWithResultSet(_ resultSet: FMResultSet) -> Set<LocalArticleStatus> {
|
||||
func localArticleStatusesWithResultSet(_ resultSet: FMResultSet) -> Set<ArticleStatus> {
|
||||
|
||||
var statuses = Set<LocalArticleStatus>()
|
||||
var statuses = Set<ArticleStatus>()
|
||||
|
||||
while(resultSet.next()) {
|
||||
if let oneArticleStatus = LocalArticleStatus(row: resultSet) {
|
||||
|
@ -135,7 +134,7 @@ private extension LocalStatusesManager {
|
|||
|
||||
// MARK: Saving
|
||||
|
||||
func saveStatuses(_ statuses: Set<LocalArticleStatus>) {
|
||||
func saveStatuses(_ statuses: Set<ArticleStatus>) {
|
||||
|
||||
let statusArray = statuses.map { (oneStatus) -> NSDictionary in
|
||||
return oneStatus.databaseDictionary
|
||||
|
@ -163,7 +162,7 @@ private extension LocalStatusesManager {
|
|||
func createStatusForNewArticleIDs(_ articleIDs: Set<String>) {
|
||||
|
||||
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<LocalArticleStatus>) {
|
||||
func cacheStatuses(_ statuses: Set<ArticleStatus>) {
|
||||
|
||||
statuses.forEach { (oneStatus) in
|
||||
if let _ = cachedStatuses[oneStatus.articleID] {
|
|
@ -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 = "<group>"; };
|
||||
8471A2EA1ED4D02F008F099E /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
8471A2FB1ED4D0A1008F099E /* LocalDatabase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocalDatabase.swift; sourceTree = "<group>"; };
|
||||
8471A2FD1ED4D0AD008F099E /* LocalStatusesManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocalStatusesManager.swift; sourceTree = "<group>"; };
|
||||
8471A2FF1ED4D0B8008F099E /* LocalCreateStatements.sql */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LocalCreateStatements.sql; sourceTree = "<group>"; };
|
||||
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 */,
|
||||
|
|
Loading…
Reference in New Issue