mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-29 00:31:14 +00:00
Merge branch 'task/switch-to-logger'
This commit is contained in:
commit
c04161efff
76 files changed
+620
-590
No files matched your search
@@ -4,7 +4,8 @@
|
||||
"Bash(find:*)",
|
||||
"Bash(grep:*)",
|
||||
"Bash(ls:*)",
|
||||
"Bash(./buildscripts/quiet_build_and_test.sh:*)"
|
||||
"Bash(./buildscripts/quiet_build_and_test.sh:*)",
|
||||
"WebSearch"
|
||||
],
|
||||
"deny": []
|
||||
}
|
||||
|
||||
@@ -67,3 +67,6 @@ NetNewsWire is a multi-platform RSS reader with separate targets for macOS and i
|
||||
Prefer idiomatic modern Swift.
|
||||
|
||||
Prefer `if let x` and `guard let x` over `if let x = x` and `guard let x = x`.
|
||||
|
||||
Don’t use `...` or `…` in Logger messages.
|
||||
|
||||
+31
-36
@@ -8,6 +8,7 @@
|
||||
|
||||
import AppKit
|
||||
import UserNotifications
|
||||
import os
|
||||
import Articles
|
||||
import RSTree
|
||||
import RSWeb
|
||||
@@ -15,7 +16,6 @@ import Account
|
||||
import RSCore
|
||||
import RSCoreResources
|
||||
import Secrets
|
||||
import OSLog
|
||||
import CrashReporter
|
||||
|
||||
// If we're not going to import Sparkle, provide dummy protocols to make it easy
|
||||
@@ -30,8 +30,9 @@ import Sparkle
|
||||
var appDelegate: AppDelegate!
|
||||
|
||||
@NSApplicationMain
|
||||
final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, UNUserNotificationCenterDelegate, UnreadCountProvider, SPUStandardUserDriverDelegate, SPUUpdaterDelegate
|
||||
{
|
||||
final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, UNUserNotificationCenterDelegate, UnreadCountProvider, SPUStandardUserDriverDelegate, SPUUpdaterDelegate {
|
||||
|
||||
static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "AppDelegate")
|
||||
|
||||
private struct WindowRestorationIdentifiers {
|
||||
static let mainWindow = "mainWindow"
|
||||
@@ -184,14 +185,14 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidat
|
||||
try self.softwareUpdater.start()
|
||||
}
|
||||
catch {
|
||||
NSLog("Failed to start software updater with error: \(error)")
|
||||
Self.logger.error("Failed to start software updater with error: \(error.localizedDescription)")
|
||||
}
|
||||
#endif
|
||||
|
||||
AppDefaults.shared.registerDefaults()
|
||||
let isFirstRun = AppDefaults.shared.isFirstRun
|
||||
if isFirstRun {
|
||||
os_log(.debug, "Is first run.")
|
||||
Self.logger.debug("Is first run.")
|
||||
}
|
||||
let localAccount = AccountManager.shared.defaultAccount
|
||||
|
||||
@@ -727,7 +728,7 @@ extension AppDelegate {
|
||||
assertionFailure("Expected non-nil app support folder path")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
NSWorkspace.shared.open(URL(fileURLWithPath: appSupport))
|
||||
}
|
||||
|
||||
@@ -987,43 +988,37 @@ extension AppDelegate: NSWindowRestoration {
|
||||
// Handle Notification Actions
|
||||
|
||||
private extension AppDelegate {
|
||||
|
||||
|
||||
func handleMarkAsRead(userInfo: [AnyHashable: Any]) {
|
||||
guard let articlePathUserInfo = userInfo[UserInfoKey.articlePath] as? [AnyHashable : Any],
|
||||
let accountID = articlePathUserInfo[ArticlePathKey.accountID] as? String,
|
||||
let articleID = articlePathUserInfo[ArticlePathKey.articleID] as? String else {
|
||||
return
|
||||
}
|
||||
|
||||
let account = AccountManager.shared.existingAccount(with: accountID)
|
||||
guard account != nil else {
|
||||
os_log(.debug, "No account found from notification.")
|
||||
return
|
||||
}
|
||||
let article = try? account!.fetchArticles(.articleIDs([articleID]))
|
||||
guard article != nil else {
|
||||
os_log(.debug, "No article found from search using %@", articleID)
|
||||
return
|
||||
}
|
||||
account!.markArticles(article!, statusKey: .read, flag: true) { _ in }
|
||||
handleStatusNotification(userInfo: userInfo, statusKey: .read)
|
||||
}
|
||||
|
||||
|
||||
func handleMarkAsStarred(userInfo: [AnyHashable: Any]) {
|
||||
handleStatusNotification(userInfo: userInfo, statusKey: .starred)
|
||||
}
|
||||
|
||||
private func handleStatusNotification(userInfo: [AnyHashable: Any], statusKey: ArticleStatus.Key) {
|
||||
guard let articlePathUserInfo = userInfo[UserInfoKey.articlePath] as? [AnyHashable : Any],
|
||||
let accountID = articlePathUserInfo[ArticlePathKey.accountID] as? String,
|
||||
let articleID = articlePathUserInfo[ArticlePathKey.articleID] as? String else {
|
||||
return
|
||||
}
|
||||
let account = AccountManager.shared.existingAccount(with: accountID)
|
||||
guard account != nil else {
|
||||
os_log(.debug, "No account found from notification.")
|
||||
let accountID = articlePathUserInfo[ArticlePathKey.accountID] as? String,
|
||||
let articleID = articlePathUserInfo[ArticlePathKey.articleID] as? String else {
|
||||
assertionFailure("Expected valid articlePathUserInfo from userInfo \(userInfo)")
|
||||
Self.logger.error("No valid articlePathUserInfo from userInfo \(userInfo) in status notification")
|
||||
return
|
||||
}
|
||||
let article = try? account!.fetchArticles(.articleIDs([articleID]))
|
||||
guard article != nil else {
|
||||
os_log(.debug, "No article found from search using %@", articleID)
|
||||
|
||||
guard let account = AccountManager.shared.existingAccount(with: accountID) else {
|
||||
assertionFailure("Expected account with \(accountID)")
|
||||
Self.logger.error("No account with accountID \(accountID) found from status notification")
|
||||
return
|
||||
}
|
||||
account!.markArticles(article!, statusKey: .starred, flag: true) { _ in }
|
||||
|
||||
guard let singleArticleSet = try? account.fetchArticles(.articleIDs([articleID])) else {
|
||||
assertionFailure("Expected article with \(articleID)")
|
||||
Self.logger.error("No article with articleID found \(articleID) from status notification")
|
||||
return
|
||||
}
|
||||
|
||||
assert(singleArticleSet.count == 1)
|
||||
account.markArticles(singleArticleSet, statusKey: statusKey, flag: true) { _ in }
|
||||
}
|
||||
}
|
||||
@@ -12,14 +12,13 @@ import os.log
|
||||
|
||||
struct ErrorHandler {
|
||||
|
||||
private static var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "Account")
|
||||
|
||||
private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "ErrorHandler")
|
||||
|
||||
public static func present(_ error: Error) {
|
||||
NSApplication.shared.presentError(error)
|
||||
}
|
||||
|
||||
|
||||
public static func log(_ error: Error) {
|
||||
os_log(.error, log: self.log, "%@", error.localizedDescription)
|
||||
logger.error("\(error.localizedDescription)")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -300,18 +300,30 @@ final class MainWindowController : NSWindowController, NSUserInterfaceValidation
|
||||
}
|
||||
|
||||
@IBAction func copyArticleURL(_ sender: Any?) {
|
||||
guard let links = selectedArticles?.compactMap{ $0.preferredLink }, !links.isEmpty else {
|
||||
guard let articles = selectedArticles else {
|
||||
assertionFailure("Expected selectedArticles to be non-nil")
|
||||
return
|
||||
}
|
||||
let links = articles.compactMap { $0.preferredLink }
|
||||
if links.isEmpty {
|
||||
assertionFailure("Expected at least one link")
|
||||
return
|
||||
}
|
||||
|
||||
URLPasteboardWriter.write(urlStrings: links, to: .general)
|
||||
}
|
||||
|
||||
@IBAction func copyExternalURL(_ sender: Any?) {
|
||||
guard let links = selectedArticles?.compactMap{ $0.externalLink }, !links.isEmpty else {
|
||||
assertionFailure("Expected at least one external link")
|
||||
guard let articles = selectedArticles else {
|
||||
assertionFailure("Expected selectedArticles to be non-nil")
|
||||
return
|
||||
}
|
||||
let links = articles.compactMap { $0.externalLink }
|
||||
if links.isEmpty {
|
||||
assertionFailure("Expected at least one link")
|
||||
return
|
||||
}
|
||||
|
||||
URLPasteboardWriter.write(urlStrings: links, to: .general)
|
||||
}
|
||||
|
||||
|
||||
@@ -210,6 +210,8 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
private let keyboardDelegate = TimelineKeyboardDelegate()
|
||||
private var timelineShowsSeparatorsObserver: NSKeyValueObservation?
|
||||
|
||||
private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "TimelineViewController")
|
||||
|
||||
convenience init(delegate: TimelineDelegate) {
|
||||
self.init(nibName: "TimelineTableView", bundle: nil)
|
||||
self.delegate = delegate
|
||||
@@ -980,7 +982,7 @@ extension TimelineViewController: NSTableViewDelegate {
|
||||
return [action]
|
||||
|
||||
@unknown default:
|
||||
os_log(.error, "Unknown table row edge: %ld", edge.rawValue)
|
||||
Self.logger.error("TimelineViewController: unknown edge \(edge.rawValue, privacy: .public)")
|
||||
}
|
||||
|
||||
return []
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
import os.log
|
||||
import UniformTypeIdentifiers
|
||||
|
||||
final class ShareViewController: NSViewController {
|
||||
@@ -17,7 +16,6 @@ final class ShareViewController: NSViewController {
|
||||
|
||||
private var url: URL?
|
||||
private var extensionContainers: ExtensionContainers?
|
||||
private var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "ShareViewController")
|
||||
|
||||
override var nibName: NSNib.Name? {
|
||||
return NSNib.Name("ShareViewController")
|
||||
|
||||
@@ -17,7 +17,6 @@ import RSParser
|
||||
import RSDatabase
|
||||
import ArticlesDatabase
|
||||
import RSWeb
|
||||
import os.log
|
||||
import Secrets
|
||||
|
||||
// Main thread only.
|
||||
@@ -78,8 +77,6 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
}
|
||||
|
||||
public static let defaultLocalAccountName = NSLocalizedString("account.name.on-my-device", tableName: "DefaultAccountNames", comment: "Device specific default account name, e.g: On My iPhone")
|
||||
|
||||
var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "account")
|
||||
|
||||
public var isDeleted = false
|
||||
|
||||
|
||||
@@ -11,9 +11,6 @@ import os.log
|
||||
import RSCore
|
||||
|
||||
final class AccountMetadataFile {
|
||||
|
||||
private var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "accountMetadataFile")
|
||||
|
||||
private let fileURL: URL
|
||||
private let account: Account
|
||||
|
||||
@@ -23,6 +20,7 @@ final class AccountMetadataFile {
|
||||
}
|
||||
}
|
||||
private let saveQueue = CoalescingQueue(name: "Save Queue", interval: 0.5)
|
||||
private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "AccountMetadataFile")
|
||||
|
||||
init(filename: String, account: Account) {
|
||||
self.fileURL = URL(fileURLWithPath: filename)
|
||||
@@ -51,7 +49,7 @@ final class AccountMetadataFile {
|
||||
let data = try encoder.encode(account.metadata)
|
||||
try data.write(to: fileURL)
|
||||
} catch let error as NSError {
|
||||
os_log(.error, log: log, "Save to disk failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("AccountMetadataFile accountID: \(self.account.accountID) save to disk failed: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,5 +67,4 @@ private extension AccountMetadataFile {
|
||||
save()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,7 +29,7 @@ enum CloudKitAccountDelegateError: LocalizedError {
|
||||
|
||||
final class CloudKitAccountDelegate: AccountDelegate {
|
||||
|
||||
private var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "CloudKit")
|
||||
private static let logger = cloudKitLogger
|
||||
|
||||
private let database: SyncDatabase
|
||||
|
||||
@@ -322,7 +322,7 @@ final class CloudKitAccountDelegate: AccountDelegate {
|
||||
self.removeWebFeedFromCloud(for: account, with: webFeed, from: folder) { result in
|
||||
group.leave()
|
||||
if case .failure(let error) = result {
|
||||
os_log(.error, log: self.log, "Remove folder, remove webfeed error: %@.", error.localizedDescription)
|
||||
Self.logger.error("CloudKit: Remove folder, remove webfeed error: \(error.localizedDescription)")
|
||||
errorOccurred = true
|
||||
}
|
||||
}
|
||||
@@ -388,7 +388,7 @@ final class CloudKitAccountDelegate: AccountDelegate {
|
||||
case .success:
|
||||
break
|
||||
case .failure(let error):
|
||||
os_log(.error, log: self.log, "Restore folder feed error: %@.", error.localizedDescription)
|
||||
Self.logger.error("CloudKit: Restore folder feed error: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -444,7 +444,7 @@ final class CloudKitAccountDelegate: AccountDelegate {
|
||||
account.externalID = externalID
|
||||
self.initialRefreshAll(for: account) { _ in }
|
||||
case .failure(let error):
|
||||
os_log(.error, log: self.log, "Error adding account container: %@", error.localizedDescription)
|
||||
Self.logger.error("CloudKit: Error adding account container: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
accountZone.subscribeToZoneChanges()
|
||||
@@ -706,12 +706,12 @@ private extension CloudKitAccountDelegate {
|
||||
case .success:
|
||||
self.articlesZone.fetchChangesInZone() { _ in }
|
||||
case .failure(let error):
|
||||
os_log(.error, log: self.log, "CloudKit Feed send articles error: %@.", error.localizedDescription)
|
||||
Self.logger.error("CloudKit: Feed send articles error: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
}
|
||||
case .failure(let error):
|
||||
os_log(.error, log: self.log, "CloudKit Feed send articles error: %@.", error.localizedDescription)
|
||||
Self.logger.error("CloudKit: Feed send articles error: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,8 +22,6 @@ enum CloudKitAccountZoneError: LocalizedError {
|
||||
final class CloudKitAccountZone: CloudKitZone {
|
||||
|
||||
var zoneID: CKRecordZone.ID
|
||||
|
||||
var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "CloudKit")
|
||||
|
||||
weak var container: CKContainer?
|
||||
weak var database: CKDatabase?
|
||||
|
||||
@@ -19,8 +19,6 @@ final class CloudKitAcountZoneDelegate: CloudKitZoneDelegate {
|
||||
private var newUnclaimedWebFeeds = [String: [UnclaimedWebFeed]]()
|
||||
private var existingUnclaimedWebFeeds = [String: [WebFeed]]()
|
||||
|
||||
private var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "CloudKit")
|
||||
|
||||
weak var account: Account?
|
||||
weak var articlesZone: CloudKitArticlesZone?
|
||||
|
||||
|
||||
@@ -19,8 +19,6 @@ final class CloudKitArticlesZone: CloudKitZone {
|
||||
|
||||
var zoneID: CKRecordZone.ID
|
||||
|
||||
var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "CloudKit")
|
||||
|
||||
weak var container: CKContainer?
|
||||
weak var database: CKDatabase?
|
||||
var delegate: CloudKitZoneDelegate? = nil
|
||||
|
||||
@@ -18,8 +18,8 @@ import ArticlesDatabase
|
||||
|
||||
final class CloudKitArticlesZoneDelegate: CloudKitZoneDelegate {
|
||||
|
||||
private var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "CloudKit")
|
||||
|
||||
private static let logger = cloudKitLogger
|
||||
|
||||
weak var account: Account?
|
||||
var database: SyncDatabase
|
||||
weak var articlesZone: CloudKitArticlesZone?
|
||||
@@ -49,19 +49,16 @@ final class CloudKitArticlesZoneDelegate: CloudKitZoneDelegate {
|
||||
}
|
||||
|
||||
case .failure(let error):
|
||||
os_log(.error, log: self.log, "Error occurred getting pending starred records: %@", error.localizedDescription)
|
||||
Self.logger.error("CloudKit: Error getting pending starred records: \(error.localizedDescription)")
|
||||
completion(.failure(CloudKitZoneError.unknown))
|
||||
}
|
||||
}
|
||||
case .failure(let error):
|
||||
os_log(.error, log: self.log, "Error occurred getting pending read status records: %@", error.localizedDescription)
|
||||
Self.logger.error("CloudKit: Error getting pending read status records: \(error.localizedDescription)")
|
||||
completion(.failure(CloudKitZoneError.unknown))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private extension CloudKitArticlesZoneDelegate {
|
||||
@@ -102,7 +99,7 @@ private extension CloudKitArticlesZoneDelegate {
|
||||
account?.markAsUnread(updateableUnreadArticleIDs) { result in
|
||||
if case .failure(let databaseError) = result {
|
||||
errorOccurred = true
|
||||
os_log(.error, log: self.log, "Error occurred while storing unread statuses: %@", databaseError.localizedDescription)
|
||||
Self.logger.error("CloudKit: Error while storing unread statuses: \(databaseError.localizedDescription)")
|
||||
}
|
||||
group.leave()
|
||||
}
|
||||
@@ -111,7 +108,7 @@ private extension CloudKitArticlesZoneDelegate {
|
||||
account?.markAsRead(updateableReadArticleIDs) { result in
|
||||
if case .failure(let databaseError) = result {
|
||||
errorOccurred = true
|
||||
os_log(.error, log: self.log, "Error occurred while storing read statuses: %@", databaseError.localizedDescription)
|
||||
Self.logger.error("CloudKit: Error while storing read statuses: \(databaseError.localizedDescription)")
|
||||
}
|
||||
group.leave()
|
||||
}
|
||||
@@ -120,7 +117,7 @@ private extension CloudKitArticlesZoneDelegate {
|
||||
account?.markAsUnstarred(updateableUnstarredArticleIDs) { result in
|
||||
if case .failure(let databaseError) = result {
|
||||
errorOccurred = true
|
||||
os_log(.error, log: self.log, "Error occurred while storing unstarred statuses: %@", databaseError.localizedDescription)
|
||||
Self.logger.error("CloudKit: Error while storing unstarred statuses: \(databaseError.localizedDescription)")
|
||||
}
|
||||
group.leave()
|
||||
}
|
||||
@@ -129,7 +126,7 @@ private extension CloudKitArticlesZoneDelegate {
|
||||
account?.markAsStarred(updateableStarredArticleIDs) { result in
|
||||
if case .failure(let databaseError) = result {
|
||||
errorOccurred = true
|
||||
os_log(.error, log: self.log, "Error occurred while storing starred statuses: %@", databaseError.localizedDescription)
|
||||
Self.logger.error("CloudKit: Error while storing starred statuses: \(databaseError.localizedDescription)")
|
||||
}
|
||||
group.leave()
|
||||
}
|
||||
@@ -155,7 +152,7 @@ private extension CloudKitArticlesZoneDelegate {
|
||||
}
|
||||
case .failure(let databaseError):
|
||||
errorOccurred = true
|
||||
os_log(.error, log: self.log, "Error occurred while storing articles: %@", databaseError.localizedDescription)
|
||||
Self.logger.error("CloudKit: Error while storing starred articles: \(databaseError.localizedDescription)")
|
||||
group.leave()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,6 @@ import os.log
|
||||
import RSCore
|
||||
|
||||
final class CloudKitReceiveStatusOperation: MainThreadOperation {
|
||||
|
||||
static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "CloudKitReceiveStatusOperation")
|
||||
|
||||
// MainThreadOperation
|
||||
public var isCanceled = false
|
||||
public var id: Int?
|
||||
@@ -22,6 +19,7 @@ final class CloudKitReceiveStatusOperation: MainThreadOperation {
|
||||
public var completionBlock: MainThreadOperation.MainThreadOperationCompletionBlock?
|
||||
|
||||
private weak var articlesZone: CloudKitArticlesZone?
|
||||
private static let logger = cloudKitLogger
|
||||
|
||||
init(articlesZone: CloudKitArticlesZone) {
|
||||
self.articlesZone = articlesZone
|
||||
|
||||
@@ -12,9 +12,6 @@ import os.log
|
||||
import RSCore
|
||||
|
||||
final class CloudKitRemoteNotificationOperation: MainThreadOperation {
|
||||
|
||||
private var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "CloudKit")
|
||||
|
||||
// MainThreadOperation
|
||||
public var isCanceled = false
|
||||
public var id: Int?
|
||||
@@ -25,7 +22,8 @@ final class CloudKitRemoteNotificationOperation: MainThreadOperation {
|
||||
private weak var accountZone: CloudKitAccountZone?
|
||||
private weak var articlesZone: CloudKitArticlesZone?
|
||||
private var userInfo: [AnyHashable : Any]
|
||||
|
||||
private static let logger = cloudKitLogger
|
||||
|
||||
init(accountZone: CloudKitAccountZone, articlesZone: CloudKitArticlesZone, userInfo: [AnyHashable : Any]) {
|
||||
self.accountZone = accountZone
|
||||
self.articlesZone = articlesZone
|
||||
@@ -37,16 +35,14 @@ final class CloudKitRemoteNotificationOperation: MainThreadOperation {
|
||||
self.operationDelegate?.operationDidComplete(self)
|
||||
return
|
||||
}
|
||||
|
||||
os_log(.debug, log: log, "Processing remote notification...")
|
||||
|
||||
|
||||
Self.logger.debug("iCloud: Processing remote notification")
|
||||
|
||||
accountZone.receiveRemoteNotification(userInfo: userInfo) {
|
||||
articlesZone.receiveRemoteNotification(userInfo: self.userInfo) {
|
||||
os_log(.debug, log: self.log, "Done processing remote notification.")
|
||||
Self.logger.debug("iCloud: Finished processing remote notification")
|
||||
self.operationDelegate?.operationDidComplete(self)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,9 +14,6 @@ import RSWeb
|
||||
import SyncDatabase
|
||||
|
||||
final class CloudKitSendStatusOperation: MainThreadOperation {
|
||||
|
||||
static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "CloudKitSendStatusOperation")
|
||||
|
||||
private let blockSize = 150
|
||||
|
||||
// MainThreadOperation
|
||||
@@ -31,6 +28,7 @@ final class CloudKitSendStatusOperation: MainThreadOperation {
|
||||
private weak var refreshProgress: DownloadProgress?
|
||||
private var showProgress: Bool
|
||||
private var database: SyncDatabase
|
||||
private static let logger = cloudKitLogger
|
||||
|
||||
init(account: Account, articlesZone: CloudKitArticlesZone, refreshProgress: DownloadProgress, showProgress: Bool, database: SyncDatabase) {
|
||||
self.account = account
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// File.swift
|
||||
// Account
|
||||
//
|
||||
// Created by Brent Simmons on 10/2/25.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import os.log
|
||||
|
||||
struct Feedbin {
|
||||
|
||||
// Convention with this logger is to put "Feedbin: " at the beginning of each message.
|
||||
static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "Feedbin")
|
||||
}
|
||||
@@ -25,8 +25,8 @@ final class FeedbinAccountDelegate: AccountDelegate {
|
||||
private let database: SyncDatabase
|
||||
|
||||
private let caller: FeedbinAPICaller
|
||||
private var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "Feedbin")
|
||||
|
||||
private static let logger = Feedbin.logger
|
||||
|
||||
let behaviors: AccountBehaviors = [.disallowFeedCopyInRootFolder]
|
||||
let server: String? = "api.feedbin.com"
|
||||
var isOPMLImportInProgress = false
|
||||
@@ -133,7 +133,7 @@ final class FeedbinAccountDelegate: AccountDelegate {
|
||||
|
||||
func sendArticleStatus(for account: Account, completion: @escaping ((Result<Void, Error>) -> Void)) {
|
||||
|
||||
os_log(.debug, log: log, "Sending article statuses...")
|
||||
Self.logger.info("Feedbin: Sending article statuses")
|
||||
|
||||
database.selectForProcessing { result in
|
||||
|
||||
@@ -179,7 +179,7 @@ final class FeedbinAccountDelegate: AccountDelegate {
|
||||
}
|
||||
|
||||
group.notify(queue: DispatchQueue.main) {
|
||||
os_log(.debug, log: self.log, "Done sending article statuses.")
|
||||
Self.logger.info("Feedbin: Finished sending article statuses")
|
||||
if errorOccurred {
|
||||
completion(.failure(FeedbinAccountDelegateError.unknown))
|
||||
} else {
|
||||
@@ -199,8 +199,8 @@ final class FeedbinAccountDelegate: AccountDelegate {
|
||||
|
||||
func refreshArticleStatus(for account: Account, completion: @escaping ((Result<Void, Error>) -> Void)) {
|
||||
|
||||
os_log(.debug, log: log, "Refreshing article statuses...")
|
||||
|
||||
Self.logger.info("Feedbin: Refreshing article statuses")
|
||||
|
||||
let group = DispatchGroup()
|
||||
var errorOccurred = false
|
||||
|
||||
@@ -213,7 +213,7 @@ final class FeedbinAccountDelegate: AccountDelegate {
|
||||
}
|
||||
case .failure(let error):
|
||||
errorOccurred = true
|
||||
os_log(.info, log: self.log, "Retrieving unread entries failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("Feedbin: Retrieving unread entries failed: \(error.localizedDescription)")
|
||||
group.leave()
|
||||
}
|
||||
|
||||
@@ -228,14 +228,14 @@ final class FeedbinAccountDelegate: AccountDelegate {
|
||||
}
|
||||
case .failure(let error):
|
||||
errorOccurred = true
|
||||
os_log(.info, log: self.log, "Retrieving starred entries failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("Feedbin: Retrieving starred entries failed: \(error.localizedDescription)")
|
||||
group.leave()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
group.notify(queue: DispatchQueue.main) {
|
||||
os_log(.debug, log: self.log, "Done refreshing article statuses.")
|
||||
Self.logger.info("Feedbin: Finished refreshing article statuses")
|
||||
if errorOccurred {
|
||||
completion(.failure(FeedbinAccountDelegateError.unknown))
|
||||
} else {
|
||||
@@ -261,7 +261,7 @@ final class FeedbinAccountDelegate: AccountDelegate {
|
||||
return
|
||||
}
|
||||
|
||||
os_log(.debug, log: log, "Begin importing OPML...")
|
||||
Self.logger.info("Feedbin: Did begin importing OPML")
|
||||
isOPMLImportInProgress = true
|
||||
refreshProgress.addToNumberOfTasksAndRemaining(1)
|
||||
|
||||
@@ -269,7 +269,7 @@ final class FeedbinAccountDelegate: AccountDelegate {
|
||||
switch result {
|
||||
case .success(let importResult):
|
||||
if importResult.complete {
|
||||
os_log(.debug, log: self.log, "Import OPML done.")
|
||||
Self.logger.info("Feedbin: Finished importing OPML")
|
||||
self.refreshProgress.completeTask()
|
||||
self.isOPMLImportInProgress = false
|
||||
DispatchQueue.main.async {
|
||||
@@ -279,7 +279,7 @@ final class FeedbinAccountDelegate: AccountDelegate {
|
||||
self.checkImportResult(opmlImportResultID: importResult.importResultID, completion: completion)
|
||||
}
|
||||
case .failure(let error):
|
||||
os_log(.debug, log: self.log, "Import OPML failed.")
|
||||
Self.logger.info("Feedbin: OPML import failed: \(error.localizedDescription)")
|
||||
self.refreshProgress.completeTask()
|
||||
self.isOPMLImportInProgress = false
|
||||
DispatchQueue.main.async {
|
||||
@@ -353,7 +353,7 @@ final class FeedbinAccountDelegate: AccountDelegate {
|
||||
self.clearFolderRelationship(for: feed, withFolderName: folder.name ?? "")
|
||||
}
|
||||
case .failure(let error):
|
||||
os_log(.error, log: self.log, "Remove feed error: %@.", error.localizedDescription)
|
||||
Self.logger.error("Feedbin: Remove feed error: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -372,7 +372,7 @@ final class FeedbinAccountDelegate: AccountDelegate {
|
||||
account.clearWebFeedMetadata(feed)
|
||||
}
|
||||
case .failure(let error):
|
||||
os_log(.error, log: self.log, "Remove feed error: %@.", error.localizedDescription)
|
||||
Self.logger.error("Feedbin: Remove feed error: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -542,7 +542,7 @@ final class FeedbinAccountDelegate: AccountDelegate {
|
||||
case .success:
|
||||
break
|
||||
case .failure(let error):
|
||||
os_log(.error, log: self.log, "Restore folder feed error: %@.", error.localizedDescription)
|
||||
Self.logger.error("Feedbin: Restore folder feed error: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -624,14 +624,14 @@ private extension FeedbinAccountDelegate {
|
||||
DispatchQueue.main.async {
|
||||
|
||||
Timer.scheduledTimer(withTimeInterval: 15, repeats: true) { timer in
|
||||
|
||||
os_log(.debug, log: self.log, "Checking status of OPML import...")
|
||||
|
||||
|
||||
Self.logger.info("Feedbin: Checking status of OPML import")
|
||||
|
||||
self.caller.retrieveOPMLImportResult(importID: opmlImportResultID) { result in
|
||||
switch result {
|
||||
case .success(let importResult):
|
||||
if let result = importResult, result.complete {
|
||||
os_log(.debug, log: self.log, "Checking status of OPML import successfully completed.")
|
||||
Self.logger.info("Feedbin: Checking status of OPML import finished successfully")
|
||||
timer.invalidate()
|
||||
self.refreshProgress.completeTask()
|
||||
self.isOPMLImportInProgress = false
|
||||
@@ -640,7 +640,7 @@ private extension FeedbinAccountDelegate {
|
||||
}
|
||||
}
|
||||
case .failure(let error):
|
||||
os_log(.debug, log: self.log, "Import OPML check failed.")
|
||||
Self.logger.info("Feedbin: Import OPML check failed: \(error.localizedDescription)")
|
||||
timer.invalidate()
|
||||
self.refreshProgress.completeTask()
|
||||
self.isOPMLImportInProgress = false
|
||||
@@ -773,7 +773,7 @@ private extension FeedbinAccountDelegate {
|
||||
guard let tags = tags else { return }
|
||||
assert(Thread.isMainThread)
|
||||
|
||||
os_log(.debug, log: log, "Syncing folders with %ld tags.", tags.count)
|
||||
Self.logger.info("Feedbin: Syncing folders \(tags.count) tags")
|
||||
|
||||
let tagNames = tags.map { $0.name }
|
||||
|
||||
@@ -812,8 +812,8 @@ private extension FeedbinAccountDelegate {
|
||||
guard let subscriptions = subscriptions else { return }
|
||||
assert(Thread.isMainThread)
|
||||
|
||||
os_log(.debug, log: log, "Syncing feeds with %ld subscriptions.", subscriptions.count)
|
||||
|
||||
Self.logger.info("Feedbin: Syncing feeds with \(subscriptions.count) subscriptions")
|
||||
|
||||
let subFeedIds = subscriptions.map { String($0.feedID) }
|
||||
|
||||
// Remove any feeds that are no longer in the subscriptions
|
||||
@@ -866,8 +866,8 @@ private extension FeedbinAccountDelegate {
|
||||
guard let taggings = taggings else { return }
|
||||
assert(Thread.isMainThread)
|
||||
|
||||
os_log(.debug, log: log, "Syncing taggings with %ld taggings.", taggings.count)
|
||||
|
||||
Self.logger.info("Feedbin: Syncing taggings with \(taggings.count) taggings")
|
||||
|
||||
// Set up some structures to make syncing easier
|
||||
let folderDict = nameToFolderDictionary(with: account.folders)
|
||||
let taggingsDict = taggings.reduce([String: [FeedbinTagging]]()) { (dict, tagging) in
|
||||
@@ -962,7 +962,8 @@ private extension FeedbinAccountDelegate {
|
||||
group.leave()
|
||||
case .failure(let error):
|
||||
errorOccurred = true
|
||||
os_log(.error, log: self.log, "Article status sync call failed: %@.", error.localizedDescription)
|
||||
|
||||
Self.logger.error("Feedbin: Article status sync call failed: \(error.localizedDescription)")
|
||||
self.database.resetSelectedForProcessing(articleIDGroup.map { String($0) } )
|
||||
group.leave()
|
||||
}
|
||||
@@ -1123,8 +1124,8 @@ private extension FeedbinAccountDelegate {
|
||||
|
||||
func refreshArticles(_ account: Account, completion: @escaping VoidResultCompletionBlock) {
|
||||
|
||||
os_log(.debug, log: log, "Refreshing articles...")
|
||||
|
||||
Self.logger.info("Feedbin: Refreshing articles")
|
||||
|
||||
caller.retrieveEntries() { result in
|
||||
|
||||
switch result {
|
||||
@@ -1144,7 +1145,7 @@ private extension FeedbinAccountDelegate {
|
||||
}
|
||||
|
||||
self.refreshArticles(account, page: page, updateFetchDate: updateFetchDate) { result in
|
||||
os_log(.debug, log: self.log, "Done refreshing articles.")
|
||||
Self.logger.info("Feedbin: Finished refreshing articles")
|
||||
switch result {
|
||||
case .success:
|
||||
completion(.success(()))
|
||||
@@ -1161,7 +1162,7 @@ private extension FeedbinAccountDelegate {
|
||||
}
|
||||
|
||||
func refreshMissingArticles(_ account: Account, completion: @escaping ((Result<Void, Error>) -> Void)) {
|
||||
os_log(.debug, log: log, "Refreshing missing articles...")
|
||||
Self.logger.info("Feedbin: Refreshing missing articles")
|
||||
|
||||
account.fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDate { result in
|
||||
|
||||
@@ -1188,7 +1189,7 @@ private extension FeedbinAccountDelegate {
|
||||
|
||||
case .failure(let error):
|
||||
errorOccurred = true
|
||||
os_log(.error, log: self.log, "Refresh missing articles failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("Feedbin: Refresh missing articles failed: \(error.localizedDescription)")
|
||||
group.leave()
|
||||
}
|
||||
}
|
||||
@@ -1196,7 +1197,7 @@ private extension FeedbinAccountDelegate {
|
||||
|
||||
group.notify(queue: DispatchQueue.main) {
|
||||
self.refreshProgress.completeTask()
|
||||
os_log(.debug, log: self.log, "Done refreshing missing articles.")
|
||||
Self.logger.info("Feedbin: Finished refreshing missing articles")
|
||||
if errorOccurred {
|
||||
completion(.failure(FeedbinAccountDelegateError.unknown))
|
||||
} else {
|
||||
@@ -1313,11 +1314,9 @@ private extension FeedbinAccountDelegate {
|
||||
case .success(let pendingArticleIDs):
|
||||
process(pendingArticleIDs)
|
||||
case .failure(let error):
|
||||
os_log(.error, log: self.log, "Sync Article Read Status failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("Feedbin: Sync Article Read Status failed: \(error.localizedDescription)")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func syncArticleStarredState(account: Account, articleIDs: [Int]?, completion: @escaping (() -> Void)) {
|
||||
@@ -1365,11 +1364,9 @@ private extension FeedbinAccountDelegate {
|
||||
case .success(let pendingArticleIDs):
|
||||
process(pendingArticleIDs)
|
||||
case .failure(let error):
|
||||
os_log(.error, log: self.log, "Sync Article Starred Status failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("Feedbin: Sync Article Starred Status failed: \(error.localizedDescription)")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func deleteTagging(for account: Account, with feed: WebFeed, from container: Container?, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
@@ -1430,11 +1427,9 @@ private extension FeedbinAccountDelegate {
|
||||
case .success:
|
||||
complete()
|
||||
case .failure(let error):
|
||||
os_log(.error, log: self.log, "Unable to remove feed from Feedbin. Removing locally and continuing processing: \(error.localizedDescription, privacy: .public)")
|
||||
Self.logger.error("Feedbin: Unable to remove feed from Feedbin. Removing locally and continuing processing: \(error.localizedDescription)")
|
||||
complete()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// Feedly.swift
|
||||
// Account
|
||||
//
|
||||
// Created by Brent Simmons on 10/2/25.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import os.log
|
||||
|
||||
struct Feedly {
|
||||
|
||||
// Convention with this logger is to put "Feedly: " at the beginning of each message.
|
||||
static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "Feedly")
|
||||
}
|
||||
@@ -60,8 +60,8 @@ final class FeedlyAccountDelegate: AccountDelegate {
|
||||
private weak var initializedAccount: Account?
|
||||
|
||||
internal let caller: FeedlyAPICaller
|
||||
|
||||
private let log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "Feedly")
|
||||
|
||||
private static let logger = Feedly.logger
|
||||
private let database: SyncDatabase
|
||||
|
||||
private weak var currentSyncAllOperation: MainThreadOperation?
|
||||
@@ -112,22 +112,20 @@ final class FeedlyAccountDelegate: AccountDelegate {
|
||||
assert(Thread.isMainThread)
|
||||
|
||||
guard currentSyncAllOperation == nil else {
|
||||
os_log(.debug, log: log, "Ignoring refreshAll: Feedly sync already in progress.")
|
||||
Self.logger.debug("Feedly: Ignoring refreshAll: sync already in progress")
|
||||
completion(.success(()))
|
||||
return
|
||||
}
|
||||
|
||||
guard let credentials = credentials else {
|
||||
os_log(.debug, log: log, "Ignoring refreshAll: Feedly account has no credentials.")
|
||||
Self.logger.info("Feedly: Ignoring refreshAll: account has no credentials")
|
||||
completion(.failure(FeedlyAccountDelegateError.notLoggedIn))
|
||||
return
|
||||
}
|
||||
|
||||
refreshProgress.reset()
|
||||
|
||||
let log = self.log
|
||||
|
||||
let syncAllOperation = FeedlySyncAllOperation(account: account, feedlyUserId: credentials.username, caller: caller, database: database, lastSuccessfulFetchStartDate: accountMetadata?.lastArticleFetchStartTime, downloadProgress: refreshProgress, log: log)
|
||||
let syncAllOperation = FeedlySyncAllOperation(account: account, feedlyUserId: credentials.username, caller: caller, database: database, lastSuccessfulFetchStartDate: accountMetadata?.lastArticleFetchStartTime, downloadProgress: refreshProgress)
|
||||
|
||||
syncAllOperation.downloadProgress = refreshProgress
|
||||
|
||||
@@ -137,8 +135,8 @@ final class FeedlyAccountDelegate: AccountDelegate {
|
||||
self?.accountMetadata?.lastArticleFetchStartTime = date
|
||||
self?.accountMetadata?.lastArticleFetchEndTime = Date()
|
||||
}
|
||||
|
||||
os_log(.debug, log: log, "Sync took %{public}.3f seconds", -date.timeIntervalSinceNow)
|
||||
|
||||
Self.logger.debug("Feedly: Sync took \(-date.timeIntervalSinceNow, privacy: .public) seconds")
|
||||
completion(result)
|
||||
self?.refreshProgress.reset()
|
||||
}
|
||||
@@ -168,7 +166,7 @@ final class FeedlyAccountDelegate: AccountDelegate {
|
||||
|
||||
func sendArticleStatus(for account: Account, completion: @escaping ((Result<Void, Error>) -> Void)) {
|
||||
// Ensure remote articles have the same status as they do locally.
|
||||
let send = FeedlySendArticleStatusesOperation(database: database, service: caller, log: log)
|
||||
let send = FeedlySendArticleStatusesOperation(database: database, service: caller)
|
||||
send.completionBlock = { operation in
|
||||
// TODO: not call with success if operation was canceled? Not sure.
|
||||
DispatchQueue.main.async {
|
||||
@@ -191,7 +189,7 @@ final class FeedlyAccountDelegate: AccountDelegate {
|
||||
|
||||
let group = DispatchGroup()
|
||||
|
||||
let ingestUnread = FeedlyIngestUnreadArticleIdsOperation(account: account, userId: credentials.username, service: caller, database: database, newerThan: nil, log: log)
|
||||
let ingestUnread = FeedlyIngestUnreadArticleIdsOperation(account: account, userId: credentials.username, service: caller, database: database, newerThan: nil)
|
||||
|
||||
group.enter()
|
||||
ingestUnread.completionBlock = { _ in
|
||||
@@ -199,7 +197,7 @@ final class FeedlyAccountDelegate: AccountDelegate {
|
||||
|
||||
}
|
||||
|
||||
let ingestStarred = FeedlyIngestStarredArticleIdsOperation(account: account, userId: credentials.username, service: caller, database: database, newerThan: nil, log: log)
|
||||
let ingestStarred = FeedlyIngestStarredArticleIdsOperation(account: account, userId: credentials.username, service: caller, database: database, newerThan: nil)
|
||||
|
||||
group.enter()
|
||||
ingestStarred.completionBlock = { _ in
|
||||
@@ -222,22 +220,22 @@ final class FeedlyAccountDelegate: AccountDelegate {
|
||||
completion(.failure(error))
|
||||
return
|
||||
}
|
||||
|
||||
os_log(.debug, log: log, "Begin importing OPML...")
|
||||
|
||||
Self.logger.info("Feedly: Begin importing OPML")
|
||||
isOPMLImportInProgress = true
|
||||
refreshProgress.addToNumberOfTasksAndRemaining(1)
|
||||
|
||||
caller.importOpml(data) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
os_log(.debug, log: self.log, "Import OPML done.")
|
||||
Self.logger.info("Feedly: OPML import finished")
|
||||
self.refreshProgress.completeTask()
|
||||
self.isOPMLImportInProgress = false
|
||||
DispatchQueue.main.async {
|
||||
completion(.success(()))
|
||||
}
|
||||
case .failure(let error):
|
||||
os_log(.debug, log: self.log, "Import OPML failed.")
|
||||
Self.logger.error("Feedly: OPML import failed: \(error.localizedDescription)")
|
||||
self.refreshProgress.completeTask()
|
||||
self.isOPMLImportInProgress = false
|
||||
DispatchQueue.main.async {
|
||||
@@ -334,9 +332,8 @@ final class FeedlyAccountDelegate: AccountDelegate {
|
||||
getStreamContentsService: caller,
|
||||
database: database,
|
||||
container: container,
|
||||
progress: refreshProgress,
|
||||
log: log)
|
||||
|
||||
progress: refreshProgress)
|
||||
|
||||
addNewFeed.addCompletionHandler = { result in
|
||||
completion(result)
|
||||
}
|
||||
@@ -391,7 +388,6 @@ final class FeedlyAccountDelegate: AccountDelegate {
|
||||
service: caller,
|
||||
container: container,
|
||||
progress: refreshProgress,
|
||||
log: log,
|
||||
customFeedName: feed.editedName)
|
||||
|
||||
|
||||
@@ -497,10 +493,9 @@ final class FeedlyAccountDelegate: AccountDelegate {
|
||||
case .success:
|
||||
break
|
||||
case .failure(let error):
|
||||
os_log(.error, log: self.log, "Restore folder feed error: %@.", error.localizedDescription)
|
||||
Self.logger.error("Feedly: Restore folder feed error: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
group.notify(queue: .main) {
|
||||
@@ -537,7 +532,7 @@ final class FeedlyAccountDelegate: AccountDelegate {
|
||||
}
|
||||
|
||||
func accountWillBeDeleted(_ account: Account) {
|
||||
let logout = FeedlyLogoutOperation(account: account, service: caller, log: log)
|
||||
let logout = FeedlyLogoutOperation(account: account, service: caller)
|
||||
// Dispatch on the shared queue because the lifetime of the account delegate is uncertain.
|
||||
MainThreadOperationQueue.shared.add(logout)
|
||||
}
|
||||
@@ -585,7 +580,7 @@ extension FeedlyAccountDelegate: FeedlyAPICallerDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
let refreshAccessToken = FeedlyRefreshAccessTokenOperation(account: account, service: self, oauthClient: oauthAuthorizationClient, log: log)
|
||||
let refreshAccessToken = FeedlyRefreshAccessTokenOperation(account: account, service: self, oauthClient: oauthAuthorizationClient)
|
||||
refreshAccessToken.downloadProgress = refreshProgress
|
||||
|
||||
/// This must be strongly referenced by the completionBlock of the `FeedlyRefreshAccessTokenOperation`.
|
||||
|
||||
+2
-2
@@ -17,7 +17,7 @@ final class FeedlyAddExistingFeedOperation: FeedlyOperation, FeedlyOperationDele
|
||||
private let operationQueue = MainThreadOperationQueue()
|
||||
var addCompletionHandler: ((Result<Void, Error>) -> ())?
|
||||
|
||||
init(account: Account, credentials: Credentials, resource: FeedlyFeedResourceId, service: FeedlyAddFeedToCollectionService, container: Container, progress: DownloadProgress, log: OSLog, customFeedName: String? = nil) throws {
|
||||
init(account: Account, credentials: Credentials, resource: FeedlyFeedResourceId, service: FeedlyAddFeedToCollectionService, container: Container, progress: DownloadProgress, customFeedName: String? = nil) throws {
|
||||
|
||||
let validator = FeedlyFeedContainerValidator(container: container)
|
||||
let (folder, collectionId) = try validator.getValidContainer()
|
||||
@@ -33,7 +33,7 @@ final class FeedlyAddExistingFeedOperation: FeedlyOperation, FeedlyOperationDele
|
||||
addRequest.downloadProgress = progress
|
||||
self.operationQueue.add(addRequest)
|
||||
|
||||
let createFeeds = FeedlyCreateFeedsForCollectionFoldersOperation(account: account, feedsAndFoldersProvider: addRequest, log: log)
|
||||
let createFeeds = FeedlyCreateFeedsForCollectionFoldersOperation(account: account, feedsAndFoldersProvider: addRequest)
|
||||
createFeeds.downloadProgress = progress
|
||||
createFeeds.addDependency(addRequest)
|
||||
self.operationQueue.add(createFeeds)
|
||||
|
||||
@@ -26,11 +26,10 @@ final class FeedlyAddNewFeedOperation: FeedlyOperation, FeedlyOperationDelegate,
|
||||
private let addToCollectionService: FeedlyAddFeedToCollectionService
|
||||
private let syncUnreadIdsService: FeedlyGetStreamIdsService
|
||||
private let getStreamContentsService: FeedlyGetStreamContentsService
|
||||
private let log: OSLog
|
||||
private var feedResourceId: FeedlyFeedResourceId?
|
||||
var addCompletionHandler: ((Result<WebFeed, Error>) -> ())?
|
||||
|
||||
init(account: Account, credentials: Credentials, url: String, feedName: String?, searchService: FeedlySearchService, addToCollectionService: FeedlyAddFeedToCollectionService, syncUnreadIdsService: FeedlyGetStreamIdsService, getStreamContentsService: FeedlyGetStreamContentsService, database: SyncDatabase, container: Container, progress: DownloadProgress, log: OSLog) throws {
|
||||
init(account: Account, credentials: Credentials, url: String, feedName: String?, searchService: FeedlySearchService, addToCollectionService: FeedlyAddFeedToCollectionService, syncUnreadIdsService: FeedlyGetStreamIdsService, getStreamContentsService: FeedlyGetStreamContentsService, database: SyncDatabase, container: Container, progress: DownloadProgress) throws {
|
||||
|
||||
|
||||
let validator = FeedlyFeedContainerValidator(container: container)
|
||||
@@ -45,7 +44,6 @@ final class FeedlyAddNewFeedOperation: FeedlyOperation, FeedlyOperationDelegate,
|
||||
self.addToCollectionService = addToCollectionService
|
||||
self.syncUnreadIdsService = syncUnreadIdsService
|
||||
self.getStreamContentsService = getStreamContentsService
|
||||
self.log = log
|
||||
|
||||
super.init()
|
||||
|
||||
@@ -91,19 +89,19 @@ final class FeedlyAddNewFeedOperation: FeedlyOperation, FeedlyOperationDelegate,
|
||||
addRequest.downloadProgress = downloadProgress
|
||||
operationQueue.add(addRequest)
|
||||
|
||||
let createFeeds = FeedlyCreateFeedsForCollectionFoldersOperation(account: account, feedsAndFoldersProvider: addRequest, log: log)
|
||||
let createFeeds = FeedlyCreateFeedsForCollectionFoldersOperation(account: account, feedsAndFoldersProvider: addRequest)
|
||||
createFeeds.delegate = self
|
||||
createFeeds.addDependency(addRequest)
|
||||
createFeeds.downloadProgress = downloadProgress
|
||||
operationQueue.add(createFeeds)
|
||||
|
||||
let syncUnread = FeedlyIngestUnreadArticleIdsOperation(account: account, userId: credentials.username, service: syncUnreadIdsService, database: database, newerThan: nil, log: log)
|
||||
let syncUnread = FeedlyIngestUnreadArticleIdsOperation(account: account, userId: credentials.username, service: syncUnreadIdsService, database: database, newerThan: nil)
|
||||
syncUnread.addDependency(createFeeds)
|
||||
syncUnread.downloadProgress = downloadProgress
|
||||
syncUnread.delegate = self
|
||||
operationQueue.add(syncUnread)
|
||||
|
||||
let syncFeed = FeedlySyncStreamContentsOperation(account: account, resource: feedResourceId, service: getStreamContentsService, isPagingEnabled: false, newerThan: nil, log: log)
|
||||
let syncFeed = FeedlySyncStreamContentsOperation(account: account, resource: feedResourceId, service: getStreamContentsService, isPagingEnabled: false, newerThan: nil)
|
||||
syncFeed.addDependency(syncUnread)
|
||||
syncFeed.downloadProgress = downloadProgress
|
||||
syncFeed.delegate = self
|
||||
@@ -120,9 +118,9 @@ final class FeedlyAddNewFeedOperation: FeedlyOperation, FeedlyOperationDelegate,
|
||||
func feedlyOperation(_ operation: FeedlyOperation, didFailWith error: Error) {
|
||||
addCompletionHandler?(.failure(error))
|
||||
addCompletionHandler = nil
|
||||
|
||||
os_log(.debug, log: log, "Unable to add new feed: %{public}@.", error as NSError)
|
||||
|
||||
|
||||
Feedly.logger.error("Feedly: Unable to add new feed with error \(error.localizedDescription)")
|
||||
|
||||
cancel()
|
||||
}
|
||||
|
||||
|
||||
+4
-6
@@ -14,12 +14,10 @@ final class FeedlyCreateFeedsForCollectionFoldersOperation: FeedlyOperation {
|
||||
|
||||
let account: Account
|
||||
let feedsAndFoldersProvider: FeedlyFeedsAndFoldersProviding
|
||||
let log: OSLog
|
||||
|
||||
init(account: Account, feedsAndFoldersProvider: FeedlyFeedsAndFoldersProviding, log: OSLog) {
|
||||
init(account: Account, feedsAndFoldersProvider: FeedlyFeedsAndFoldersProviding) {
|
||||
self.feedsAndFoldersProvider = feedsAndFoldersProvider
|
||||
self.account = account
|
||||
self.log = log
|
||||
}
|
||||
|
||||
override func run() {
|
||||
@@ -93,8 +91,8 @@ final class FeedlyCreateFeedsForCollectionFoldersOperation: FeedlyOperation {
|
||||
|
||||
return (feed, folder)
|
||||
}
|
||||
|
||||
os_log(.debug, log: log, "Processing %i feeds.", feedsAndFolders.count)
|
||||
|
||||
Feedly.logger.info("Feedly: Processing \(feedsAndFolders.count) feeds")
|
||||
feedsAndFolders.forEach { (feed, folder) in
|
||||
if !folder.has(feed) {
|
||||
folder.addWebFeed(feed)
|
||||
@@ -107,7 +105,7 @@ final class FeedlyCreateFeedsForCollectionFoldersOperation: FeedlyOperation {
|
||||
account.removeFeeds(feedsWithoutCollections)
|
||||
|
||||
if !feedsWithoutCollections.isEmpty {
|
||||
os_log(.debug, log: log, "Removed %i feeds", feedsWithoutCollections.count)
|
||||
Feedly.logger.info("Feedly: Removed \(feedsWithoutCollections.count) feeds")
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
-17
@@ -14,21 +14,19 @@ import RSWeb
|
||||
final class FeedlyDownloadArticlesOperation: FeedlyOperation {
|
||||
|
||||
private let account: Account
|
||||
private let log: OSLog
|
||||
private let missingArticleEntryIdProvider: FeedlyEntryIdentifierProviding
|
||||
private let updatedArticleEntryIdProvider: FeedlyEntryIdentifierProviding
|
||||
private let getEntriesService: FeedlyGetEntriesService
|
||||
private let operationQueue = MainThreadOperationQueue()
|
||||
private let finishOperation: FeedlyCheckpointOperation
|
||||
|
||||
init(account: Account, missingArticleEntryIdProvider: FeedlyEntryIdentifierProviding, updatedArticleEntryIdProvider: FeedlyEntryIdentifierProviding, getEntriesService: FeedlyGetEntriesService, log: OSLog) {
|
||||
init(account: Account, missingArticleEntryIdProvider: FeedlyEntryIdentifierProviding, updatedArticleEntryIdProvider: FeedlyEntryIdentifierProviding, getEntriesService: FeedlyGetEntriesService) {
|
||||
self.account = account
|
||||
self.operationQueue.suspend()
|
||||
self.missingArticleEntryIdProvider = missingArticleEntryIdProvider
|
||||
self.updatedArticleEntryIdProvider = updatedArticleEntryIdProvider
|
||||
self.getEntriesService = getEntriesService
|
||||
self.finishOperation = FeedlyCheckpointOperation()
|
||||
self.log = log
|
||||
super.init()
|
||||
self.finishOperation.checkpointDelegate = self
|
||||
self.operationQueue.add(self.finishOperation)
|
||||
@@ -37,27 +35,29 @@ final class FeedlyDownloadArticlesOperation: FeedlyOperation {
|
||||
override func run() {
|
||||
var articleIds = missingArticleEntryIdProvider.entryIds
|
||||
articleIds.formUnion(updatedArticleEntryIdProvider.entryIds)
|
||||
|
||||
os_log(.debug, log: log, "Requesting %{public}i articles.", articleIds.count)
|
||||
|
||||
|
||||
Feedly.logger.info("Feedly: Requesting \(articleIds.count) articles")
|
||||
|
||||
let feedlyAPILimitBatchSize = 1000
|
||||
for articleIds in Array(articleIds).chunked(into: feedlyAPILimitBatchSize) {
|
||||
|
||||
let provider = FeedlyEntryIdentifierProvider(entryIds: Set(articleIds))
|
||||
let getEntries = FeedlyGetEntriesOperation(account: account, service: getEntriesService, provider: provider, log: log)
|
||||
let getEntries = FeedlyGetEntriesOperation(account: account, service: getEntriesService, provider: provider)
|
||||
getEntries.delegate = self
|
||||
self.operationQueue.add(getEntries)
|
||||
|
||||
let organiseByFeed = FeedlyOrganiseParsedItemsByFeedOperation(account: account,
|
||||
parsedItemProvider: getEntries,
|
||||
log: log)
|
||||
let organiseByFeed = FeedlyOrganiseParsedItemsByFeedOperation(
|
||||
account: account,
|
||||
parsedItemProvider: getEntries
|
||||
)
|
||||
organiseByFeed.delegate = self
|
||||
organiseByFeed.addDependency(getEntries)
|
||||
self.operationQueue.add(organiseByFeed)
|
||||
|
||||
let updateAccount = FeedlyUpdateAccountFeedsWithItemsOperation(account: account,
|
||||
organisedItemsProvider: organiseByFeed,
|
||||
log: log)
|
||||
let updateAccount = FeedlyUpdateAccountFeedsWithItemsOperation(
|
||||
account: account,
|
||||
organisedItemsProvider: organiseByFeed
|
||||
)
|
||||
|
||||
updateAccount.delegate = self
|
||||
updateAccount.addDependency(organiseByFeed)
|
||||
@@ -70,8 +70,7 @@ final class FeedlyDownloadArticlesOperation: FeedlyOperation {
|
||||
}
|
||||
|
||||
override func didCancel() {
|
||||
// TODO: fix error on below line: "Expression type '()' is ambiguous without more context"
|
||||
//os_log(.debug, log: log, "Cancelling %{public}@.", self)
|
||||
Feedly.logger.info("Feedly: Canceling FeedlyDownloadArticlesOperation")
|
||||
operationQueue.cancelAllOperations()
|
||||
super.didCancel()
|
||||
}
|
||||
@@ -90,8 +89,7 @@ extension FeedlyDownloadArticlesOperation: FeedlyOperationDelegate {
|
||||
assert(Thread.isMainThread)
|
||||
|
||||
// Having this log is useful for debugging missing required JSON keys in the response from Feedly, for example.
|
||||
os_log(.debug, log: log, "%{public}@ failed with error: %{public}@.", String(describing: operation), error as NSError)
|
||||
|
||||
Feedly.logger.error("Feedly: FeedlyDownloadArticlesOperation did fail with error: \(error.localizedDescription)")
|
||||
cancel()
|
||||
}
|
||||
}
|
||||
+1
-3
@@ -12,13 +12,11 @@ import os.log
|
||||
final class FeedlyFetchIdsForMissingArticlesOperation: FeedlyOperation, FeedlyEntryIdentifierProviding {
|
||||
|
||||
private let account: Account
|
||||
private let log: OSLog
|
||||
|
||||
private(set) var entryIds = Set<String>()
|
||||
|
||||
init(account: Account, log: OSLog) {
|
||||
init(account: Account) {
|
||||
self.account = account
|
||||
self.log = log
|
||||
}
|
||||
|
||||
override func run() {
|
||||
|
||||
+5
-7
@@ -17,27 +17,25 @@ protocol FeedlyCollectionProviding: AnyObject {
|
||||
final class FeedlyGetCollectionsOperation: FeedlyOperation, FeedlyCollectionProviding {
|
||||
|
||||
let service: FeedlyGetCollectionsService
|
||||
let log: OSLog
|
||||
|
||||
private(set) var collections = [FeedlyCollection]()
|
||||
|
||||
init(service: FeedlyGetCollectionsService, log: OSLog) {
|
||||
init(service: FeedlyGetCollectionsService) {
|
||||
self.service = service
|
||||
self.log = log
|
||||
}
|
||||
|
||||
override func run() {
|
||||
os_log(.debug, log: log, "Requesting collections.")
|
||||
|
||||
Feedly.logger.info("Feedly: Requesting collections")
|
||||
|
||||
service.getCollections { result in
|
||||
switch result {
|
||||
case .success(let collections):
|
||||
os_log(.debug, log: self.log, "Received collections: %{public}@", collections.map { $0.id })
|
||||
Feedly.logger.info("Feedly: Received collections \(collections.map { $0.id })")
|
||||
self.collections = collections
|
||||
self.didFinish()
|
||||
|
||||
case .failure(let error):
|
||||
os_log(.debug, log: self.log, "Unable to request collections: %{public}@.", error as NSError)
|
||||
Feedly.logger.error("Feedly: Unable to request collections with error \(error.localizedDescription)")
|
||||
self.didFinish(with: error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,13 +16,11 @@ final class FeedlyGetEntriesOperation: FeedlyOperation, FeedlyEntryProviding, Fe
|
||||
let account: Account
|
||||
let service: FeedlyGetEntriesService
|
||||
let provider: FeedlyEntryIdentifierProviding
|
||||
let log: OSLog
|
||||
|
||||
init(account: Account, service: FeedlyGetEntriesService, provider: FeedlyEntryIdentifierProviding, log: OSLog) {
|
||||
init(account: Account, service: FeedlyGetEntriesService, provider: FeedlyEntryIdentifierProviding) {
|
||||
self.account = account
|
||||
self.service = service
|
||||
self.provider = provider
|
||||
self.log = log
|
||||
}
|
||||
|
||||
private(set) var entries = [FeedlyEntry]()
|
||||
@@ -63,7 +61,7 @@ final class FeedlyGetEntriesOperation: FeedlyOperation, FeedlyEntryProviding, Fe
|
||||
self.didFinish()
|
||||
|
||||
case .failure(let error):
|
||||
os_log(.debug, log: self.log, "Unable to get entries: %{public}@.", error as NSError)
|
||||
Feedly.logger.error("Feedly: Unable to get entries with error \(error.localizedDescription)")
|
||||
self.didFinish(with: error)
|
||||
}
|
||||
}
|
||||
|
||||
+5
-7
@@ -58,7 +58,7 @@ final class FeedlyGetStreamContentsOperation: FeedlyOperation, FeedlyEntryProvid
|
||||
let entryIds = Set(entries.map { $0.id })
|
||||
let parsedIds = Set(parsed.map { $0.uniqueID })
|
||||
let difference = entryIds.subtracting(parsedIds)
|
||||
os_log(.debug, log: log, "Dropping articles with ids: %{public}@.", difference)
|
||||
Feedly.logger.info("Feedly: Dropping articles with IDs \(difference)")
|
||||
}
|
||||
|
||||
storedParsedEntries = parsed
|
||||
@@ -79,22 +79,20 @@ final class FeedlyGetStreamContentsOperation: FeedlyOperation, FeedlyEntryProvid
|
||||
let unreadOnly: Bool?
|
||||
let newerThan: Date?
|
||||
let continuation: String?
|
||||
let log: OSLog
|
||||
|
||||
weak var streamDelegate: FeedlyGetStreamContentsOperationDelegate?
|
||||
|
||||
init(account: Account, resource: FeedlyResourceId, service: FeedlyGetStreamContentsService, continuation: String? = nil, newerThan: Date?, unreadOnly: Bool? = nil, log: OSLog) {
|
||||
init(account: Account, resource: FeedlyResourceId, service: FeedlyGetStreamContentsService, continuation: String? = nil, newerThan: Date?, unreadOnly: Bool? = nil) {
|
||||
self.account = account
|
||||
self.resourceProvider = ResourceProvider(resource: resource)
|
||||
self.service = service
|
||||
self.continuation = continuation
|
||||
self.unreadOnly = unreadOnly
|
||||
self.newerThan = newerThan
|
||||
self.log = log
|
||||
}
|
||||
|
||||
convenience init(account: Account, resourceProvider: FeedlyResourceProviding, service: FeedlyGetStreamContentsService, newerThan: Date?, unreadOnly: Bool? = nil, log: OSLog) {
|
||||
self.init(account: account, resource: resourceProvider.resource, service: service, newerThan: newerThan, unreadOnly: unreadOnly, log: log)
|
||||
convenience init(account: Account, resourceProvider: FeedlyResourceProviding, service: FeedlyGetStreamContentsService, newerThan: Date?, unreadOnly: Bool? = nil) {
|
||||
self.init(account: account, resource: resourceProvider.resource, service: service, newerThan: newerThan, unreadOnly: unreadOnly)
|
||||
}
|
||||
|
||||
override func run() {
|
||||
@@ -108,7 +106,7 @@ final class FeedlyGetStreamContentsOperation: FeedlyOperation, FeedlyEntryProvid
|
||||
self.didFinish()
|
||||
|
||||
case .failure(let error):
|
||||
os_log(.debug, log: self.log, "Unable to get stream contents: %{public}@.", error as NSError)
|
||||
Feedly.logger.error("Feedly: Unable to get stream contents: \(error.localizedDescription)")
|
||||
self.didFinish(with: error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,16 +32,14 @@ final class FeedlyGetStreamIdsOperation: FeedlyOperation, FeedlyEntryIdentifierP
|
||||
let resource: FeedlyResourceId
|
||||
let unreadOnly: Bool?
|
||||
let newerThan: Date?
|
||||
let log: OSLog
|
||||
|
||||
init(account: Account, resource: FeedlyResourceId, service: FeedlyGetStreamIdsService, continuation: String? = nil, newerThan: Date? = nil, unreadOnly: Bool?, log: OSLog) {
|
||||
init(account: Account, resource: FeedlyResourceId, service: FeedlyGetStreamIdsService, continuation: String? = nil, newerThan: Date? = nil, unreadOnly: Bool?) {
|
||||
self.account = account
|
||||
self.resource = resource
|
||||
self.service = service
|
||||
self.continuation = continuation
|
||||
self.newerThan = newerThan
|
||||
self.unreadOnly = unreadOnly
|
||||
self.log = log
|
||||
}
|
||||
|
||||
weak var streamIdsDelegate: FeedlyGetStreamIdsOperationDelegate?
|
||||
@@ -57,7 +55,7 @@ final class FeedlyGetStreamIdsOperation: FeedlyOperation, FeedlyEntryIdentifierP
|
||||
self.didFinish()
|
||||
|
||||
case .failure(let error):
|
||||
os_log(.debug, log: self.log, "Unable to get stream ids: %{public}@.", error as NSError)
|
||||
Feedly.logger.error("Feedly: Unable to get stream IDs: \(error.localizedDescription)")
|
||||
self.didFinish(with: error)
|
||||
}
|
||||
}
|
||||
|
||||
+5
-7
@@ -20,19 +20,17 @@ final class FeedlyGetUpdatedArticleIdsOperation: FeedlyOperation, FeedlyEntryIde
|
||||
private let resource: FeedlyResourceId
|
||||
private let service: FeedlyGetStreamIdsService
|
||||
private let newerThan: Date?
|
||||
private let log: OSLog
|
||||
|
||||
init(account: Account, resource: FeedlyResourceId, service: FeedlyGetStreamIdsService, newerThan: Date?, log: OSLog) {
|
||||
init(account: Account, resource: FeedlyResourceId, service: FeedlyGetStreamIdsService, newerThan: Date?) {
|
||||
self.account = account
|
||||
self.resource = resource
|
||||
self.service = service
|
||||
self.newerThan = newerThan
|
||||
self.log = log
|
||||
}
|
||||
|
||||
convenience init(account: Account, userId: String, service: FeedlyGetStreamIdsService, newerThan: Date?, log: OSLog) {
|
||||
convenience init(account: Account, userId: String, service: FeedlyGetStreamIdsService, newerThan: Date?) {
|
||||
let all = FeedlyCategoryResourceId.Global.all(for: userId)
|
||||
self.init(account: account, resource: all, service: service, newerThan: newerThan, log: log)
|
||||
self.init(account: account, resource: all, service: service, newerThan: newerThan)
|
||||
}
|
||||
|
||||
var entryIds: Set<String> {
|
||||
@@ -47,7 +45,7 @@ final class FeedlyGetUpdatedArticleIdsOperation: FeedlyOperation, FeedlyEntryIde
|
||||
|
||||
private func getStreamIds(_ continuation: String?) {
|
||||
guard let date = newerThan else {
|
||||
os_log(.debug, log: log, "No date provided so everything must be new (nothing is updated).")
|
||||
Feedly.logger.debug("Feedly: No date provided so everything must be new (nothing is updated)")
|
||||
didFinish()
|
||||
return
|
||||
}
|
||||
@@ -66,7 +64,7 @@ final class FeedlyGetUpdatedArticleIdsOperation: FeedlyOperation, FeedlyEntryIde
|
||||
storedUpdatedArticleIds.formUnion(streamIds.ids)
|
||||
|
||||
guard let continuation = streamIds.continuation else {
|
||||
os_log(.debug, log: log, "%{public}i articles updated since last successful sync start date.", storedUpdatedArticleIds.count)
|
||||
Feedly.logger.info("Feedly: Articles updated since last successful sync start date: \(self.storedUpdatedArticleIds.count)")
|
||||
didFinish()
|
||||
return
|
||||
}
|
||||
|
||||
+3
-5
@@ -24,19 +24,17 @@ final class FeedlyIngestStarredArticleIdsOperation: FeedlyOperation {
|
||||
private let service: FeedlyGetStreamIdsService
|
||||
private let database: SyncDatabase
|
||||
private var remoteEntryIds = Set<String>()
|
||||
private let log: OSLog
|
||||
|
||||
convenience init(account: Account, userId: String, service: FeedlyGetStreamIdsService, database: SyncDatabase, newerThan: Date?, log: OSLog) {
|
||||
convenience init(account: Account, userId: String, service: FeedlyGetStreamIdsService, database: SyncDatabase, newerThan: Date?) {
|
||||
let resource = FeedlyTagResourceId.Global.saved(for: userId)
|
||||
self.init(account: account, resource: resource, service: service, database: database, newerThan: newerThan, log: log)
|
||||
self.init(account: account, resource: resource, service: service, database: database, newerThan: newerThan)
|
||||
}
|
||||
|
||||
init(account: Account, resource: FeedlyResourceId, service: FeedlyGetStreamIdsService, database: SyncDatabase, newerThan: Date?, log: OSLog) {
|
||||
init(account: Account, resource: FeedlyResourceId, service: FeedlyGetStreamIdsService, database: SyncDatabase, newerThan: Date?) {
|
||||
self.account = account
|
||||
self.resource = resource
|
||||
self.service = service
|
||||
self.database = database
|
||||
self.log = log
|
||||
}
|
||||
|
||||
override func run() {
|
||||
|
||||
+4
-6
@@ -20,18 +20,16 @@ final class FeedlyIngestStreamArticleIdsOperation: FeedlyOperation {
|
||||
private let account: Account
|
||||
private let resource: FeedlyResourceId
|
||||
private let service: FeedlyGetStreamIdsService
|
||||
private let log: OSLog
|
||||
|
||||
init(account: Account, resource: FeedlyResourceId, service: FeedlyGetStreamIdsService, log: OSLog) {
|
||||
init(account: Account, resource: FeedlyResourceId, service: FeedlyGetStreamIdsService) {
|
||||
self.account = account
|
||||
self.resource = resource
|
||||
self.service = service
|
||||
self.log = log
|
||||
}
|
||||
|
||||
convenience init(account: Account, userId: String, service: FeedlyGetStreamIdsService, log: OSLog) {
|
||||
convenience init(account: Account, userId: String, service: FeedlyGetStreamIdsService) {
|
||||
let all = FeedlyCategoryResourceId.Global.all(for: userId)
|
||||
self.init(account: account, resource: all, service: service, log: log)
|
||||
self.init(account: account, resource: all, service: service)
|
||||
}
|
||||
|
||||
override func run() {
|
||||
@@ -58,7 +56,7 @@ final class FeedlyIngestStreamArticleIdsOperation: FeedlyOperation {
|
||||
}
|
||||
|
||||
guard let continuation = streamIds.continuation else {
|
||||
os_log(.debug, log: self.log, "Reached end of stream for %@", self.resource.id)
|
||||
Feedly.logger.info("Feedly: Reached end of stream for \(self.resource.id)")
|
||||
self.didFinish()
|
||||
return
|
||||
}
|
||||
|
||||
+3
-5
@@ -25,19 +25,17 @@ final class FeedlyIngestUnreadArticleIdsOperation: FeedlyOperation {
|
||||
private let service: FeedlyGetStreamIdsService
|
||||
private let database: SyncDatabase
|
||||
private var remoteEntryIds = Set<String>()
|
||||
private let log: OSLog
|
||||
|
||||
convenience init(account: Account, userId: String, service: FeedlyGetStreamIdsService, database: SyncDatabase, newerThan: Date?, log: OSLog) {
|
||||
convenience init(account: Account, userId: String, service: FeedlyGetStreamIdsService, database: SyncDatabase, newerThan: Date?) {
|
||||
let resource = FeedlyCategoryResourceId.Global.all(for: userId)
|
||||
self.init(account: account, resource: resource, service: service, database: database, newerThan: newerThan, log: log)
|
||||
self.init(account: account, resource: resource, service: service, database: database, newerThan: newerThan)
|
||||
}
|
||||
|
||||
init(account: Account, resource: FeedlyResourceId, service: FeedlyGetStreamIdsService, database: SyncDatabase, newerThan: Date?, log: OSLog) {
|
||||
init(account: Account, resource: FeedlyResourceId, service: FeedlyGetStreamIdsService, database: SyncDatabase, newerThan: Date?) {
|
||||
self.account = account
|
||||
self.resource = resource
|
||||
self.service = service
|
||||
self.database = database
|
||||
self.log = log
|
||||
}
|
||||
|
||||
override func run() {
|
||||
|
||||
@@ -17,16 +17,14 @@ final class FeedlyLogoutOperation: FeedlyOperation {
|
||||
|
||||
let service: FeedlyLogoutService
|
||||
let account: Account
|
||||
let log: OSLog
|
||||
|
||||
init(account: Account, service: FeedlyLogoutService, log: OSLog) {
|
||||
init(account: Account, service: FeedlyLogoutService) {
|
||||
self.service = service
|
||||
self.account = account
|
||||
self.log = log
|
||||
}
|
||||
|
||||
override func run() {
|
||||
os_log("Requesting logout of %{public}@ account.", "\(account.type)")
|
||||
Feedly.logger.info("Feedly: Requesting logout \(self.account.accountID, privacy: .public)")
|
||||
service.logout(completion: didCompleteLogout(_:))
|
||||
}
|
||||
|
||||
@@ -34,7 +32,7 @@ final class FeedlyLogoutOperation: FeedlyOperation {
|
||||
assert(Thread.isMainThread)
|
||||
switch result {
|
||||
case .success:
|
||||
os_log("Logged out of %{public}@ account.", "\(account.type)")
|
||||
Feedly.logger.info("Feedly: Logged out of \(self.account.accountID, privacy: .public)")
|
||||
do {
|
||||
try account.removeCredentials(type: .oauthAccessToken)
|
||||
try account.removeCredentials(type: .oauthRefreshToken)
|
||||
@@ -44,7 +42,7 @@ final class FeedlyLogoutOperation: FeedlyOperation {
|
||||
didFinish()
|
||||
|
||||
case .failure(let error):
|
||||
os_log("Logout failed because %{public}@.", error as NSError)
|
||||
Feedly.logger.error("Feedly: Logout failed: \(error.localizedDescription)")
|
||||
didFinish(with: error)
|
||||
}
|
||||
}
|
||||
|
||||
+8
-8
@@ -18,14 +18,12 @@ final class FeedlyMirrorCollectionsAsFoldersOperation: FeedlyOperation, FeedlyFe
|
||||
|
||||
let account: Account
|
||||
let collectionsProvider: FeedlyCollectionProviding
|
||||
let log: OSLog
|
||||
|
||||
private(set) var feedsAndFolders = [([FeedlyFeed], Folder)]()
|
||||
|
||||
init(account: Account, collectionsProvider: FeedlyCollectionProviding, log: OSLog) {
|
||||
init(account: Account, collectionsProvider: FeedlyCollectionProviding) {
|
||||
self.collectionsProvider = collectionsProvider
|
||||
self.account = account
|
||||
self.log = log
|
||||
}
|
||||
|
||||
override func run() {
|
||||
@@ -45,9 +43,9 @@ final class FeedlyMirrorCollectionsAsFoldersOperation: FeedlyOperation, FeedlyFe
|
||||
folder.externalID = parser.externalID
|
||||
return (collection.feeds, folder)
|
||||
}
|
||||
|
||||
os_log(.debug, log: log, "Ensured %i folders for %i collections.", feedsAndFolders.count, collections.count)
|
||||
|
||||
|
||||
Feedly.logger.info("Feedly: Ensured \(self.feedsAndFolders.count) folders for \(collections.count) collections")
|
||||
|
||||
// Remove folders without a corresponding collection
|
||||
let collectionFolders = Set(feedsAndFolders.map { $0.1 })
|
||||
let foldersWithoutCollections = localFolders.subtracting(collectionFolders)
|
||||
@@ -56,8 +54,10 @@ final class FeedlyMirrorCollectionsAsFoldersOperation: FeedlyOperation, FeedlyFe
|
||||
for unmatched in foldersWithoutCollections {
|
||||
account.removeFolder(unmatched)
|
||||
}
|
||||
|
||||
os_log(.debug, log: log, "Removed %i folders: %@", foldersWithoutCollections.count, foldersWithoutCollections.map { $0.externalID ?? $0.nameForDisplay })
|
||||
|
||||
let folderCountForLog = foldersWithoutCollections.count
|
||||
let foldersForLog = foldersWithoutCollections.map { $0.externalID ?? $0.nameForDisplay }
|
||||
Feedly.logger.info("Feedly: Removed \(folderCountForLog) folders: \(foldersForLog)")
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-6
@@ -20,7 +20,6 @@ final class FeedlyOrganiseParsedItemsByFeedOperation: FeedlyOperation, FeedlyPar
|
||||
|
||||
private let account: Account
|
||||
private let parsedItemProvider: FeedlyParsedItemProviding
|
||||
private let log: OSLog
|
||||
|
||||
var parsedItemsByFeedProviderName: String {
|
||||
return name ?? String(describing: Self.self)
|
||||
@@ -33,10 +32,9 @@ final class FeedlyOrganiseParsedItemsByFeedOperation: FeedlyOperation, FeedlyPar
|
||||
|
||||
private var itemsKeyedByFeedId = [String: Set<ParsedItem>]()
|
||||
|
||||
init(account: Account, parsedItemProvider: FeedlyParsedItemProviding, log: OSLog) {
|
||||
init(account: Account, parsedItemProvider: FeedlyParsedItemProviding) {
|
||||
self.account = account
|
||||
self.parsedItemProvider = parsedItemProvider
|
||||
self.log = log
|
||||
}
|
||||
|
||||
override func run() {
|
||||
@@ -59,9 +57,9 @@ final class FeedlyOrganiseParsedItemsByFeedOperation: FeedlyOperation, FeedlyPar
|
||||
}()
|
||||
dict[key] = value
|
||||
}
|
||||
|
||||
os_log(.debug, log: log, "Grouped %i items by %i feeds for %@", items.count, dict.count, parsedItemProvider.parsedItemProviderName)
|
||||
|
||||
|
||||
Feedly.logger.info("Feedly: Grouped \(items.count) items by \(dict.count) feeds for \(self.parsedItemProvider.parsedItemProviderName)")
|
||||
|
||||
itemsKeyedByFeedId = dict
|
||||
}
|
||||
}
|
||||
+7
-9
@@ -16,13 +16,11 @@ final class FeedlyRefreshAccessTokenOperation: FeedlyOperation {
|
||||
let service: OAuthAccessTokenRefreshing
|
||||
let oauthClient: OAuthAuthorizationClient
|
||||
let account: Account
|
||||
let log: OSLog
|
||||
|
||||
init(account: Account, service: OAuthAccessTokenRefreshing, oauthClient: OAuthAuthorizationClient, log: OSLog) {
|
||||
init(account: Account, service: OAuthAccessTokenRefreshing, oauthClient: OAuthAuthorizationClient) {
|
||||
self.oauthClient = oauthClient
|
||||
self.service = service
|
||||
self.account = account
|
||||
self.log = log
|
||||
}
|
||||
|
||||
override func run() {
|
||||
@@ -30,7 +28,7 @@ final class FeedlyRefreshAccessTokenOperation: FeedlyOperation {
|
||||
|
||||
do {
|
||||
guard let credentials = try account.retrieveCredentials(type: .oauthRefreshToken) else {
|
||||
os_log(.debug, log: log, "Could not find a refresh token in the keychain. Check the refresh token is added to the Keychain, remove the account and add it again.")
|
||||
Feedly.logger.error("Feedly: Could not find a refresh token in the keychain. Check the refresh token is added to the Keychain, remove the account and add it again")
|
||||
throw TransportError.httpError(status: 403)
|
||||
}
|
||||
|
||||
@@ -40,9 +38,9 @@ final class FeedlyRefreshAccessTokenOperation: FeedlyOperation {
|
||||
didFinish(with: error)
|
||||
return
|
||||
}
|
||||
|
||||
os_log(.debug, log: log, "Refreshing access token.")
|
||||
|
||||
|
||||
Feedly.logger.info("Feedly: Refreshing access token")
|
||||
|
||||
// Ignore cancellation after the request is resumed otherwise we may continue storing a potentially invalid token!
|
||||
service.refreshAccessToken(with: refreshToken.secret, client: oauthClient) { result in
|
||||
self.didRefreshAccessToken(result)
|
||||
@@ -55,13 +53,13 @@ final class FeedlyRefreshAccessTokenOperation: FeedlyOperation {
|
||||
switch result {
|
||||
case .success(let grant):
|
||||
do {
|
||||
os_log(.debug, log: log, "Storing refresh token.")
|
||||
Feedly.logger.info("Feedly: Storing refresh token")
|
||||
// Store the refresh token first because it sends this token to the account delegate.
|
||||
if let token = grant.refreshToken {
|
||||
try account.storeCredentials(token)
|
||||
}
|
||||
|
||||
os_log(.debug, log: log, "Storing access token.")
|
||||
Feedly.logger.info("Feedly: Storing access token")
|
||||
// Now store the access token because we want the account delegate to use it.
|
||||
try account.storeCredentials(grant.accessToken)
|
||||
|
||||
|
||||
+9
-10
@@ -22,17 +22,15 @@ final class FeedlyRequestStreamsOperation: FeedlyOperation {
|
||||
let collectionsProvider: FeedlyCollectionProviding
|
||||
let service: FeedlyGetStreamContentsService
|
||||
let account: Account
|
||||
let log: OSLog
|
||||
let newerThan: Date?
|
||||
let unreadOnly: Bool?
|
||||
|
||||
init(account: Account, collectionsProvider: FeedlyCollectionProviding, newerThan: Date?, unreadOnly: Bool?, service: FeedlyGetStreamContentsService, log: OSLog) {
|
||||
init(account: Account, collectionsProvider: FeedlyCollectionProviding, newerThan: Date?, unreadOnly: Bool?, service: FeedlyGetStreamContentsService) {
|
||||
self.account = account
|
||||
self.service = service
|
||||
self.collectionsProvider = collectionsProvider
|
||||
self.newerThan = newerThan
|
||||
self.unreadOnly = unreadOnly
|
||||
self.log = log
|
||||
}
|
||||
|
||||
override func run() {
|
||||
@@ -46,15 +44,16 @@ final class FeedlyRequestStreamsOperation: FeedlyOperation {
|
||||
|
||||
for collection in collectionsProvider.collections {
|
||||
let resource = FeedlyCategoryResourceId(id: collection.id)
|
||||
let operation = FeedlyGetStreamContentsOperation(account: account,
|
||||
resource: resource,
|
||||
service: service,
|
||||
newerThan: newerThan,
|
||||
unreadOnly: unreadOnly,
|
||||
log: log)
|
||||
let operation = FeedlyGetStreamContentsOperation(
|
||||
account: account,
|
||||
resource: resource,
|
||||
service: service,
|
||||
newerThan: newerThan,
|
||||
unreadOnly: unreadOnly
|
||||
)
|
||||
queueDelegate?.feedlyRequestStreamsOperation(self, enqueue: operation)
|
||||
}
|
||||
|
||||
os_log(.debug, log: log, "Requested %i collection streams", collectionsProvider.collections.count)
|
||||
Feedly.logger.info("Feedly: Requested \(self.collectionsProvider.collections.count) collection streams")
|
||||
}
|
||||
}
|
||||
+3
-5
@@ -16,17 +16,15 @@ import os.log
|
||||
final class FeedlySendArticleStatusesOperation: FeedlyOperation {
|
||||
|
||||
private let database: SyncDatabase
|
||||
private let log: OSLog
|
||||
private let service: FeedlyMarkArticlesService
|
||||
|
||||
init(database: SyncDatabase, service: FeedlyMarkArticlesService, log: OSLog) {
|
||||
init(database: SyncDatabase, service: FeedlyMarkArticlesService) {
|
||||
self.database = database
|
||||
self.service = service
|
||||
self.log = log
|
||||
}
|
||||
|
||||
override func run() {
|
||||
os_log(.debug, log: log, "Sending article statuses...")
|
||||
Feedly.logger.info("Feedly: Sending article statuses")
|
||||
|
||||
database.selectForProcessing { result in
|
||||
if self.isCanceled {
|
||||
@@ -81,7 +79,7 @@ private extension FeedlySendArticleStatusesOperation {
|
||||
}
|
||||
|
||||
group.notify(queue: DispatchQueue.main) {
|
||||
os_log(.debug, log: self.log, "Done sending article statuses.")
|
||||
Feedly.logger.info("Feedly: Finished sending article statuses")
|
||||
self.didFinish()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ import Secrets
|
||||
final class FeedlySyncAllOperation: FeedlyOperation {
|
||||
|
||||
private let operationQueue = MainThreadOperationQueue()
|
||||
private let log: OSLog
|
||||
let syncUUID: UUID
|
||||
|
||||
var syncCompletionHandler: ((Result<Void, Error>) -> ())?
|
||||
@@ -34,9 +33,8 @@ final class FeedlySyncAllOperation: FeedlyOperation {
|
||||
///
|
||||
/// Download articles for statuses at the union of those statuses without its corresponding article and those included in 3 (changed since last successful sync).
|
||||
///
|
||||
init(account: Account, feedlyUserId: String, lastSuccessfulFetchStartDate: Date?, markArticlesService: FeedlyMarkArticlesService, getUnreadService: FeedlyGetStreamIdsService, getCollectionsService: FeedlyGetCollectionsService, getStreamContentsService: FeedlyGetStreamContentsService, getStarredService: FeedlyGetStreamIdsService, getStreamIdsService: FeedlyGetStreamIdsService, getEntriesService: FeedlyGetEntriesService, database: SyncDatabase, downloadProgress: DownloadProgress, log: OSLog) {
|
||||
init(account: Account, feedlyUserId: String, lastSuccessfulFetchStartDate: Date?, markArticlesService: FeedlyMarkArticlesService, getUnreadService: FeedlyGetStreamIdsService, getCollectionsService: FeedlyGetCollectionsService, getStreamContentsService: FeedlyGetStreamContentsService, getStarredService: FeedlyGetStreamIdsService, getStreamIdsService: FeedlyGetStreamIdsService, getEntriesService: FeedlyGetEntriesService, database: SyncDatabase, downloadProgress: DownloadProgress) {
|
||||
self.syncUUID = UUID()
|
||||
self.log = log
|
||||
self.operationQueue.suspend()
|
||||
|
||||
super.init()
|
||||
@@ -44,38 +42,38 @@ final class FeedlySyncAllOperation: FeedlyOperation {
|
||||
self.downloadProgress = downloadProgress
|
||||
|
||||
// Send any read/unread/starred article statuses to Feedly before anything else.
|
||||
let sendArticleStatuses = FeedlySendArticleStatusesOperation(database: database, service: markArticlesService, log: log)
|
||||
let sendArticleStatuses = FeedlySendArticleStatusesOperation(database: database, service: markArticlesService)
|
||||
sendArticleStatuses.delegate = self
|
||||
sendArticleStatuses.downloadProgress = downloadProgress
|
||||
self.operationQueue.add(sendArticleStatuses)
|
||||
|
||||
// Get all the Collections the user has.
|
||||
let getCollections = FeedlyGetCollectionsOperation(service: getCollectionsService, log: log)
|
||||
let getCollections = FeedlyGetCollectionsOperation(service: getCollectionsService)
|
||||
getCollections.delegate = self
|
||||
getCollections.downloadProgress = downloadProgress
|
||||
getCollections.addDependency(sendArticleStatuses)
|
||||
self.operationQueue.add(getCollections)
|
||||
|
||||
// Ensure a folder exists for each Collection, removing Folders without a corresponding Collection.
|
||||
let mirrorCollectionsAsFolders = FeedlyMirrorCollectionsAsFoldersOperation(account: account, collectionsProvider: getCollections, log: log)
|
||||
let mirrorCollectionsAsFolders = FeedlyMirrorCollectionsAsFoldersOperation(account: account, collectionsProvider: getCollections)
|
||||
mirrorCollectionsAsFolders.delegate = self
|
||||
mirrorCollectionsAsFolders.addDependency(getCollections)
|
||||
self.operationQueue.add(mirrorCollectionsAsFolders)
|
||||
|
||||
// Ensure feeds are created and grouped by their folders.
|
||||
let createFeedsOperation = FeedlyCreateFeedsForCollectionFoldersOperation(account: account, feedsAndFoldersProvider: mirrorCollectionsAsFolders, log: log)
|
||||
let createFeedsOperation = FeedlyCreateFeedsForCollectionFoldersOperation(account: account, feedsAndFoldersProvider: mirrorCollectionsAsFolders)
|
||||
createFeedsOperation.delegate = self
|
||||
createFeedsOperation.addDependency(mirrorCollectionsAsFolders)
|
||||
self.operationQueue.add(createFeedsOperation)
|
||||
|
||||
let getAllArticleIds = FeedlyIngestStreamArticleIdsOperation(account: account, userId: feedlyUserId, service: getStreamIdsService, log: log)
|
||||
let getAllArticleIds = FeedlyIngestStreamArticleIdsOperation(account: account, userId: feedlyUserId, service: getStreamIdsService)
|
||||
getAllArticleIds.delegate = self
|
||||
getAllArticleIds.downloadProgress = downloadProgress
|
||||
getAllArticleIds.addDependency(createFeedsOperation)
|
||||
self.operationQueue.add(getAllArticleIds)
|
||||
|
||||
// Get each page of unread article ids in the global.all stream for the last 31 days (nil = Feedly API default).
|
||||
let getUnread = FeedlyIngestUnreadArticleIdsOperation(account: account, userId: feedlyUserId, service: getUnreadService, database: database, newerThan: nil, log: log)
|
||||
let getUnread = FeedlyIngestUnreadArticleIdsOperation(account: account, userId: feedlyUserId, service: getUnreadService, database: database, newerThan: nil)
|
||||
getUnread.delegate = self
|
||||
getUnread.addDependency(getAllArticleIds)
|
||||
getUnread.downloadProgress = downloadProgress
|
||||
@@ -83,21 +81,21 @@ final class FeedlySyncAllOperation: FeedlyOperation {
|
||||
|
||||
// Get each page of the article ids which have been update since the last successful fetch start date.
|
||||
// If the date is nil, this operation provides an empty set (everything is new, nothing is updated).
|
||||
let getUpdated = FeedlyGetUpdatedArticleIdsOperation(account: account, userId: feedlyUserId, service: getStreamIdsService, newerThan: lastSuccessfulFetchStartDate, log: log)
|
||||
let getUpdated = FeedlyGetUpdatedArticleIdsOperation(account: account, userId: feedlyUserId, service: getStreamIdsService, newerThan: lastSuccessfulFetchStartDate)
|
||||
getUpdated.delegate = self
|
||||
getUpdated.downloadProgress = downloadProgress
|
||||
getUpdated.addDependency(createFeedsOperation)
|
||||
self.operationQueue.add(getUpdated)
|
||||
|
||||
// Get each page of the article ids for starred articles.
|
||||
let getStarred = FeedlyIngestStarredArticleIdsOperation(account: account, userId: feedlyUserId, service: getStarredService, database: database, newerThan: nil, log: log)
|
||||
let getStarred = FeedlyIngestStarredArticleIdsOperation(account: account, userId: feedlyUserId, service: getStarredService, database: database, newerThan: nil)
|
||||
getStarred.delegate = self
|
||||
getStarred.downloadProgress = downloadProgress
|
||||
getStarred.addDependency(createFeedsOperation)
|
||||
self.operationQueue.add(getStarred)
|
||||
|
||||
// Now all the possible article ids we need have a status, fetch the article ids for missing articles.
|
||||
let getMissingIds = FeedlyFetchIdsForMissingArticlesOperation(account: account, log: log)
|
||||
let getMissingIds = FeedlyFetchIdsForMissingArticlesOperation(account: account)
|
||||
getMissingIds.delegate = self
|
||||
getMissingIds.downloadProgress = downloadProgress
|
||||
getMissingIds.addDependency(getAllArticleIds)
|
||||
@@ -107,11 +105,12 @@ final class FeedlySyncAllOperation: FeedlyOperation {
|
||||
self.operationQueue.add(getMissingIds)
|
||||
|
||||
// Download all the missing and updated articles
|
||||
let downloadMissingArticles = FeedlyDownloadArticlesOperation(account: account,
|
||||
missingArticleEntryIdProvider: getMissingIds,
|
||||
updatedArticleEntryIdProvider: getUpdated,
|
||||
getEntriesService: getEntriesService,
|
||||
log: log)
|
||||
let downloadMissingArticles = FeedlyDownloadArticlesOperation(
|
||||
account: account,
|
||||
missingArticleEntryIdProvider: getMissingIds,
|
||||
updatedArticleEntryIdProvider: getUpdated,
|
||||
getEntriesService: getEntriesService
|
||||
)
|
||||
downloadMissingArticles.delegate = self
|
||||
downloadMissingArticles.downloadProgress = downloadProgress
|
||||
downloadMissingArticles.addDependency(getMissingIds)
|
||||
@@ -126,17 +125,17 @@ final class FeedlySyncAllOperation: FeedlyOperation {
|
||||
self.operationQueue.add(finishOperation)
|
||||
}
|
||||
|
||||
convenience init(account: Account, feedlyUserId: String, caller: FeedlyAPICaller, database: SyncDatabase, lastSuccessfulFetchStartDate: Date?, downloadProgress: DownloadProgress, log: OSLog) {
|
||||
self.init(account: account, feedlyUserId: feedlyUserId, lastSuccessfulFetchStartDate: lastSuccessfulFetchStartDate, markArticlesService: caller, getUnreadService: caller, getCollectionsService: caller, getStreamContentsService: caller, getStarredService: caller, getStreamIdsService: caller, getEntriesService: caller, database: database, downloadProgress: downloadProgress, log: log)
|
||||
convenience init(account: Account, feedlyUserId: String, caller: FeedlyAPICaller, database: SyncDatabase, lastSuccessfulFetchStartDate: Date?, downloadProgress: DownloadProgress) {
|
||||
self.init(account: account, feedlyUserId: feedlyUserId, lastSuccessfulFetchStartDate: lastSuccessfulFetchStartDate, markArticlesService: caller, getUnreadService: caller, getCollectionsService: caller, getStreamContentsService: caller, getStarredService: caller, getStreamIdsService: caller, getEntriesService: caller, database: database, downloadProgress: downloadProgress)
|
||||
}
|
||||
|
||||
override func run() {
|
||||
os_log(.debug, log: log, "Starting sync %{public}@", syncUUID.uuidString)
|
||||
Feedly.logger.info("Feedly: Starting sync \(self.syncUUID.uuidString, privacy: .public)")
|
||||
operationQueue.resume()
|
||||
}
|
||||
|
||||
override func didCancel() {
|
||||
os_log(.debug, log: log, "Cancelling sync %{public}@", syncUUID.uuidString)
|
||||
Feedly.logger.info("Feedly: Canceling sync \(self.syncUUID.uuidString, privacy: .public)")
|
||||
self.operationQueue.cancelAllOperations()
|
||||
syncCompletionHandler = nil
|
||||
super.didCancel()
|
||||
@@ -147,8 +146,8 @@ extension FeedlySyncAllOperation: FeedlyCheckpointOperationDelegate {
|
||||
|
||||
func feedlyCheckpointOperationDidReachCheckpoint(_ operation: FeedlyCheckpointOperation) {
|
||||
assert(Thread.isMainThread)
|
||||
os_log(.debug, log: self.log, "Sync completed: %{public}@", syncUUID.uuidString)
|
||||
|
||||
Feedly.logger.info("Feedly: Sync finished \(self.syncUUID.uuidString, privacy: .public)")
|
||||
|
||||
syncCompletionHandler?(.success(()))
|
||||
syncCompletionHandler = nil
|
||||
|
||||
@@ -162,8 +161,8 @@ extension FeedlySyncAllOperation: FeedlyOperationDelegate {
|
||||
assert(Thread.isMainThread)
|
||||
|
||||
// Having this log is useful for debugging missing required JSON keys in the response from Feedly, for example.
|
||||
os_log(.debug, log: log, "%{public}@ failed with error: %{public}@.", String(describing: operation), error as NSError)
|
||||
|
||||
Feedly.logger.error("Feedly: Sync \(self.syncUUID.uuidString, privacy: .public) failed with error: \(error.localizedDescription)")
|
||||
|
||||
syncCompletionHandler?(.failure(error))
|
||||
syncCompletionHandler = nil
|
||||
|
||||
|
||||
+14
-17
@@ -21,17 +21,15 @@ final class FeedlySyncStreamContentsOperation: FeedlyOperation, FeedlyOperationD
|
||||
private let service: FeedlyGetStreamContentsService
|
||||
private let newerThan: Date?
|
||||
private let isPagingEnabled: Bool
|
||||
private let log: OSLog
|
||||
private let finishOperation: FeedlyCheckpointOperation
|
||||
|
||||
init(account: Account, resource: FeedlyResourceId, service: FeedlyGetStreamContentsService, isPagingEnabled: Bool, newerThan: Date?, log: OSLog) {
|
||||
init(account: Account, resource: FeedlyResourceId, service: FeedlyGetStreamContentsService, isPagingEnabled: Bool, newerThan: Date?) {
|
||||
self.account = account
|
||||
self.resource = resource
|
||||
self.service = service
|
||||
self.isPagingEnabled = isPagingEnabled
|
||||
self.operationQueue.suspend()
|
||||
self.newerThan = newerThan
|
||||
self.log = log
|
||||
self.finishOperation = FeedlyCheckpointOperation()
|
||||
|
||||
super.init()
|
||||
@@ -41,9 +39,9 @@ final class FeedlySyncStreamContentsOperation: FeedlyOperation, FeedlyOperationD
|
||||
enqueueOperations(for: nil)
|
||||
}
|
||||
|
||||
convenience init(account: Account, credentials: Credentials, service: FeedlyGetStreamContentsService, newerThan: Date?, log: OSLog) {
|
||||
convenience init(account: Account, credentials: Credentials, service: FeedlyGetStreamContentsService, newerThan: Date?) {
|
||||
let all = FeedlyCategoryResourceId.Global.all(for: credentials.username)
|
||||
self.init(account: account, resource: all, service: service, isPagingEnabled: true, newerThan: newerThan, log: log)
|
||||
self.init(account: account, resource: all, service: service, isPagingEnabled: true, newerThan: newerThan)
|
||||
}
|
||||
|
||||
override func run() {
|
||||
@@ -51,13 +49,13 @@ final class FeedlySyncStreamContentsOperation: FeedlyOperation, FeedlyOperationD
|
||||
}
|
||||
|
||||
override func didCancel() {
|
||||
os_log(.debug, log: log, "Canceling sync stream contents for %{public}@", resource.id)
|
||||
Feedly.logger.info("Feedly: Canceling sync stream contents for \(self.resource.id)")
|
||||
operationQueue.cancelAllOperations()
|
||||
super.didCancel()
|
||||
}
|
||||
|
||||
func enqueueOperations(for continuation: String?) {
|
||||
os_log(.debug, log: log, "Requesting page for %{public}@", resource.id)
|
||||
Feedly.logger.info("Feedly: Requesting page for \(self.resource.id)")
|
||||
let operations = pageOperations(for: continuation)
|
||||
operationQueue.addOperations(operations)
|
||||
}
|
||||
@@ -67,13 +65,12 @@ final class FeedlySyncStreamContentsOperation: FeedlyOperation, FeedlyOperationD
|
||||
resource: resource,
|
||||
service: service,
|
||||
continuation: continuation,
|
||||
newerThan: newerThan,
|
||||
log: log)
|
||||
newerThan: newerThan)
|
||||
|
||||
|
||||
let organiseByFeed = FeedlyOrganiseParsedItemsByFeedOperation(account: account, parsedItemProvider: getPage, log: log)
|
||||
let organiseByFeed = FeedlyOrganiseParsedItemsByFeedOperation(account: account, parsedItemProvider: getPage)
|
||||
|
||||
let updateAccount = FeedlyUpdateAccountFeedsWithItemsOperation(account: account, organisedItemsProvider: organiseByFeed, log: log)
|
||||
let updateAccount = FeedlyUpdateAccountFeedsWithItemsOperation(account: account, organisedItemsProvider: organiseByFeed)
|
||||
|
||||
getPage.delegate = self
|
||||
getPage.streamDelegate = self
|
||||
@@ -91,14 +88,14 @@ final class FeedlySyncStreamContentsOperation: FeedlyOperation, FeedlyOperationD
|
||||
|
||||
func feedlyGetStreamContentsOperation(_ operation: FeedlyGetStreamContentsOperation, didGetContentsOf stream: FeedlyStream) {
|
||||
guard !isCanceled else {
|
||||
os_log(.debug, log: log, "Cancelled requesting page for %{public}@", resource.id)
|
||||
Feedly.logger.info("Feedly: Canceled requesting page for \(self.resource.id)")
|
||||
return
|
||||
}
|
||||
|
||||
os_log(.debug, log: log, "Ingesting %i items from %{public}@", stream.items.count, stream.id)
|
||||
|
||||
|
||||
Feedly.logger.info("Feedly: Ingesting \(stream.items.count) items from \(stream.id)")
|
||||
|
||||
guard isPagingEnabled, let continuation = stream.continuation else {
|
||||
os_log(.debug, log: log, "Reached end of stream for %{public}@", stream.id)
|
||||
Feedly.logger.info("Feedly: Reached end of stream for \(stream.id)")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -106,7 +103,7 @@ final class FeedlySyncStreamContentsOperation: FeedlyOperation, FeedlyOperationD
|
||||
}
|
||||
|
||||
func feedlyCheckpointOperationDidReachCheckpoint(_ operation: FeedlyCheckpointOperation) {
|
||||
os_log(.debug, log: log, "Completed ingesting items from %{public}@", resource.id)
|
||||
Feedly.logger.info("Feedly: Finished ingesting items from \(self.resource.id)")
|
||||
didFinish()
|
||||
}
|
||||
|
||||
|
||||
+3
-5
@@ -15,12 +15,10 @@ final class FeedlyUpdateAccountFeedsWithItemsOperation: FeedlyOperation {
|
||||
|
||||
private let account: Account
|
||||
private let organisedItemsProvider: FeedlyParsedItemsByFeedProviding
|
||||
private let log: OSLog
|
||||
|
||||
init(account: Account, organisedItemsProvider: FeedlyParsedItemsByFeedProviding, log: OSLog) {
|
||||
init(account: Account, organisedItemsProvider: FeedlyParsedItemsByFeedProviding) {
|
||||
self.account = account
|
||||
self.organisedItemsProvider = organisedItemsProvider
|
||||
self.log = log
|
||||
}
|
||||
|
||||
override func run() {
|
||||
@@ -31,8 +29,8 @@ final class FeedlyUpdateAccountFeedsWithItemsOperation: FeedlyOperation {
|
||||
self.didFinish(with: error)
|
||||
return
|
||||
}
|
||||
|
||||
os_log(.debug, log: self.log, "Updated %i feeds for \"%@\"", webFeedIDsAndItems.count, self.organisedItemsProvider.parsedItemsByFeedProviderName)
|
||||
|
||||
Feedly.logger.info("Feedly: updated \(webFeedIDsAndItems.count) for \(self.organisedItemsProvider.parsedItemsByFeedProviderName)")
|
||||
self.didFinish()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import os.log
|
||||
import RSCore
|
||||
import RSParser
|
||||
import Articles
|
||||
@@ -21,8 +20,6 @@ public enum LocalAccountDelegateError: String, Error {
|
||||
|
||||
final class LocalAccountDelegate: AccountDelegate {
|
||||
|
||||
private var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "LocalAccount")
|
||||
|
||||
weak var account: Account?
|
||||
|
||||
lazy var refreshProgress: DownloadProgress = {
|
||||
|
||||
@@ -34,6 +34,8 @@ final class LocalAccountRefresher {
|
||||
|
||||
private var urlToFeedDictionary = [String: WebFeed]()
|
||||
|
||||
private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "LocalAccountRefresher")
|
||||
|
||||
public func refreshFeeds(_ feeds: Set<WebFeed>, completion: (() -> Void)? = nil) {
|
||||
|
||||
let filteredFeeds = feeds.filter { !Self.feedShouldBeSkipped($0) }
|
||||
@@ -172,7 +174,7 @@ private extension LocalAccountRefresher {
|
||||
|
||||
for badHost in badHosts {
|
||||
if lowercaseHost == badHost {
|
||||
os_log(.debug, "Dropping request because it‘s X/Twitter, which doesn’t provide feeds: \(feed.url)")
|
||||
Self.logger.info("Dropping request becasue it’s X/Twitter, which doesn’t provide feeds: \(feed.url)")
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -197,7 +199,7 @@ private extension LocalAccountRefresher {
|
||||
|
||||
if url.isOpenRSSOrgURL {
|
||||
if let cacheControlInfo = feed.cacheControlInfo, !cacheControlInfo.canResume {
|
||||
os_log(.debug, "Dropping request for Cache-Control reasons: \(feed.url)")
|
||||
Self.logger.info("Dropping request for Cache-Control reasons: \(feed.url)")
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
+8
-8
@@ -18,7 +18,7 @@ import os.log
|
||||
extension NewsBlurAccountDelegate {
|
||||
|
||||
func refreshFeeds(for account: Account, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
os_log(.debug, log: log, "Refreshing feeds...")
|
||||
Self.logger.info("NewsBlur: Refreshing feeds")
|
||||
|
||||
caller.retrieveFeeds { result in
|
||||
switch result {
|
||||
@@ -39,7 +39,7 @@ extension NewsBlurAccountDelegate {
|
||||
guard let folders = folders else { return }
|
||||
assert(Thread.isMainThread)
|
||||
|
||||
os_log(.debug, log: log, "Syncing folders with %ld folders.", folders.count)
|
||||
Self.logger.info("NewsBlur: Syncing folders with \(folders.count) folders")
|
||||
|
||||
let folderNames = folders.map { $0.name }
|
||||
|
||||
@@ -77,7 +77,7 @@ extension NewsBlurAccountDelegate {
|
||||
guard let feeds = feeds else { return }
|
||||
assert(Thread.isMainThread)
|
||||
|
||||
os_log(.debug, log: log, "Syncing feeds with %ld feeds.", feeds.count)
|
||||
Self.logger.info("NewsBlur: Syncing feeds with \(feeds.count) feeds")
|
||||
|
||||
let newsBlurFeedIds = feeds.map { String($0.feedID) }
|
||||
|
||||
@@ -128,7 +128,7 @@ extension NewsBlurAccountDelegate {
|
||||
guard let folders = folders else { return }
|
||||
assert(Thread.isMainThread)
|
||||
|
||||
os_log(.debug, log: log, "Syncing folders with %ld folders.", folders.count)
|
||||
Self.logger.info("NewsBlur: Syncing folders with \(folders.count) folders")
|
||||
|
||||
// Set up some structures to make syncing easier
|
||||
let relationships = folders.map({ $0.asRelationships }).flatMap { $0 }
|
||||
@@ -251,7 +251,7 @@ extension NewsBlurAccountDelegate {
|
||||
}
|
||||
|
||||
self.refreshUnreadStories(for: account, hashes: Array(hashes[numberOfStories...]), updateFetchDate: date) { result in
|
||||
os_log(.debug, log: self.log, "Done refreshing stories.")
|
||||
Self.logger.info("NewsBlur: Finished refreshing stories")
|
||||
switch result {
|
||||
case .success:
|
||||
completion(.success(()))
|
||||
@@ -300,7 +300,7 @@ extension NewsBlurAccountDelegate {
|
||||
group.leave()
|
||||
case .failure(let error):
|
||||
errorOccurred = true
|
||||
os_log(.error, log: self.log, "Story status sync call failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("NewsBlur: Story status sync call failed: \(error.localizedDescription)")
|
||||
self.database.resetSelectedForProcessing(storyHashGroup.map { String($0) } )
|
||||
group.leave()
|
||||
}
|
||||
@@ -359,7 +359,7 @@ extension NewsBlurAccountDelegate {
|
||||
case .success(let pendingArticleIDs):
|
||||
process(pendingArticleIDs)
|
||||
case .failure(let error):
|
||||
os_log(.error, log: self.log, "Sync Story Read Status failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("NewsBlur: Sync Story Read Status failed: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -407,7 +407,7 @@ extension NewsBlurAccountDelegate {
|
||||
case .success(let pendingArticleIDs):
|
||||
process(pendingArticleIDs)
|
||||
case .failure(let error):
|
||||
os_log(.error, log: self.log, "Sync Story Starred Status failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("NewsBlur: Sync Story Starred Status failed: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// NewsBlur.swift
|
||||
// Account
|
||||
//
|
||||
// Created by Brent Simmons on 10/2/25.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import os.log
|
||||
|
||||
struct NewsBlur {
|
||||
|
||||
// Convention with this logger is to put "NewsBlur: " at the beginning of each message.
|
||||
static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "NewsBlur")
|
||||
}
|
||||
@@ -16,7 +16,6 @@ import os.log
|
||||
import Secrets
|
||||
|
||||
final class NewsBlurAccountDelegate: AccountDelegate {
|
||||
|
||||
var behaviors: AccountBehaviors = []
|
||||
|
||||
var isOPMLImportInProgress: Bool = false
|
||||
@@ -31,9 +30,10 @@ final class NewsBlurAccountDelegate: AccountDelegate {
|
||||
var refreshProgress = DownloadProgress(numberOfTasks: 0)
|
||||
|
||||
let caller: NewsBlurAPICaller
|
||||
let log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "NewsBlur")
|
||||
let database: SyncDatabase
|
||||
|
||||
static let logger = NewsBlur.logger
|
||||
|
||||
init(dataFolder: String, transport: Transport?) {
|
||||
if let transport = transport {
|
||||
caller = NewsBlurAPICaller(transport: transport)
|
||||
@@ -136,7 +136,7 @@ final class NewsBlurAccountDelegate: AccountDelegate {
|
||||
}
|
||||
|
||||
func sendArticleStatus(for account: Account, completion: @escaping (Result<Void, Error>) -> ()) {
|
||||
os_log(.debug, log: log, "Sending story statuses...")
|
||||
Self.logger.info("NewsBlur: Sending story statuses")
|
||||
|
||||
database.selectForProcessing { result in
|
||||
|
||||
@@ -190,7 +190,7 @@ final class NewsBlurAccountDelegate: AccountDelegate {
|
||||
}
|
||||
|
||||
group.notify(queue: DispatchQueue.main) {
|
||||
os_log(.debug, log: self.log, "Done sending article statuses.")
|
||||
Self.logger.info("NewsBlur: Finished sending article statuses")
|
||||
if errorOccurred {
|
||||
completion(.failure(NewsBlurError.unknown))
|
||||
} else {
|
||||
@@ -209,7 +209,7 @@ final class NewsBlurAccountDelegate: AccountDelegate {
|
||||
}
|
||||
|
||||
func refreshArticleStatus(for account: Account, completion: @escaping (Result<Void, Error>) -> ()) {
|
||||
os_log(.debug, log: log, "Refreshing story statuses...")
|
||||
Self.logger.info("NewsBlur: Refreshing story statuses")
|
||||
|
||||
let group = DispatchGroup()
|
||||
var errorOccurred = false
|
||||
@@ -223,7 +223,7 @@ final class NewsBlurAccountDelegate: AccountDelegate {
|
||||
}
|
||||
case .failure(let error):
|
||||
errorOccurred = true
|
||||
os_log(.info, log: self.log, "Retrieving unread stories failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("NewsBlur: error retrieving unread stories: \(error.localizedDescription)")
|
||||
group.leave()
|
||||
}
|
||||
}
|
||||
@@ -237,13 +237,13 @@ final class NewsBlurAccountDelegate: AccountDelegate {
|
||||
}
|
||||
case .failure(let error):
|
||||
errorOccurred = true
|
||||
os_log(.info, log: self.log, "Retrieving starred stories failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("NewsBlur: error retrieving starred stories: \(error.localizedDescription)")
|
||||
group.leave()
|
||||
}
|
||||
}
|
||||
|
||||
group.notify(queue: DispatchQueue.main) {
|
||||
os_log(.debug, log: self.log, "Done refreshing article statuses.")
|
||||
Self.logger.info("NewsBlur: Finished refreshing article statuses")
|
||||
if errorOccurred {
|
||||
completion(.failure(NewsBlurError.unknown))
|
||||
} else {
|
||||
@@ -253,8 +253,7 @@ final class NewsBlurAccountDelegate: AccountDelegate {
|
||||
}
|
||||
|
||||
func refreshStories(for account: Account, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
os_log(.debug, log: log, "Refreshing stories...")
|
||||
os_log(.debug, log: log, "Refreshing unread stories...")
|
||||
Self.logger.info("NewsBlur: Refreshing stories and unread stories")
|
||||
|
||||
caller.retrieveUnreadStoryHashes { result in
|
||||
switch result {
|
||||
@@ -272,7 +271,7 @@ final class NewsBlurAccountDelegate: AccountDelegate {
|
||||
}
|
||||
|
||||
func refreshMissingStories(for account: Account, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
os_log(.debug, log: log, "Refreshing missing stories...")
|
||||
Self.logger.info("NewsBlur: Refreshing missing stories")
|
||||
|
||||
account.fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDate { result in
|
||||
|
||||
@@ -299,7 +298,7 @@ final class NewsBlurAccountDelegate: AccountDelegate {
|
||||
}
|
||||
case .failure(let error):
|
||||
errorOccurred = true
|
||||
os_log(.error, log: self.log, "Refresh missing stories failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("NewsBlur: Refresh missing stories failed: \(error.localizedDescription)")
|
||||
group.leave()
|
||||
}
|
||||
}
|
||||
@@ -307,7 +306,7 @@ final class NewsBlurAccountDelegate: AccountDelegate {
|
||||
|
||||
group.notify(queue: DispatchQueue.main) {
|
||||
self.refreshProgress.completeTask()
|
||||
os_log(.debug, log: self.log, "Done refreshing missing stories.")
|
||||
Self.logger.info("NewsBlur: Finished refreshing missing stories.")
|
||||
if errorOccurred {
|
||||
completion(.failure(NewsBlurError.unknown))
|
||||
} else {
|
||||
@@ -571,12 +570,12 @@ final class NewsBlurAccountDelegate: AccountDelegate {
|
||||
case .success:
|
||||
break
|
||||
case .failure(let error):
|
||||
os_log(.error, log: self.log, "Restore folder feed error: %@.", error.localizedDescription)
|
||||
Self.logger.error("NewsBlur: Restore folder feed error: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
}
|
||||
case .failure(let error):
|
||||
os_log(.error, log: self.log, "Restore folder feed error: %@.", error.localizedDescription)
|
||||
Self.logger.error("NewsBlur: Restore folder feed error: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,9 +12,6 @@ import RSCore
|
||||
import RSParser
|
||||
|
||||
final class OPMLFile {
|
||||
|
||||
private var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "opmlFile")
|
||||
|
||||
private let fileURL: URL
|
||||
private let account: Account
|
||||
|
||||
@@ -24,6 +21,7 @@ final class OPMLFile {
|
||||
}
|
||||
}
|
||||
private let saveQueue = CoalescingQueue(name: "Save Queue", interval: 0.5)
|
||||
private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "OPMLFile")
|
||||
|
||||
init(filename: String, account: Account) {
|
||||
self.fileURL = URL(fileURLWithPath: filename)
|
||||
@@ -51,7 +49,7 @@ final class OPMLFile {
|
||||
do {
|
||||
try opmlDocumentString.write(to: fileURL, atomically: true, encoding: .utf8)
|
||||
} catch let error as NSError {
|
||||
os_log(.error, log: log, "OPML save to disk failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("OPML save to disk failed: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +74,7 @@ private extension OPMLFile {
|
||||
do {
|
||||
fileData = try Data(contentsOf: fileURL)
|
||||
} catch {
|
||||
os_log(.error, log: log, "OPML read from disk failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("OPML read from disk failed: \(error.localizedDescription)")
|
||||
}
|
||||
|
||||
return fileData
|
||||
@@ -89,7 +87,7 @@ private extension OPMLFile {
|
||||
do {
|
||||
opmlDocument = try RSOPMLParser.parseOPML(with: parserData)
|
||||
} catch {
|
||||
os_log(.error, log: log, "OPML Import failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("OPML import failed: \(error.localizedDescription)")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -121,5 +119,4 @@ private extension OPMLFile {
|
||||
let opml = openingText + middleText + closingText
|
||||
return opml
|
||||
}
|
||||
|
||||
}
|
||||
@@ -41,7 +41,7 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
|
||||
private let database: SyncDatabase
|
||||
|
||||
private let caller: ReaderAPICaller
|
||||
private var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "ReaderAPI")
|
||||
private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "ReaderAPI")
|
||||
|
||||
var behaviors: AccountBehaviors {
|
||||
var behaviors: AccountBehaviors = [.disallowOPMLImports, .disallowFeedInMultipleFolders]
|
||||
@@ -199,7 +199,7 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
|
||||
}
|
||||
|
||||
func sendArticleStatus(for account: Account, completion: @escaping ((Result<Void, Error>) -> Void)) {
|
||||
os_log(.debug, log: log, "Sending article statuses...")
|
||||
Self.logger.info("ReaderAPI: Sending article statuses")
|
||||
|
||||
database.selectForProcessing { result in
|
||||
|
||||
@@ -232,7 +232,7 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
|
||||
}
|
||||
|
||||
group.notify(queue: DispatchQueue.main) {
|
||||
os_log(.debug, log: self.log, "Done sending article statuses.")
|
||||
Self.logger.info("ReaderAPI: finished sending article statuses")
|
||||
completion(.success(()))
|
||||
}
|
||||
}
|
||||
@@ -247,7 +247,7 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
|
||||
}
|
||||
|
||||
func refreshArticleStatus(for account: Account, completion: @escaping ((Result<Void, Error>) -> Void)) {
|
||||
os_log(.debug, log: log, "Refreshing article statuses...")
|
||||
Self.logger.info("ReaderAPI: Refreshing article statuses")
|
||||
|
||||
let group = DispatchGroup()
|
||||
var errorOccurred = false
|
||||
@@ -261,7 +261,7 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
|
||||
}
|
||||
case .failure(let error):
|
||||
errorOccurred = true
|
||||
os_log(.info, log: self.log, "Retrieving unread entries failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("ReaderAPI: Retrieving unread entries failed: \(error.localizedDescription)")
|
||||
group.leave()
|
||||
}
|
||||
|
||||
@@ -276,14 +276,14 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
|
||||
}
|
||||
case .failure(let error):
|
||||
errorOccurred = true
|
||||
os_log(.info, log: self.log, "Retrieving starred entries failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("ReaderAPI: Retrieving starred entries failed: \(error.localizedDescription)")
|
||||
group.leave()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
group.notify(queue: DispatchQueue.main) {
|
||||
os_log(.debug, log: self.log, "Done refreshing article statuses.")
|
||||
Self.logger.info("ReaderAPI: Finished refreshing article statuses")
|
||||
if errorOccurred {
|
||||
completion(.failure(ReaderAPIAccountDelegateError.unknown))
|
||||
} else {
|
||||
@@ -345,7 +345,7 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
|
||||
self.clearFolderRelationship(for: feed, folderExternalID: folder.externalID)
|
||||
}
|
||||
case .failure(let error):
|
||||
os_log(.error, log: self.log, "Remove feed error: %@.", error.localizedDescription)
|
||||
Self.logger.error("ReaderAPI: Remove feed error: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -364,14 +364,11 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
|
||||
account.clearWebFeedMetadata(feed)
|
||||
}
|
||||
case .failure(let error):
|
||||
os_log(.error, log: self.log, "Remove feed error: %@.", error.localizedDescription)
|
||||
Self.logger.error("ReaderAPI: Remove feed error: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
group.notify(queue: DispatchQueue.main) {
|
||||
@@ -390,7 +387,6 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func createWebFeed(for account: Account, url: String, name: String?, container: Container, validateFeed: Bool, completion: @escaping (Result<WebFeed, Error>) -> Void) {
|
||||
@@ -596,17 +592,15 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
|
||||
case .success:
|
||||
break
|
||||
case .failure(let error):
|
||||
os_log(.error, log: self.log, "Restore folder feed error: %@.", error.localizedDescription)
|
||||
Self.logger.error("ReaderAPI: Restore folder feed error: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
group.notify(queue: DispatchQueue.main) {
|
||||
account.addFolder(folder)
|
||||
completion(.success(()))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func markArticles(for account: Account, articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
@@ -713,8 +707,8 @@ private extension ReaderAPIAccountDelegate {
|
||||
}
|
||||
|
||||
guard !folderTags.isEmpty else { return }
|
||||
|
||||
os_log(.debug, log: log, "Syncing folders with %ld tags.", folderTags.count)
|
||||
|
||||
Self.logger.info("ReaderAPI: Syncing folders with \(folderTags.count) tags")
|
||||
|
||||
let readerFolderExternalIDs = folderTags.compactMap { $0.tagID }
|
||||
|
||||
@@ -754,8 +748,8 @@ private extension ReaderAPIAccountDelegate {
|
||||
guard let subscriptions = subscriptions else { return }
|
||||
assert(Thread.isMainThread)
|
||||
|
||||
os_log(.debug, log: log, "Syncing feeds with %ld subscriptions.", subscriptions.count)
|
||||
|
||||
Self.logger.info("ReaderAPI: Syncing feeds with \(subscriptions.count) subscriptions")
|
||||
|
||||
let subFeedIds = subscriptions.map { $0.feedID }
|
||||
|
||||
// Remove any feeds that are no longer in the subscriptions
|
||||
@@ -796,8 +790,8 @@ private extension ReaderAPIAccountDelegate {
|
||||
func syncFeedFolderRelationship(_ account: Account, _ subscriptions: [ReaderAPISubscription]?) {
|
||||
guard let subscriptions = subscriptions else { return }
|
||||
assert(Thread.isMainThread)
|
||||
os_log(.debug, log: log, "Syncing taggings with %ld subscriptions.", subscriptions.count)
|
||||
|
||||
Self.logger.info("ReaderAPI: Syncing taggings with \(subscriptions.count) subscriptions")
|
||||
|
||||
// Set up some structures to make syncing easier
|
||||
let folderDict = externalIDToFolderDictionary(with: account.folders)
|
||||
let taggingsDict = subscriptions.reduce([String: [ReaderAPISubscription]]()) { (dict, subscription) in
|
||||
@@ -890,7 +884,7 @@ private extension ReaderAPIAccountDelegate {
|
||||
self.database.deleteSelectedForProcessing(articleIDGroup.map { $0 } )
|
||||
group.leave()
|
||||
case .failure(let error):
|
||||
os_log(.error, log: self.log, "Article status sync call failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("ReaderAPI: Article status sync call failed: \(error.localizedDescription)")
|
||||
self.database.resetSelectedForProcessing(articleIDGroup.map { $0 } )
|
||||
group.leave()
|
||||
}
|
||||
@@ -989,8 +983,8 @@ private extension ReaderAPIAccountDelegate {
|
||||
completion()
|
||||
return
|
||||
}
|
||||
|
||||
os_log(.debug, log: self.log, "Refreshing missing articles...")
|
||||
|
||||
Self.logger.info("ReaderAPI: Refreshing missing articles")
|
||||
let group = DispatchGroup()
|
||||
|
||||
let articleIDs = Array(fetchedArticleIDs)
|
||||
@@ -1010,7 +1004,7 @@ private extension ReaderAPIAccountDelegate {
|
||||
}
|
||||
|
||||
case .failure(let error):
|
||||
os_log(.error, log: self.log, "Refresh missing articles failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("ReaderAPI: Refresh missing articles failed: \(error.localizedDescription)")
|
||||
group.leave()
|
||||
}
|
||||
}
|
||||
@@ -1018,7 +1012,7 @@ private extension ReaderAPIAccountDelegate {
|
||||
|
||||
group.notify(queue: DispatchQueue.main) {
|
||||
self.refreshProgress.completeTask()
|
||||
os_log(.debug, log: self.log, "Done refreshing missing articles.")
|
||||
Self.logger.info("ReaderAPI: Finished refreshing missing articles")
|
||||
completion()
|
||||
}
|
||||
}
|
||||
@@ -1124,11 +1118,9 @@ private extension ReaderAPIAccountDelegate {
|
||||
case .success(let pendingArticleIDs):
|
||||
process(pendingArticleIDs)
|
||||
case .failure(let error):
|
||||
os_log(.error, log: self.log, "Sync Article Read Status failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("ReaderAPI: Sync article read status failed: \(error.localizedDescription)")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func syncArticleStarredState(account: Account, articleIDs: [String]?, completion: @escaping (() -> Void)) {
|
||||
@@ -1173,11 +1165,8 @@ private extension ReaderAPIAccountDelegate {
|
||||
case .success(let pendingArticleIDs):
|
||||
process(pendingArticleIDs)
|
||||
case .failure(let error):
|
||||
os_log(.error, log: self.log, "Sync Article Starred Status failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("ReaderAPI: Sync article starred status failed: \(error.localizedDescription)")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,9 +11,6 @@ import os.log
|
||||
import RSCore
|
||||
|
||||
final class WebFeedMetadataFile {
|
||||
|
||||
private var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "webFeedMetadataFile")
|
||||
|
||||
private let fileURL: URL
|
||||
private let account: Account
|
||||
|
||||
@@ -22,17 +19,19 @@ final class WebFeedMetadataFile {
|
||||
queueSaveToDiskIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
private let saveQueue = CoalescingQueue(name: "Save Queue", interval: 0.5)
|
||||
static private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "WebFeedMetadataFile")
|
||||
|
||||
init(filename: String, account: Account) {
|
||||
self.fileURL = URL(fileURLWithPath: filename)
|
||||
self.account = account
|
||||
}
|
||||
|
||||
|
||||
func markAsDirty() {
|
||||
isDirty = true
|
||||
}
|
||||
|
||||
|
||||
func load() {
|
||||
if let fileData = try? Data(contentsOf: fileURL) {
|
||||
let decoder = PropertyListDecoder()
|
||||
@@ -40,10 +39,10 @@ final class WebFeedMetadataFile {
|
||||
}
|
||||
account.webFeedMetadata.values.forEach { $0.delegate = account }
|
||||
}
|
||||
|
||||
|
||||
func save() {
|
||||
guard !account.isDeleted else { return }
|
||||
|
||||
|
||||
let feedMetadata = metadataForOnlySubscribedToFeeds()
|
||||
|
||||
let encoder = PropertyListEncoder()
|
||||
@@ -53,10 +52,9 @@ final class WebFeedMetadataFile {
|
||||
let data = try encoder.encode(feedMetadata)
|
||||
try data.write(to: fileURL)
|
||||
} catch let error as NSError {
|
||||
os_log(.error, log: log, "Save to disk failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("Save WebFeedMetadataFile file to disk failed: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private extension WebFeedMetadataFile {
|
||||
@@ -78,5 +76,4 @@ private extension WebFeedMetadataFile {
|
||||
return webFeedIDs.contains(metadata.webFeedID)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+3
-3
@@ -53,7 +53,7 @@ final class FeedlyCreateFeedsForCollectionFoldersOperationTests: XCTestCase {
|
||||
return (feeds, accountFolder)
|
||||
}
|
||||
|
||||
let createFeeds = FeedlyCreateFeedsForCollectionFoldersOperation(account: account, feedsAndFoldersProvider: provider, log: support.log)
|
||||
let createFeeds = FeedlyCreateFeedsForCollectionFoldersOperation(account: account, feedsAndFoldersProvider: provider)
|
||||
let completionExpectation = expectation(description: "Did Finish")
|
||||
createFeeds.completionBlock = { _ in
|
||||
completionExpectation.fulfill()
|
||||
@@ -124,7 +124,7 @@ final class FeedlyCreateFeedsForCollectionFoldersOperationTests: XCTestCase {
|
||||
return (feeds, accountFolder)
|
||||
}
|
||||
|
||||
let createFeeds = FeedlyCreateFeedsForCollectionFoldersOperation(account: account, feedsAndFoldersProvider: provider, log: support.log)
|
||||
let createFeeds = FeedlyCreateFeedsForCollectionFoldersOperation(account: account, feedsAndFoldersProvider: provider)
|
||||
let completionExpectation = expectation(description: "Did Finish")
|
||||
createFeeds.completionBlock = { _ in
|
||||
completionExpectation.fulfill()
|
||||
@@ -148,7 +148,7 @@ final class FeedlyCreateFeedsForCollectionFoldersOperationTests: XCTestCase {
|
||||
return (feeds, accountFolder)
|
||||
}
|
||||
|
||||
let removeFeeds = FeedlyCreateFeedsForCollectionFoldersOperation(account: account, feedsAndFoldersProvider: provider, log: support.log)
|
||||
let removeFeeds = FeedlyCreateFeedsForCollectionFoldersOperation(account: account, feedsAndFoldersProvider: provider)
|
||||
let completionExpectation = expectation(description: "Did Finish")
|
||||
removeFeeds.completionBlock = { _ in
|
||||
completionExpectation.fulfill()
|
||||
|
||||
@@ -19,7 +19,7 @@ final class FeedlyGetCollectionsOperationTests: XCTestCase {
|
||||
let jsonName = "JSON/feedly_collections_initial"
|
||||
transport.testFiles["/v3/collections"] = "\(jsonName).json"
|
||||
|
||||
let getCollections = FeedlyGetCollectionsOperation(service: caller, log: support.log)
|
||||
let getCollections = FeedlyGetCollectionsOperation(service: caller)
|
||||
let completionExpectation = expectation(description: "Did Finish")
|
||||
getCollections.completionBlock = { _ in
|
||||
completionExpectation.fulfill()
|
||||
@@ -71,11 +71,10 @@ final class FeedlyGetCollectionsOperationTests: XCTestCase {
|
||||
let delegate = TestDelegate()
|
||||
delegate.errorExpectation = expectation(description: "Did Fail With Expected Error")
|
||||
|
||||
let support = FeedlyTestSupport()
|
||||
let service = TestGetCollectionsService()
|
||||
service.mockResult = .failure(URLError(.timedOut))
|
||||
|
||||
let getCollections = FeedlyGetCollectionsOperation(service: service, log: support.log)
|
||||
let getCollections = FeedlyGetCollectionsOperation(service: service)
|
||||
getCollections.delegate = delegate
|
||||
|
||||
let completionExpectation = expectation(description: "Did Finish")
|
||||
|
||||
+3
-3
@@ -31,7 +31,7 @@ final class FeedlyGetStreamContentsOperationTests: XCTestCase {
|
||||
let service = TestGetStreamContentsService()
|
||||
let resource = FeedlyCategoryResourceId(id: "user/1234/category/5678")
|
||||
|
||||
let getStreamContents = FeedlyGetStreamContentsOperation(account: account, resource: resource, service: service, continuation: nil, newerThan: nil, unreadOnly: nil, log: support.log)
|
||||
let getStreamContents = FeedlyGetStreamContentsOperation(account: account, resource: resource, service: service, continuation: nil, newerThan: nil, unreadOnly: nil)
|
||||
|
||||
service.mockResult = .failure(URLError(.fileDoesNotExist))
|
||||
|
||||
@@ -55,7 +55,7 @@ final class FeedlyGetStreamContentsOperationTests: XCTestCase {
|
||||
let newerThan: Date? = Date(timeIntervalSinceReferenceDate: 86)
|
||||
let unreadOnly: Bool? = true
|
||||
|
||||
let getStreamContents = FeedlyGetStreamContentsOperation(account: account, resource: resource, service: service, continuation: continuation, newerThan: newerThan, unreadOnly: unreadOnly, log: support.log)
|
||||
let getStreamContents = FeedlyGetStreamContentsOperation(account: account, resource: resource, service: service, continuation: continuation, newerThan: newerThan, unreadOnly: unreadOnly)
|
||||
|
||||
let mockStream = FeedlyStream(id: "stream/1", updated: nil, continuation: nil, items: [])
|
||||
service.mockResult = .success(mockStream)
|
||||
@@ -98,7 +98,7 @@ final class FeedlyGetStreamContentsOperationTests: XCTestCase {
|
||||
transport.testFiles["/v3/streams/contents"] = "\(jsonName).json"
|
||||
|
||||
let resource = FeedlyCategoryResourceId(id: "user/f2f031bd-f3e3-4893-a447-467a291c6d1e/category/5ca4d61d-e55d-4999-a8d1-c3b9d8789815")
|
||||
let getStreamContents = FeedlyGetStreamContentsOperation(account: account, resource: resource, service: caller, continuation: nil, newerThan: nil, unreadOnly: nil, log: support.log)
|
||||
let getStreamContents = FeedlyGetStreamContentsOperation(account: account, resource: resource, service: caller, continuation: nil, newerThan: nil, unreadOnly: nil)
|
||||
|
||||
let completionExpectation = expectation(description: "Did Finish")
|
||||
getStreamContents.completionBlock = { _ in
|
||||
|
||||
@@ -31,7 +31,7 @@ final class FeedlyGetStreamIdsOperationTests: XCTestCase {
|
||||
let service = TestGetStreamIdsService()
|
||||
let resource = FeedlyCategoryResourceId(id: "user/1234/category/5678")
|
||||
|
||||
let getStreamIds = FeedlyGetStreamIdsOperation(account: account, resource: resource, service: service, continuation: nil, newerThan: nil, unreadOnly: nil, log: support.log)
|
||||
let getStreamIds = FeedlyGetStreamIdsOperation(account: account, resource: resource, service: service, continuation: nil, newerThan: nil, unreadOnly: nil)
|
||||
|
||||
service.mockResult = .failure(URLError(.fileDoesNotExist))
|
||||
|
||||
@@ -55,7 +55,7 @@ final class FeedlyGetStreamIdsOperationTests: XCTestCase {
|
||||
let newerThan: Date? = Date(timeIntervalSinceReferenceDate: 1000)
|
||||
let unreadOnly: Bool? = false
|
||||
|
||||
let getStreamIds = FeedlyGetStreamIdsOperation(account: account, resource: resource, service: service, continuation: continuation, newerThan: newerThan, unreadOnly: unreadOnly, log: support.log)
|
||||
let getStreamIds = FeedlyGetStreamIdsOperation(account: account, resource: resource, service: service, continuation: continuation, newerThan: newerThan, unreadOnly: unreadOnly)
|
||||
|
||||
let mockStreamIds = FeedlyStreamIds(continuation: "1234", ids: ["item/1", "item/2", "item/3"])
|
||||
service.mockResult = .success(mockStreamIds)
|
||||
@@ -93,7 +93,7 @@ final class FeedlyGetStreamIdsOperationTests: XCTestCase {
|
||||
transport.testFiles["/v3/streams/ids"] = "\(jsonName).json"
|
||||
|
||||
let resource = FeedlyCategoryResourceId(id: "user/1234/category/5678")
|
||||
let getStreamIds = FeedlyGetStreamIdsOperation(account: account, resource: resource, service: caller, continuation: nil, newerThan: nil, unreadOnly: nil, log: support.log)
|
||||
let getStreamIds = FeedlyGetStreamIdsOperation(account: account, resource: resource, service: caller, continuation: nil, newerThan: nil, unreadOnly: nil)
|
||||
|
||||
let completionExpectation = expectation(description: "Did Finish")
|
||||
getStreamIds.completionBlock = { _ in
|
||||
|
||||
@@ -66,7 +66,7 @@ final class FeedlyLogoutOperationTests: XCTestCase {
|
||||
return
|
||||
}
|
||||
|
||||
let logout = FeedlyLogoutOperation(account: account, service: service, log: support.log)
|
||||
let logout = FeedlyLogoutOperation(account: account, service: service)
|
||||
|
||||
// If this expectation is not fulfilled, the operation is not calling `didFinish`.
|
||||
let completionExpectation = expectation(description: "Did Finish")
|
||||
@@ -98,7 +98,7 @@ final class FeedlyLogoutOperationTests: XCTestCase {
|
||||
service.logoutExpectation = expectation(description: "Did Call Logout")
|
||||
service.mockResult = .success(())
|
||||
|
||||
let logout = FeedlyLogoutOperation(account: account, service: service, log: support.log)
|
||||
let logout = FeedlyLogoutOperation(account: account, service: service)
|
||||
|
||||
// If this expectation is not fulfilled, the operation is not calling `didFinish`.
|
||||
let completionExpectation = expectation(description: "Did Finish")
|
||||
@@ -139,7 +139,7 @@ final class FeedlyLogoutOperationTests: XCTestCase {
|
||||
let (_, service) = support.makeMockNetworkStack()
|
||||
service.credentials = nil
|
||||
|
||||
let logout = FeedlyLogoutOperation(account: account, service: service, log: support.log)
|
||||
let logout = FeedlyLogoutOperation(account: account, service: service)
|
||||
|
||||
let delegate = TestLogoutDelegate()
|
||||
delegate.didFailExpectation = expectation(description: "Did Fail")
|
||||
@@ -190,7 +190,7 @@ final class FeedlyLogoutOperationTests: XCTestCase {
|
||||
return
|
||||
}
|
||||
|
||||
let logout = FeedlyLogoutOperation(account: account, service: service, log: support.log)
|
||||
let logout = FeedlyLogoutOperation(account: account, service: service)
|
||||
|
||||
// If this expectation is not fulfilled, the operation is not calling `didFinish`.
|
||||
let completionExpectation = expectation(description: "Did Finish")
|
||||
|
||||
+7
-7
@@ -36,7 +36,7 @@ final class FeedlyMirrorCollectionsAsFoldersOperationTests: XCTestCase {
|
||||
|
||||
func testAddsFolders() {
|
||||
let provider = CollectionsProvider()
|
||||
let mirrorOperation = FeedlyMirrorCollectionsAsFoldersOperation(account: account, collectionsProvider: provider, log: support.log)
|
||||
let mirrorOperation = FeedlyMirrorCollectionsAsFoldersOperation(account: account, collectionsProvider: provider)
|
||||
let completionExpectation = expectation(description: "Did Finish")
|
||||
mirrorOperation.completionBlock = { _ in
|
||||
completionExpectation.fulfill()
|
||||
@@ -65,7 +65,7 @@ final class FeedlyMirrorCollectionsAsFoldersOperationTests: XCTestCase {
|
||||
let provider = CollectionsProvider()
|
||||
|
||||
do {
|
||||
let addFolders = FeedlyMirrorCollectionsAsFoldersOperation(account: account, collectionsProvider: provider, log: support.log)
|
||||
let addFolders = FeedlyMirrorCollectionsAsFoldersOperation(account: account, collectionsProvider: provider)
|
||||
let completionExpectation = expectation(description: "Did Finish")
|
||||
addFolders.completionBlock = { _ in
|
||||
completionExpectation.fulfill()
|
||||
@@ -79,7 +79,7 @@ final class FeedlyMirrorCollectionsAsFoldersOperationTests: XCTestCase {
|
||||
// Now that the folders are added, remove them all.
|
||||
provider.collections = []
|
||||
|
||||
let removeFolders = FeedlyMirrorCollectionsAsFoldersOperation(account: account, collectionsProvider: provider, log: support.log)
|
||||
let removeFolders = FeedlyMirrorCollectionsAsFoldersOperation(account: account, collectionsProvider: provider)
|
||||
let completionExpectation = expectation(description: "Did Finish")
|
||||
removeFolders.completionBlock = { _ in
|
||||
completionExpectation.fulfill()
|
||||
@@ -126,7 +126,7 @@ final class FeedlyMirrorCollectionsAsFoldersOperationTests: XCTestCase {
|
||||
|
||||
func testFeedMappedToFolders() {
|
||||
let provider = CollectionsAndFeedsProvider()
|
||||
let mirrorOperation = FeedlyMirrorCollectionsAsFoldersOperation(account: account, collectionsProvider: provider, log: support.log)
|
||||
let mirrorOperation = FeedlyMirrorCollectionsAsFoldersOperation(account: account, collectionsProvider: provider)
|
||||
let completionExpectation = expectation(description: "Did Finish")
|
||||
mirrorOperation.completionBlock = { _ in
|
||||
completionExpectation.fulfill()
|
||||
@@ -166,9 +166,9 @@ final class FeedlyMirrorCollectionsAsFoldersOperationTests: XCTestCase {
|
||||
func testRemovingFolderRemovesFeeds() {
|
||||
do {
|
||||
let provider = CollectionsAndFeedsProvider()
|
||||
let addFoldersAndFeeds = FeedlyMirrorCollectionsAsFoldersOperation(account: account, collectionsProvider: provider, log: support.log)
|
||||
let addFoldersAndFeeds = FeedlyMirrorCollectionsAsFoldersOperation(account: account, collectionsProvider: provider)
|
||||
|
||||
let createFeeds = FeedlyCreateFeedsForCollectionFoldersOperation(account: account, feedsAndFoldersProvider: addFoldersAndFeeds, log: support.log)
|
||||
let createFeeds = FeedlyCreateFeedsForCollectionFoldersOperation(account: account, feedsAndFoldersProvider: addFoldersAndFeeds)
|
||||
MainThreadOperationQueue.shared.make(createFeeds, dependOn: addFoldersAndFeeds)
|
||||
|
||||
let completionExpectation = expectation(description: "Did Finish")
|
||||
@@ -187,7 +187,7 @@ final class FeedlyMirrorCollectionsAsFoldersOperationTests: XCTestCase {
|
||||
let provider = CollectionsProvider()
|
||||
provider.collections = []
|
||||
|
||||
let removeFolders = FeedlyMirrorCollectionsAsFoldersOperation(account: account, collectionsProvider: provider, log: support.log)
|
||||
let removeFolders = FeedlyMirrorCollectionsAsFoldersOperation(account: account, collectionsProvider: provider)
|
||||
let completionExpectation = expectation(description: "Did Finish")
|
||||
removeFolders.completionBlock = { _ in
|
||||
completionExpectation.fulfill()
|
||||
|
||||
+3
-3
@@ -40,7 +40,7 @@ final class FeedlyOrganiseParsedItemsByFeedOperationTests: XCTestCase {
|
||||
let parsedEntries = Set(entries.values.flatMap { $0 })
|
||||
let provider = TestParsedItemsProvider(resource: resource, parsedEntries: parsedEntries)
|
||||
|
||||
let organise = FeedlyOrganiseParsedItemsByFeedOperation(account: account, parsedItemProvider: provider, log: support.log)
|
||||
let organise = FeedlyOrganiseParsedItemsByFeedOperation(account: account, parsedItemProvider: provider)
|
||||
|
||||
let completionExpectation = expectation(description: "Did Finish")
|
||||
organise.completionBlock = { _ in
|
||||
@@ -61,7 +61,7 @@ final class FeedlyOrganiseParsedItemsByFeedOperationTests: XCTestCase {
|
||||
let parsedEntries = Set(entries.values.flatMap { $0 })
|
||||
let provider = TestParsedItemsProvider(resource: resource, parsedEntries: parsedEntries)
|
||||
|
||||
let organise = FeedlyOrganiseParsedItemsByFeedOperation(account: account, parsedItemProvider: provider, log: support.log)
|
||||
let organise = FeedlyOrganiseParsedItemsByFeedOperation(account: account, parsedItemProvider: provider)
|
||||
|
||||
let completionExpectation = expectation(description: "Did Finish")
|
||||
organise.completionBlock = { _ in
|
||||
@@ -82,7 +82,7 @@ final class FeedlyOrganiseParsedItemsByFeedOperationTests: XCTestCase {
|
||||
let parsedEntries = Set(entries.values.flatMap { $0 })
|
||||
let provider = TestParsedItemsProvider(resource: resource, parsedEntries: parsedEntries)
|
||||
|
||||
let organise = FeedlyOrganiseParsedItemsByFeedOperation(account: account, parsedItemProvider: provider, log: support.log)
|
||||
let organise = FeedlyOrganiseParsedItemsByFeedOperation(account: account, parsedItemProvider: provider)
|
||||
|
||||
let completionExpectation = expectation(description: "Did Finish")
|
||||
organise.completionBlock = { _ in
|
||||
|
||||
+5
-5
@@ -54,7 +54,7 @@ final class FeedlyRefreshAccessTokenOperationTests: XCTestCase {
|
||||
service.refreshAccessTokenExpectation?.isInverted = true
|
||||
|
||||
let client = support.makeMockOAuthClient()
|
||||
let refresh = FeedlyRefreshAccessTokenOperation(account: account, service: service, oauthClient: client, log: support.log)
|
||||
let refresh = FeedlyRefreshAccessTokenOperation(account: account, service: service, oauthClient: client)
|
||||
|
||||
// If this expectation is not fulfilled, the operation is not calling `didFinish`.
|
||||
let completionExpectation = expectation(description: "Did Finish")
|
||||
@@ -89,8 +89,8 @@ final class FeedlyRefreshAccessTokenOperationTests: XCTestCase {
|
||||
service.refreshAccessTokenExpectation?.isInverted = true
|
||||
|
||||
let client = support.makeMockOAuthClient()
|
||||
let refresh = FeedlyRefreshAccessTokenOperation(account: account, service: service, oauthClient: client, log: support.log)
|
||||
|
||||
let refresh = FeedlyRefreshAccessTokenOperation(account: account, service: service, oauthClient: client)
|
||||
|
||||
let delegate = TestRefreshTokenDelegate()
|
||||
delegate.didFailExpectation = expectation(description: "Did Fail")
|
||||
refresh.delegate = delegate
|
||||
@@ -140,7 +140,7 @@ final class FeedlyRefreshAccessTokenOperationTests: XCTestCase {
|
||||
XCTAssertEqual(serviceClient, client)
|
||||
}
|
||||
|
||||
let refresh = FeedlyRefreshAccessTokenOperation(account: account, service: service, oauthClient: client, log: support.log)
|
||||
let refresh = FeedlyRefreshAccessTokenOperation(account: account, service: service, oauthClient: client)
|
||||
|
||||
// If this expectation is not fulfilled, the operation is not calling `didFinish`.
|
||||
let completionExpectation = expectation(description: "Did Finish")
|
||||
@@ -194,7 +194,7 @@ final class FeedlyRefreshAccessTokenOperationTests: XCTestCase {
|
||||
XCTAssertEqual(serviceClient, client)
|
||||
}
|
||||
|
||||
let refresh = FeedlyRefreshAccessTokenOperation(account: account, service: service, oauthClient: client, log: support.log)
|
||||
let refresh = FeedlyRefreshAccessTokenOperation(account: account, service: service, oauthClient: client)
|
||||
|
||||
// If this expectation is not fulfilled, the operation is not calling `didFinish`.
|
||||
let completionExpectation = expectation(description: "Did Finish")
|
||||
|
||||
+11
-11
@@ -34,7 +34,7 @@ final class FeedlySendArticleStatusesOperationTests: XCTestCase {
|
||||
|
||||
func testSendEmpty() {
|
||||
let service = TestMarkArticlesService()
|
||||
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service, log: support.log)
|
||||
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service)
|
||||
|
||||
let didFinishExpectation = expectation(description: "Did Finish")
|
||||
send.completionBlock = { _ in
|
||||
@@ -65,7 +65,7 @@ final class FeedlySendArticleStatusesOperationTests: XCTestCase {
|
||||
XCTAssertEqual(action, .unread)
|
||||
}
|
||||
|
||||
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service, log: support.log)
|
||||
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service)
|
||||
|
||||
let didFinishExpectation = expectation(description: "Did Finish")
|
||||
send.completionBlock = { _ in
|
||||
@@ -108,7 +108,7 @@ final class FeedlySendArticleStatusesOperationTests: XCTestCase {
|
||||
XCTAssertEqual(action, .unread)
|
||||
}
|
||||
|
||||
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service, log: support.log)
|
||||
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service)
|
||||
|
||||
let didFinishExpectation = expectation(description: "Did Finish")
|
||||
send.completionBlock = { _ in
|
||||
@@ -151,7 +151,7 @@ final class FeedlySendArticleStatusesOperationTests: XCTestCase {
|
||||
XCTAssertEqual(action, .read)
|
||||
}
|
||||
|
||||
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service, log: support.log)
|
||||
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service)
|
||||
|
||||
let didFinishExpectation = expectation(description: "Did Finish")
|
||||
send.completionBlock = { _ in
|
||||
@@ -194,7 +194,7 @@ final class FeedlySendArticleStatusesOperationTests: XCTestCase {
|
||||
XCTAssertEqual(action, .read)
|
||||
}
|
||||
|
||||
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service, log: support.log)
|
||||
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service)
|
||||
|
||||
let didFinishExpectation = expectation(description: "Did Finish")
|
||||
send.completionBlock = { _ in
|
||||
@@ -237,7 +237,7 @@ final class FeedlySendArticleStatusesOperationTests: XCTestCase {
|
||||
XCTAssertEqual(action, .saved)
|
||||
}
|
||||
|
||||
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service, log: support.log)
|
||||
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service)
|
||||
|
||||
let didFinishExpectation = expectation(description: "Did Finish")
|
||||
send.completionBlock = { _ in
|
||||
@@ -280,7 +280,7 @@ final class FeedlySendArticleStatusesOperationTests: XCTestCase {
|
||||
XCTAssertEqual(action, .saved)
|
||||
}
|
||||
|
||||
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service, log: support.log)
|
||||
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service)
|
||||
|
||||
let didFinishExpectation = expectation(description: "Did Finish")
|
||||
send.completionBlock = { _ in
|
||||
@@ -323,7 +323,7 @@ final class FeedlySendArticleStatusesOperationTests: XCTestCase {
|
||||
XCTAssertEqual(action, .unsaved)
|
||||
}
|
||||
|
||||
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service, log: support.log)
|
||||
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service)
|
||||
|
||||
let didFinishExpectation = expectation(description: "Did Finish")
|
||||
send.completionBlock = { _ in
|
||||
@@ -366,7 +366,7 @@ final class FeedlySendArticleStatusesOperationTests: XCTestCase {
|
||||
XCTAssertEqual(action, .unsaved)
|
||||
}
|
||||
|
||||
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service, log: support.log)
|
||||
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service)
|
||||
|
||||
let didFinishExpectation = expectation(description: "Did Finish")
|
||||
send.completionBlock = { _ in
|
||||
@@ -426,7 +426,7 @@ final class FeedlySendArticleStatusesOperationTests: XCTestCase {
|
||||
let expectedArticleIds = Set(syncStatuses.map { $0.articleID })
|
||||
XCTAssertEqual(serviceArticleIds, expectedArticleIds)
|
||||
}
|
||||
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service, log: support.log)
|
||||
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service)
|
||||
|
||||
let didFinishExpectation = expectation(description: "Did Finish")
|
||||
send.completionBlock = { _ in
|
||||
@@ -487,7 +487,7 @@ final class FeedlySendArticleStatusesOperationTests: XCTestCase {
|
||||
XCTAssertEqual(serviceArticleIds, expectedArticleIds)
|
||||
}
|
||||
|
||||
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service, log: support.log)
|
||||
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service)
|
||||
|
||||
let didFinishExpectation = expectation(description: "Did Finish")
|
||||
send.completionBlock = { _ in
|
||||
|
||||
+3
-3
@@ -45,7 +45,7 @@ final class FeedlySyncStreamContentsOperationTests: XCTestCase {
|
||||
XCTAssertNil(serviceUnreadOnly)
|
||||
}
|
||||
|
||||
let syncStreamContents = FeedlySyncStreamContentsOperation(account: account, resource: resource, service: service, isPagingEnabled: true, newerThan: newerThan, log: support.log)
|
||||
let syncStreamContents = FeedlySyncStreamContentsOperation(account: account, resource: resource, service: service, isPagingEnabled: true, newerThan: newerThan)
|
||||
|
||||
let completionExpectation = expectation(description: "Did Finish")
|
||||
syncStreamContents.completionBlock = { _ in
|
||||
@@ -79,7 +79,7 @@ final class FeedlySyncStreamContentsOperationTests: XCTestCase {
|
||||
XCTAssertNil(serviceUnreadOnly)
|
||||
}
|
||||
|
||||
let syncStreamContents = FeedlySyncStreamContentsOperation(account: account, resource: resource, service: service, isPagingEnabled: true, newerThan: newerThan, log: support.log)
|
||||
let syncStreamContents = FeedlySyncStreamContentsOperation(account: account, resource: resource, service: service, isPagingEnabled: true, newerThan: newerThan)
|
||||
|
||||
let completionExpectation = expectation(description: "Did Finish")
|
||||
syncStreamContents.completionBlock = { _ in
|
||||
@@ -120,7 +120,7 @@ final class FeedlySyncStreamContentsOperationTests: XCTestCase {
|
||||
getStreamPageExpectation.fulfill()
|
||||
}
|
||||
|
||||
let syncStreamContents = FeedlySyncStreamContentsOperation(account: account, resource: resource, service: service, isPagingEnabled: true, newerThan: newerThan, log: support.log)
|
||||
let syncStreamContents = FeedlySyncStreamContentsOperation(account: account, resource: resource, service: service, isPagingEnabled: true, newerThan: newerThan)
|
||||
|
||||
let completionExpectation = expectation(description: "Did Finish")
|
||||
syncStreamContents.completionBlock = { _ in
|
||||
|
||||
@@ -14,7 +14,7 @@ import os.log
|
||||
import SyncDatabase
|
||||
|
||||
final class FeedlyTestSupport {
|
||||
var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "FeedlyTests")
|
||||
|
||||
var accessToken = Credentials(type: .oauthAccessToken, username: "Test", secret: "t3st-access-tok3n")
|
||||
var refreshToken = Credentials(type: .oauthRefreshToken, username: "Test", secret: "t3st-refresh-tok3n")
|
||||
var transport = TestTransport()
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1620"
|
||||
version = "1.7">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES"
|
||||
buildArchitectures = "Automatic">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "RSCore"
|
||||
BuildableName = "RSCore"
|
||||
BlueprintName = "RSCore"
|
||||
ReferencedContainer = "container:">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
shouldAutocreateTestPlan = "YES">
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "RSCore"
|
||||
BuildableName = "RSCore"
|
||||
BlueprintName = "RSCore"
|
||||
ReferencedContainer = "container:">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
||||
@@ -0,0 +1,11 @@
|
||||
//
|
||||
// CloudKitLogger.swift
|
||||
// RSCore
|
||||
//
|
||||
// Created by Brent Simmons on 10/2/25.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import os.log
|
||||
|
||||
public let cloudKitLogger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "CloudKit")
|
||||
@@ -38,8 +38,6 @@ public protocol CloudKitZone: AnyObject {
|
||||
|
||||
var zoneID: CKRecordZone.ID { get }
|
||||
|
||||
var log: OSLog { get }
|
||||
|
||||
var container: CKContainer? { get }
|
||||
var database: CKDatabase? { get }
|
||||
var delegate: CloudKitZoneDelegate? { get set }
|
||||
@@ -70,7 +68,11 @@ public extension CloudKitZone {
|
||||
return .default
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
private static var logger: Logger {
|
||||
cloudKitLogger
|
||||
}
|
||||
|
||||
var oldChangeTokenKey: String {
|
||||
return "cloudkit.server.token.\(zoneID.zoneName)"
|
||||
}
|
||||
@@ -127,7 +129,7 @@ public extension CloudKitZone {
|
||||
|
||||
fetchChangesInZone() { result in
|
||||
if case .failure(let error) = result {
|
||||
os_log(.error, log: self.log, "%@ zone remote notification fetch error: %@", self.zoneID.zoneName, error.localizedDescription)
|
||||
Self.logger.error("CloudKit: \(self.zoneID.zoneName) remote notification fetch error: \(error.localizedDescription)")
|
||||
}
|
||||
completion()
|
||||
}
|
||||
@@ -159,7 +161,7 @@ public extension CloudKitZone {
|
||||
}
|
||||
}
|
||||
case .retry(let timeToWait):
|
||||
os_log(.error, log: self.log, "%@ zone fetch changes retry in %f seconds.", self.zoneID.zoneName, timeToWait)
|
||||
Self.logger.debug("CloudKit: \(self.zoneID.zoneName) fetch changes retry in \(timeToWait) seconds.")
|
||||
self.retryIfPossible(after: timeToWait) {
|
||||
self.fetchZoneRecord(completion: completion)
|
||||
}
|
||||
@@ -204,7 +206,7 @@ public extension CloudKitZone {
|
||||
|
||||
save(subscription) { result in
|
||||
if case .failure(let error) = result {
|
||||
os_log(.error, log: self.log, "%@ zone subscribe to changes error: %@", self.zoneID.zoneName, error.localizedDescription)
|
||||
Self.logger.error("CloudKit: \(self.zoneID.zoneName) zone subscribe to changes error: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -251,7 +253,7 @@ public extension CloudKitZone {
|
||||
}
|
||||
}
|
||||
case .retry(let timeToWait):
|
||||
os_log(.error, log: self.log, "%@ zone query retry in %f seconds.", self.zoneID.zoneName, timeToWait)
|
||||
Self.logger.debug("CloudKit: \(self.zoneID.zoneName) zone query retry in \(timeToWait) seconds")
|
||||
self.retryIfPossible(after: timeToWait) {
|
||||
self.query(ckQuery, desiredKeys: desiredKeys, completion: completion)
|
||||
}
|
||||
@@ -311,7 +313,7 @@ public extension CloudKitZone {
|
||||
}
|
||||
}
|
||||
case .retry(let timeToWait):
|
||||
os_log(.error, log: self.log, "%@ zone query retry in %f seconds.", self.zoneID.zoneName, timeToWait)
|
||||
Self.logger.debug("CloudKit: \(self.zoneID.zoneName) zone query retry in \(timeToWait) seconds")
|
||||
self.retryIfPossible(after: timeToWait) {
|
||||
self.query(cursor: cursor, desiredKeys: desiredKeys, carriedRecords: records, completion: completion)
|
||||
}
|
||||
@@ -366,7 +368,7 @@ public extension CloudKitZone {
|
||||
}
|
||||
}
|
||||
case .retry(let timeToWait):
|
||||
os_log(.error, log: self.log, "%@ zone fetch retry in %f seconds.", self.zoneID.zoneName, timeToWait)
|
||||
Self.logger.debug("CloudKit: \(self.zoneID.zoneName) zone fetch retry in \(timeToWait) seconds")
|
||||
self.retryIfPossible(after: timeToWait) {
|
||||
self.fetch(externalID: externalID, completion: completion)
|
||||
}
|
||||
@@ -440,7 +442,7 @@ public extension CloudKitZone {
|
||||
self.saveIfNew(records) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
os_log(.info, log: self.log, "Saved %d chunked new records.", records.count)
|
||||
Self.logger.info("CloudKit: Saved \(records.count) chunked new records.")
|
||||
saveChunksIfNew()
|
||||
case .failure(let error):
|
||||
completion(.failure(error))
|
||||
@@ -488,7 +490,7 @@ public extension CloudKitZone {
|
||||
}
|
||||
}
|
||||
case .retry(let timeToWait):
|
||||
os_log(.error, log: self.log, "%@ zone save subscription retry in %f seconds.", self.zoneID.zoneName, timeToWait)
|
||||
Self.logger.debug("CloudKit: \(self.zoneID.zoneName) save subscription retry in \(timeToWait) seconds")
|
||||
self.retryIfPossible(after: timeToWait) {
|
||||
self.save(subscription, completion: completion)
|
||||
}
|
||||
@@ -603,7 +605,7 @@ public extension CloudKitZone {
|
||||
completion(.success(()))
|
||||
}
|
||||
case .retry(let timeToWait):
|
||||
os_log(.error, log: self.log, "%@ zone delete subscription retry in %f seconds.", self.zoneID.zoneName, timeToWait)
|
||||
Self.logger.debug("CloudKit: \(self.zoneID.zoneName) delete subscription retry in \(timeToWait) seconds")
|
||||
self.retryIfPossible(after: timeToWait) {
|
||||
self.delete(subscriptionID: subscriptionID, completion: completion)
|
||||
}
|
||||
@@ -657,7 +659,7 @@ public extension CloudKitZone {
|
||||
completion(.failure(CloudKitZoneError.userDeletedZone))
|
||||
}
|
||||
case .retry(let timeToWait):
|
||||
os_log(.error, log: self.log, "%@ zone modify retry in %f seconds.", self.zoneID.zoneName, timeToWait)
|
||||
Self.logger.debug("CloudKit: \(self.zoneID.zoneName) zone modify retry in \(timeToWait) seconds")
|
||||
self.retryIfPossible(after: timeToWait) {
|
||||
self.modify(recordsToSave: recordsToSave, recordIDsToDelete: recordIDsToDelete, completion: completion)
|
||||
}
|
||||
@@ -671,7 +673,7 @@ public extension CloudKitZone {
|
||||
self.modify(recordsToSave: records, recordIDsToDelete: []) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
os_log(.info, log: self.log, "Saved %d chunked records.", records.count)
|
||||
Self.logger.info("CloudKit: Saved \(records.count) chunked records")
|
||||
saveChunks(completion: completion)
|
||||
case .failure(let error):
|
||||
completion(.failure(error))
|
||||
@@ -688,7 +690,7 @@ public extension CloudKitZone {
|
||||
self.modify(recordsToSave: [], recordIDsToDelete: records) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
os_log(.info, log: self.log, "Deleted %d chunked records.", records.count)
|
||||
Self.logger.debug("CloudKit: Deleted \(records.count) chunked records")
|
||||
deleteChunks()
|
||||
case .failure(let error):
|
||||
DispatchQueue.main.async {
|
||||
@@ -792,7 +794,7 @@ public extension CloudKitZone {
|
||||
completion(.failure(CloudKitZoneError.userDeletedZone))
|
||||
}
|
||||
case .retry(let timeToWait):
|
||||
os_log(.error, log: self.log, "%@ zone fetch changes retry in %f seconds.", self.zoneID.zoneName, timeToWait)
|
||||
Self.logger.debug("CloudKit: \(self.zoneID.zoneName) zone fetch changeds retry in \(timeToWait) seconds")
|
||||
self.retryIfPossible(after: timeToWait) {
|
||||
self.fetchChangesInZone(completion: completion)
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import os
|
||||
|
||||
public enum Platform {
|
||||
|
||||
private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "Platform")
|
||||
|
||||
/// Get the path to a subfolder of the application's data folder (often `Application Support`).
|
||||
/// - Parameters:
|
||||
/// - appName: The name of the application.
|
||||
@@ -24,7 +26,7 @@ public enum Platform {
|
||||
try FileManager.default.createDirectory(at: dataFolder, withIntermediateDirectories: true, attributes: nil)
|
||||
return dataFolder.path
|
||||
} catch {
|
||||
os_log(.error, log: .default, "Platform.dataSubfolder error: %@", error.localizedDescription)
|
||||
Self.logger.error("Platform.dataSubfolder error: \(error.localizedDescription)")
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -46,7 +48,7 @@ private extension Platform {
|
||||
|
||||
return dataFolder
|
||||
} catch {
|
||||
os_log(.error, log: .default, "Platform.dataFolder error: %@", error.localizedDescription)
|
||||
Self.logger.error("Platform.dataFolder error: \(error.localizedDescription)")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -9,8 +9,15 @@
|
||||
import Foundation
|
||||
import RSDatabaseObjC
|
||||
|
||||
public enum DatabaseError: Error {
|
||||
public enum DatabaseError: Error, LocalizedError {
|
||||
case isSuspended // On iOS, to support background refreshing, a database may be suspended.
|
||||
|
||||
public var errorDescription: String? {
|
||||
switch self {
|
||||
case .isSuspended:
|
||||
return NSLocalizedString("Database is suspended", comment: "Database suspended error")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Result type that provides an FMDatabase or a DatabaseError.
|
||||
|
||||
@@ -40,6 +40,7 @@ public protocol DownloadSessionDelegate {
|
||||
/// These URLs are skipped for the rest of the session.
|
||||
private var urlsWith400s = Set<URL>()
|
||||
|
||||
private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "DownloadSession")
|
||||
|
||||
public init(delegate: DownloadSessionDelegate) {
|
||||
|
||||
@@ -194,11 +195,11 @@ private extension DownloadSession {
|
||||
let urlToUse = cachedRedirect(for: url) ?? url
|
||||
|
||||
if requestShouldBeDroppedDueToActive429(urlToUse) {
|
||||
os_log(.debug, "Dropping request for previous 429: \(urlToUse)")
|
||||
Self.logger.info("Dropping request for previous 429: \(urlToUse)")
|
||||
return
|
||||
}
|
||||
if requestShouldBeDroppedDueToPrevious400(urlToUse) {
|
||||
os_log(.debug, "Dropping request for previous 400-499: \(urlToUse)")
|
||||
Self.logger.info("Dropping request for previous 400-499: \(urlToUse)")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import os.log
|
||||
import os
|
||||
import RSWeb
|
||||
|
||||
struct CacheCleaner {
|
||||
|
||||
static let log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "CacheCleaner")
|
||||
static private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "CacheCleaner")
|
||||
|
||||
static func purgeIfNecessary() {
|
||||
|
||||
@@ -35,19 +35,16 @@ struct CacheCleaner {
|
||||
|
||||
for tempItem in [faviconsFolderURL, imagesFolderURL, feedURLToIconURL, homePageToIconURL, homePagesWithNoIconURL] {
|
||||
do {
|
||||
os_log(.info, log: self.log, "Removing cache file: %@", tempItem.absoluteString)
|
||||
logger.info("Removing cache file: \(tempItem.absoluteString)")
|
||||
try FileManager.default.removeItem(at: tempItem)
|
||||
} catch {
|
||||
os_log(.error, log: self.log, "Could not delete cache file: %@", error.localizedDescription)
|
||||
logger.error("Could not delete cache file: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
|
||||
AppDefaults.shared.lastImageCacheFlushDate = Date()
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,8 +29,8 @@ final class SingleFaviconDownloader {
|
||||
var iconImage: IconImage?
|
||||
let homePageURL: String?
|
||||
|
||||
private var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "SingleFaviconDownloader")
|
||||
|
||||
static private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "SingleFaviconDownloader")
|
||||
|
||||
private var lastDownloadAttemptDate: Date
|
||||
private var diskStatus = DiskStatus.unknown
|
||||
private var diskCache: BinaryDiskCache
|
||||
@@ -66,7 +66,7 @@ final class SingleFaviconDownloader {
|
||||
|
||||
lastDownloadAttemptDate = Date()
|
||||
findFavicon()
|
||||
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -93,7 +93,7 @@ private extension SingleFaviconDownloader {
|
||||
}
|
||||
|
||||
self.postDidLoadFaviconNotification()
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -141,17 +141,17 @@ private extension SingleFaviconDownloader {
|
||||
|
||||
Task { @MainActor in
|
||||
Downloader.shared.download(url) { (data, response, error) in
|
||||
|
||||
|
||||
if let data = data, !data.isEmpty, let response = response, response.statusIsOK, error == nil {
|
||||
self.saveToDisk(data)
|
||||
RSImage.image(with: data, imageResultBlock: completion)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if let error = error {
|
||||
os_log(.info, log: self.log, "Error downloading image at %@: %@.", url.absoluteString, error.localizedDescription)
|
||||
Self.logger.error("Error downloading image at \(url.absoluteString): \(error.localizedDescription)")
|
||||
}
|
||||
|
||||
|
||||
completion(nil)
|
||||
}
|
||||
}
|
||||
@@ -162,5 +162,5 @@ private extension SingleFaviconDownloader {
|
||||
assert(Thread.isMainThread)
|
||||
NotificationCenter.default.post(name: .DidLoadFavicon, object: self)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -21,7 +21,7 @@ final class ImageDownloader {
|
||||
|
||||
public static let shared = ImageDownloader()
|
||||
|
||||
private var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "ImageDownloader")
|
||||
static private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "ImageDownloader")
|
||||
|
||||
private var diskCache: BinaryDiskCache
|
||||
private let queue: DispatchQueue
|
||||
@@ -107,20 +107,20 @@ private extension ImageDownloader {
|
||||
|
||||
Task { @MainActor in
|
||||
Downloader.shared.download(imageURL) { (data, response, error) in
|
||||
|
||||
|
||||
if let data = data, !data.isEmpty, let response = response, response.statusIsOK, error == nil {
|
||||
self.saveToDisk(url, data)
|
||||
completion(data)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if let response = response as? HTTPURLResponse, response.statusCode >= HTTPResponseCode.badRequest && response.statusCode <= HTTPResponseCode.notAcceptable {
|
||||
self.badURLs.insert(url)
|
||||
}
|
||||
if let error = error {
|
||||
os_log(.info, log: self.log, "Error downloading image at %@: %@.", url, error.localizedDescription)
|
||||
Self.logger.error("Error downloading image at \(url) \(error.localizedDescription)")
|
||||
}
|
||||
|
||||
|
||||
completion(nil)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,15 +13,15 @@ import RSParser
|
||||
import Account
|
||||
|
||||
final class ExtensionContainersFile {
|
||||
|
||||
private static var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "extensionContainersFile")
|
||||
|
||||
static private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "ExtensionContainersFile")
|
||||
|
||||
private static var filePath: String = {
|
||||
let appGroup = Bundle.main.object(forInfoDictionaryKey: "AppGroup") as! String
|
||||
let containerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroup)
|
||||
return containerURL!.appendingPathComponent("extension_containers.plist").path
|
||||
}()
|
||||
|
||||
|
||||
private var isDirty = false {
|
||||
didSet {
|
||||
queueSaveToDiskIfNeeded()
|
||||
@@ -33,7 +33,7 @@ final class ExtensionContainersFile {
|
||||
if !FileManager.default.fileExists(atPath: ExtensionContainersFile.filePath) {
|
||||
save()
|
||||
}
|
||||
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(markAsDirty), name: .UserDidAddAccount, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(markAsDirty), name: .UserDidDeleteAccount, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(markAsDirty), name: .AccountStateDidChange, object: nil)
|
||||
@@ -53,14 +53,14 @@ final class ExtensionContainersFile {
|
||||
extensionContainers = try? decoder.decode(ExtensionContainers.self, from: fileData)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
if let error = errorPointer?.pointee {
|
||||
os_log(.error, log: log, "Read from disk coordination failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("Read from disk coordination failed: \(error.localizedDescription)")
|
||||
}
|
||||
|
||||
return extensionContainers
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private extension ExtensionContainersFile {
|
||||
@@ -68,7 +68,7 @@ private extension ExtensionContainersFile {
|
||||
@objc func markAsDirty() {
|
||||
isDirty = true
|
||||
}
|
||||
|
||||
|
||||
func queueSaveToDiskIfNeeded() {
|
||||
saveQueue.add(self, #selector(saveToDiskIfNeeded))
|
||||
}
|
||||
@@ -87,7 +87,7 @@ private extension ExtensionContainersFile {
|
||||
let errorPointer: NSErrorPointer = nil
|
||||
let fileCoordinator = NSFileCoordinator()
|
||||
let fileURL = URL(fileURLWithPath: ExtensionContainersFile.filePath)
|
||||
|
||||
|
||||
fileCoordinator.coordinate(writingItemAt: fileURL, options: [], error: errorPointer, byAccessor: { writeURL in
|
||||
do {
|
||||
let extensionAccounts = AccountManager.shared.sortedActiveAccounts.map { ExtensionAccount(account: $0) }
|
||||
@@ -95,12 +95,12 @@ private extension ExtensionContainersFile {
|
||||
let data = try encoder.encode(extensionContainers)
|
||||
try data.write(to: writeURL)
|
||||
} catch let error as NSError {
|
||||
os_log(.error, log: Self.log, "Save to disk failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("Save to disk failed: \(error.localizedDescription)")
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
if let error = errorPointer?.pointee {
|
||||
os_log(.error, log: Self.log, "Save to disk coordination failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("Save to disk coordination failed: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ import os.log
|
||||
import Account
|
||||
|
||||
final class ExtensionFeedAddRequestFile: NSObject, NSFilePresenter {
|
||||
|
||||
private static var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "extensionFeedAddRequestFile")
|
||||
|
||||
static private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "ExtensionFeedAddRequestFile")
|
||||
|
||||
private static var filePath: String = {
|
||||
let appGroup = Bundle.main.object(forInfoDictionaryKey: "AppGroup") as! String
|
||||
@@ -82,15 +82,14 @@ final class ExtensionFeedAddRequestFile: NSObject, NSFilePresenter {
|
||||
try data.write(to: url)
|
||||
|
||||
} catch let error as NSError {
|
||||
os_log(.error, log: Self.log, "Save to disk failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("Save to disk failed: \(error.localizedDescription)")
|
||||
}
|
||||
})
|
||||
|
||||
if let error = errorPointer?.pointee {
|
||||
os_log(.error, log: Self.log, "Save to disk coordination failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("Save to disk coordination failed: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private extension ExtensionFeedAddRequestFile {
|
||||
@@ -119,12 +118,12 @@ private extension ExtensionFeedAddRequestFile {
|
||||
try data.write(to: url)
|
||||
|
||||
} catch let error as NSError {
|
||||
os_log(.error, log: Self.log, "Save to disk failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("Save to disk failed: \(error.localizedDescription)")
|
||||
}
|
||||
})
|
||||
|
||||
if let error = errorPointer?.pointee {
|
||||
os_log(.error, log: Self.log, "Save to disk coordination failed: %@.", error.localizedDescription)
|
||||
Self.logger.error("Save to disk coordination failed: \(error.localizedDescription)")
|
||||
}
|
||||
|
||||
requests?.forEach { processRequest($0) }
|
||||
@@ -156,5 +155,4 @@ private extension ExtensionFeedAddRequestFile {
|
||||
|
||||
account.createWebFeed(url: request.feedURL.absoluteString, name: request.name, container: container, validateFeed: true) { _ in }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,10 +14,9 @@ import RSCore
|
||||
import Articles
|
||||
import Account
|
||||
|
||||
|
||||
public final class WidgetDataEncoder {
|
||||
public var isRunning = false
|
||||
|
||||
private let log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "Application")
|
||||
private let fetchLimit = 7
|
||||
|
||||
private lazy var appGroup = Bundle.main.object(forInfoDictionaryKey: "AppGroup") as! String
|
||||
@@ -25,7 +24,7 @@ public final class WidgetDataEncoder {
|
||||
private lazy var imageContainer = containerURL?.appendingPathComponent("widgetImages", isDirectory: true)
|
||||
private lazy var dataURL = containerURL?.appendingPathComponent("widget-data.json")
|
||||
|
||||
public var isRunning = false
|
||||
private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "WidgetDataEncoder")
|
||||
|
||||
init () {
|
||||
if imageContainer != nil {
|
||||
@@ -38,7 +37,7 @@ public final class WidgetDataEncoder {
|
||||
isRunning = true
|
||||
|
||||
flushSharedContainer()
|
||||
os_log(.debug, log: log, "Starting encoding widget data.")
|
||||
Self.logger.debug("Encoding widget data")
|
||||
|
||||
DispatchQueue.main.async {
|
||||
self.encodeWidgetData() { latestData in
|
||||
@@ -49,15 +48,15 @@ public final class WidgetDataEncoder {
|
||||
|
||||
let encodedData = try? JSONEncoder().encode(latestData)
|
||||
|
||||
os_log(.debug, log: self.log, "Finished encoding widget data.")
|
||||
Self.logger.debug("Finished encoding widget data")
|
||||
|
||||
if self.fileExists() {
|
||||
try? FileManager.default.removeItem(at: self.dataURL!)
|
||||
os_log(.debug, log: self.log, "Removed widget data from container.")
|
||||
Self.logger.debug("Removed widget data from container")
|
||||
}
|
||||
|
||||
if FileManager.default.createFile(atPath: self.dataURL!.path, contents: encodedData, attributes: nil) {
|
||||
os_log(.debug, log: self.log, "Wrote widget data to container.")
|
||||
Self.logger.info("Wrote widget data to container")
|
||||
WidgetCenter.shared.reloadAllTimelines()
|
||||
}
|
||||
|
||||
@@ -136,8 +135,8 @@ public final class WidgetDataEncoder {
|
||||
}
|
||||
|
||||
dispatchGroup.notify(queue: .main) {
|
||||
if groupError != nil {
|
||||
os_log(.error, log: self.log, "WidgetDataEncoder failed to write the widget data.")
|
||||
if let groupError {
|
||||
Self.logger.error("WidgetDataEncoder failed to write the widget data: \(groupError.localizedDescription)")
|
||||
completion(nil)
|
||||
} else {
|
||||
let latestData = WidgetData(currentUnreadCount: SmartFeedsController.shared.unreadFeed.unreadCount,
|
||||
@@ -150,7 +149,6 @@ public final class WidgetDataEncoder {
|
||||
completion(latestData)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private func fileExists() -> Bool {
|
||||
@@ -179,7 +177,4 @@ public final class WidgetDataEncoder {
|
||||
try? FileManager.default.createDirectory(at: imageContainer, withIntermediateDirectories: true, attributes: nil)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
+36
-48
@@ -7,13 +7,14 @@
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import BackgroundTasks
|
||||
import os
|
||||
import WidgetKit
|
||||
import RSCore
|
||||
import RSWeb
|
||||
import Account
|
||||
import BackgroundTasks
|
||||
import os
|
||||
import Articles
|
||||
import Secrets
|
||||
import WidgetKit
|
||||
|
||||
var appDelegate: AppDelegate!
|
||||
|
||||
@@ -36,7 +37,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationC
|
||||
}
|
||||
}
|
||||
|
||||
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "Application")
|
||||
private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "Application")
|
||||
|
||||
var userNotificationManager: UserNotificationManager!
|
||||
var faviconDownloader: FaviconDownloader!
|
||||
@@ -79,7 +80,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationC
|
||||
|
||||
let isFirstRun = AppDefaults.shared.isFirstRun
|
||||
if isFirstRun {
|
||||
logger.info("Is first run.")
|
||||
Self.logger.info("Is first run.")
|
||||
}
|
||||
|
||||
if isFirstRun && !AccountManager.shared.anyAccountHasAtLeastOneFeed() {
|
||||
@@ -172,7 +173,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationC
|
||||
func resumeDatabaseProcessingIfNecessary() {
|
||||
if AccountManager.shared.isSuspended {
|
||||
AccountManager.shared.resumeAll()
|
||||
logger.info("Application processing resumed.")
|
||||
Self.logger.info("Application processing resumed.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,7 +278,7 @@ private extension AppDelegate {
|
||||
self.waitBackgroundUpdateTask = UIApplication.shared.beginBackgroundTask { [weak self] in
|
||||
guard let self = self else { return }
|
||||
self.completeProcessing(true)
|
||||
logger.info("Accounts wait for progress terminated for running too long.")
|
||||
Self.logger.info("Accounts wait for progress terminated for running too long.")
|
||||
}
|
||||
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
@@ -289,18 +290,18 @@ private extension AppDelegate {
|
||||
|
||||
func waitToComplete(completion: @escaping (Bool) -> Void) {
|
||||
guard UIApplication.shared.applicationState == .background else {
|
||||
logger.info("App came back to foreground, no longer waiting.")
|
||||
Self.logger.info("App came back to foreground, no longer waiting.")
|
||||
completion(false)
|
||||
return
|
||||
}
|
||||
|
||||
if AccountManager.shared.refreshInProgress || isSyncArticleStatusRunning || widgetDataEncoder.isRunning {
|
||||
logger.info("Waiting for sync to finish…")
|
||||
Self.logger.info("Waiting for sync to finish…")
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { [weak self] in
|
||||
self?.waitToComplete(completion: completion)
|
||||
}
|
||||
} else {
|
||||
logger.info("Refresh progress complete.")
|
||||
Self.logger.info("Refresh progress complete.")
|
||||
completion(true)
|
||||
}
|
||||
}
|
||||
@@ -327,7 +328,7 @@ private extension AppDelegate {
|
||||
|
||||
self.syncBackgroundUpdateTask = UIApplication.shared.beginBackgroundTask {
|
||||
completeProcessing()
|
||||
self.logger.info("Accounts sync processing terminated for running too long.")
|
||||
Self.logger.info("Accounts sync processing terminated for running too long.")
|
||||
}
|
||||
|
||||
DispatchQueue.main.async {
|
||||
@@ -351,7 +352,7 @@ private extension AppDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("Application processing suspended.")
|
||||
Self.logger.info("Application processing suspended.")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -379,7 +380,7 @@ private extension AppDelegate {
|
||||
do {
|
||||
try BGTaskScheduler.shared.submit(request)
|
||||
} catch {
|
||||
self.logger.error("Could not schedule app refresh: \(error.localizedDescription)")
|
||||
Self.logger.error("Could not schedule app refresh: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -391,7 +392,7 @@ private extension AppDelegate {
|
||||
|
||||
scheduleBackgroundFeedRefresh() // schedule next refresh
|
||||
|
||||
logger.info("Woken to perform account refresh.")
|
||||
Self.logger.info("Woken to perform account refresh.")
|
||||
|
||||
DispatchQueue.main.async {
|
||||
if AccountManager.shared.isSuspended {
|
||||
@@ -400,7 +401,7 @@ private extension AppDelegate {
|
||||
AccountManager.shared.refreshAll(errorHandler: ErrorHandler.log) { [unowned self] in
|
||||
if !AccountManager.shared.isSuspended {
|
||||
self.suspendApplication()
|
||||
logger.info("Account refresh operation completed.")
|
||||
Self.logger.info("Account refresh operation completed.")
|
||||
task.setTaskCompleted(success: true)
|
||||
}
|
||||
}
|
||||
@@ -408,7 +409,7 @@ private extension AppDelegate {
|
||||
|
||||
// set expiration handler
|
||||
task.expirationHandler = { [weak task] in
|
||||
self.logger.info("Accounts refresh processing terminated for running too long.")
|
||||
Self.logger.info("Accounts refresh processing terminated for running too long.")
|
||||
DispatchQueue.main.async {
|
||||
self.suspendApplication()
|
||||
task?.setTaskCompleted(success: false)
|
||||
@@ -422,51 +423,38 @@ private extension AppDelegate {
|
||||
private extension AppDelegate {
|
||||
|
||||
func handleMarkAsRead(userInfo: [AnyHashable: Any]) {
|
||||
guard let articlePathUserInfo = userInfo[UserInfoKey.articlePath] as? [AnyHashable : Any],
|
||||
let accountID = articlePathUserInfo[ArticlePathKey.accountID] as? String,
|
||||
let articleID = articlePathUserInfo[ArticlePathKey.articleID] as? String else {
|
||||
return
|
||||
}
|
||||
resumeDatabaseProcessingIfNecessary()
|
||||
let account = AccountManager.shared.existingAccount(with: accountID)
|
||||
guard account != nil else {
|
||||
os_log(.debug, "No account found from notification.")
|
||||
return
|
||||
}
|
||||
let article = try? account!.fetchArticles(.articleIDs([articleID]))
|
||||
guard article != nil else {
|
||||
os_log(.debug, "No article found from search using %@", articleID)
|
||||
return
|
||||
}
|
||||
account!.markArticles(article!, statusKey: .read, flag: true) { _ in }
|
||||
self.prepareAccountsForBackground()
|
||||
account!.syncArticleStatus(completion: { [weak self] _ in
|
||||
if !AccountManager.shared.isSuspended {
|
||||
self?.prepareAccountsForBackground()
|
||||
self?.suspendApplication()
|
||||
}
|
||||
})
|
||||
handleStatusNotification(userInfo: userInfo, statusKey: .read)
|
||||
}
|
||||
|
||||
func handleMarkAsStarred(userInfo: [AnyHashable: Any]) {
|
||||
handleStatusNotification(userInfo: userInfo, statusKey: .starred)
|
||||
}
|
||||
|
||||
private func handleStatusNotification(userInfo: [AnyHashable: Any], statusKey: ArticleStatus.Key) {
|
||||
guard let articlePathUserInfo = userInfo[UserInfoKey.articlePath] as? [AnyHashable : Any],
|
||||
let accountID = articlePathUserInfo[ArticlePathKey.accountID] as? String,
|
||||
let articleID = articlePathUserInfo[ArticlePathKey.articleID] as? String else {
|
||||
return
|
||||
}
|
||||
|
||||
resumeDatabaseProcessingIfNecessary()
|
||||
let account = AccountManager.shared.existingAccount(with: accountID)
|
||||
guard account != nil else {
|
||||
os_log(.debug, "No account found from notification.")
|
||||
|
||||
guard let account = AccountManager.shared.existingAccount(with: accountID) else {
|
||||
assertionFailure("Expected account with \(accountID)")
|
||||
Self.logger.error("No account with accountID \(accountID) found from status notification")
|
||||
return
|
||||
}
|
||||
let article = try? account!.fetchArticles(.articleIDs([articleID]))
|
||||
guard article != nil else {
|
||||
os_log(.debug, "No article found from search using %@", articleID)
|
||||
|
||||
guard let singleArticleSet = try? account.fetchArticles(.articleIDs([articleID])) else {
|
||||
assertionFailure("Expected article with \(articleID)")
|
||||
Self.logger.error("No article with articleID found \(articleID) from status notification")
|
||||
return
|
||||
}
|
||||
account!.markArticles(article!, statusKey: .starred, flag: true) { _ in }
|
||||
account!.syncArticleStatus(completion: { [weak self] _ in
|
||||
|
||||
assert(singleArticleSet.count == 1)
|
||||
account.markArticles(singleArticleSet, statusKey: statusKey, flag: true) { _ in }
|
||||
|
||||
account.syncArticleStatus(completion: { [weak self] _ in
|
||||
if !AccountManager.shared.isSuspended {
|
||||
self?.prepareAccountsForBackground()
|
||||
self?.suspendApplication()
|
||||
|
||||
@@ -7,25 +7,24 @@
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import os
|
||||
import RSCore
|
||||
import os.log
|
||||
|
||||
struct ErrorHandler {
|
||||
|
||||
private static var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "Application")
|
||||
private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "ErrorHandler")
|
||||
|
||||
public static func present(_ viewController: UIViewController) -> (Error) -> () {
|
||||
return { [weak viewController] error in
|
||||
if UIApplication.shared.applicationState == .active {
|
||||
viewController?.presentError(error)
|
||||
} else {
|
||||
ErrorHandler.log(error)
|
||||
log(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static func log(_ error: Error) {
|
||||
os_log(.error, log: self.log, "%@", error.localizedDescription)
|
||||
}
|
||||
|
||||
public static func log(_ error: Error) {
|
||||
logger.error("\(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user