diff --git a/apple/OmnivoreKit/Sources/Models/LinkedItemSort.swift b/apple/OmnivoreKit/Sources/Models/LinkedItemSort.swift index 0c5efd1fa..fc7f188c2 100644 --- a/apple/OmnivoreKit/Sources/Models/LinkedItemSort.swift +++ b/apple/OmnivoreKit/Sources/Models/LinkedItemSort.swift @@ -3,9 +3,8 @@ import Foundation public enum LinkedItemSort: String, CaseIterable { case newest case oldest - // case recentlyRead + case recentlyRead case recentlyPublished -// case relevance } public extension LinkedItemSort { @@ -15,12 +14,10 @@ public extension LinkedItemSort { return "Newest" case .oldest: return "Oldest" -// case .recentlyRead: -// return "Recently Read" + case .recentlyRead: + return "Recently Read" case .recentlyPublished: return "Recently Published" -// case .relevance: -// return "Relevance" } } @@ -30,23 +27,21 @@ public extension LinkedItemSort { return "sort:saved" case .oldest: return "sort:saved-ASC" -// case .recentlyRead: -// return "sort:updated" + case .recentlyRead: + return "sort:read" case .recentlyPublished: return "sort:published" -// case .relevance: -// return "relevance" } } var sortDescriptors: [NSSortDescriptor] { switch self { - case .newest /* , .relevance */: + case .newest: return [NSSortDescriptor(keyPath: \LinkedItem.savedAt, ascending: false)] case .oldest: return [NSSortDescriptor(keyPath: \LinkedItem.savedAt, ascending: true)] -// case .recentlyRead: -// return [NSSortDescriptor(keyPath: \LinkedItem.updatedAt, ascending: false)] + case .recentlyRead: + return [NSSortDescriptor(keyPath: \LinkedItem.updatedAt, ascending: false)] case .recentlyPublished: return [NSSortDescriptor(keyPath: \LinkedItem.publishDate, ascending: false)] } diff --git a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/UpdateArticleReadingProgress.swift b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/UpdateArticleReadingProgress.swift index 90a7bc752..07e9f273f 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/UpdateArticleReadingProgress.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/UpdateArticleReadingProgress.swift @@ -27,7 +27,7 @@ extension DataService { func syncLinkReadingProgress(itemID: String, objectID: NSManagedObjectID, readingProgress: Double, anchorIndex: Int) { enum MutationResult { - case saved(readingProgress: Double) + case saved(updatedAt: Date?) case error(errorCode: Enums.SaveArticleReadingProgressErrorCode) } @@ -36,7 +36,7 @@ extension DataService { saveArticleReadingProgressError: .init { .error(errorCode: try $0.errorCodes().first ?? .badData) }, saveArticleReadingProgressSuccess: .init { .saved( - readingProgress: try $0.updatedArticle(selection: Selection.Article { try $0.readingProgressPercent() }) + updatedAt: try $0.updatedArticle(selection: Selection.Article { try $0.updatedAt().value }) ) } ) @@ -64,6 +64,9 @@ extension DataService { context.perform { guard let linkedItem = context.object(with: objectID) as? LinkedItem else { return } linkedItem.serverSyncStatus = Int64(syncStatus.rawValue) + if let mutationResult = data?.data, case let MutationResult.saved(updatedAt) = mutationResult { + linkedItem.updatedAt = updatedAt + } do { try context.save()