2019-09-19 04:56:43 +02:00
|
|
|
//
|
|
|
|
// FeedlyUpdateAccountFeedsWithItemsOperation.swift
|
|
|
|
// Account
|
|
|
|
//
|
|
|
|
// Created by Kiel Gillard on 20/9/19.
|
|
|
|
// Copyright © 2019 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import RSParser
|
|
|
|
import os.log
|
|
|
|
|
|
|
|
/// Single responsibility is to combine the articles with their feeds for a specific account.
|
2019-09-23 09:29:53 +02:00
|
|
|
final class FeedlyUpdateAccountFeedsWithItemsOperation: FeedlyOperation {
|
2019-09-19 04:56:43 +02:00
|
|
|
private let account: Account
|
|
|
|
private let organisedItemsProvider: FeedlyParsedItemsByFeedProviding
|
|
|
|
private let log: OSLog
|
|
|
|
|
|
|
|
init(account: Account, organisedItemsProvider: FeedlyParsedItemsByFeedProviding, log: OSLog) {
|
|
|
|
self.account = account
|
|
|
|
self.organisedItemsProvider = organisedItemsProvider
|
|
|
|
self.log = log
|
|
|
|
}
|
|
|
|
|
|
|
|
override func main() {
|
2019-10-14 04:32:46 +02:00
|
|
|
assert(Thread.isMainThread) // Needs to be on main thread because Feed is a main-thread-only model type.
|
2019-09-19 04:56:43 +02:00
|
|
|
guard !isCancelled else {
|
|
|
|
didFinish()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-11-15 03:11:41 +01:00
|
|
|
let webFeedIDsAndItems = organisedItemsProvider.parsedItemsKeyedByFeedId
|
2019-09-19 04:56:43 +02:00
|
|
|
|
2019-11-15 03:11:41 +01:00
|
|
|
account.update(webFeedIDsAndItems: webFeedIDsAndItems, defaultRead: true) {
|
|
|
|
os_log(.debug, log: self.log, "Updated %i feeds for \"%@\"", webFeedIDsAndItems.count, self.organisedItemsProvider.providerName)
|
2019-09-19 04:56:43 +02:00
|
|
|
self.didFinish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|