MOve the lastItemSyncTime into the dataservice so we can reset the instance value
This commit is contained in:
committed by
Hongbo Wu
parent
8c6798a467
commit
75a5e9fb03
@ -36,10 +36,6 @@ import Views
|
||||
|
||||
@AppStorage(UserDefaultKey.lastSelectedLinkedItemFilter.rawValue) var appliedFilter = LinkedItemFilter.inbox.rawValue
|
||||
|
||||
@AppStorage(UserDefaultKey.lastItemSyncTime.rawValue) var lastItemSyncTime = DateFormatter.formatterISO8601.string(
|
||||
from: Date(timeIntervalSinceReferenceDate: 0)
|
||||
)
|
||||
|
||||
func handleReaderItemNotification(objectID: NSManagedObjectID, dataService: DataService) {
|
||||
// Pop the current selected item if needed
|
||||
if selectedItem != nil, selectedItem?.objectID != objectID {
|
||||
@ -108,11 +104,11 @@ import Views
|
||||
}
|
||||
|
||||
func syncItems(dataService: DataService, syncStartTime: Date) async {
|
||||
let lastSyncDate = dateFormatter.date(from: lastItemSyncTime) ?? Date(timeIntervalSinceReferenceDate: 0)
|
||||
let lastSyncDate = dateFormatter.date(from: dataService.lastItemSyncTime) ?? Date(timeIntervalSinceReferenceDate: 0)
|
||||
let syncResult = try? await dataService.syncLinkedItems(since: lastSyncDate, cursor: nil)
|
||||
|
||||
if syncResult != nil {
|
||||
lastItemSyncTime = dateFormatter.string(from: syncStartTime)
|
||||
dataService.lastItemSyncTime = dateFormatter.string(from: syncStartTime)
|
||||
}
|
||||
|
||||
// If possible start prefetching new pages in the background
|
||||
|
||||
@ -4,6 +4,7 @@ import Foundation
|
||||
import Models
|
||||
import OSLog
|
||||
import QuickLookThumbnailing
|
||||
import SwiftUI
|
||||
import Utils
|
||||
|
||||
#if os(iOS)
|
||||
@ -28,6 +29,10 @@ public final class DataService: ObservableObject {
|
||||
persistentContainer.viewContext
|
||||
}
|
||||
|
||||
@AppStorage(UserDefaultKey.lastItemSyncTime.rawValue) public var lastItemSyncTime = DateFormatter.formatterISO8601.string(
|
||||
from: Date(timeIntervalSinceReferenceDate: 0)
|
||||
)
|
||||
|
||||
public init(appEnvironment: AppEnvironment, networker: Networker) {
|
||||
self.appEnvironment = appEnvironment
|
||||
self.networker = networker
|
||||
@ -96,10 +101,7 @@ public final class DataService: ObservableObject {
|
||||
}
|
||||
|
||||
public func resetCoreData() {
|
||||
UserDefaults.standard.set(
|
||||
DateFormatter.formatterISO8601.string(from: Date(timeIntervalSinceReferenceDate: 0)),
|
||||
forKey: UserDefaultKey.lastItemSyncTime.rawValue
|
||||
)
|
||||
lastItemSyncTime = DateFormatter.formatterISO8601.string(from: Date(timeIntervalSinceReferenceDate: 0))
|
||||
|
||||
clearCoreData()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user