2019-09-19 04:56:43 +02:00
|
|
|
//
|
|
|
|
// FeedlyRequestStreamsOperation.swift
|
|
|
|
// Account
|
|
|
|
//
|
|
|
|
// Created by Kiel Gillard on 20/9/19.
|
|
|
|
// Copyright © 2019 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import os.log
|
|
|
|
|
|
|
|
protocol FeedlyRequestStreamsOperationDelegate: class {
|
2019-10-18 23:21:02 +02:00
|
|
|
func feedlyRequestStreamsOperation(_ operation: FeedlyRequestStreamsOperation, enqueue collectionStreamOperation: FeedlyGetStreamContentsOperation)
|
2019-09-19 04:56:43 +02:00
|
|
|
}
|
|
|
|
|
2020-01-19 23:19:06 +01:00
|
|
|
/// Create one stream request operation for one Feedly collection.
|
2019-09-19 04:56:43 +02:00
|
|
|
/// This is the start of the process of refreshing the entire contents of a Folder.
|
2019-09-23 09:29:53 +02:00
|
|
|
final class FeedlyRequestStreamsOperation: FeedlyOperation {
|
2019-09-19 04:56:43 +02:00
|
|
|
|
|
|
|
weak var queueDelegate: FeedlyRequestStreamsOperationDelegate?
|
|
|
|
|
|
|
|
let collectionsProvider: FeedlyCollectionProviding
|
2019-10-18 23:21:02 +02:00
|
|
|
let service: FeedlyGetStreamContentsService
|
2019-09-19 04:56:43 +02:00
|
|
|
let account: Account
|
|
|
|
let log: OSLog
|
2019-10-03 13:23:49 +02:00
|
|
|
let newerThan: Date?
|
|
|
|
let unreadOnly: Bool?
|
2020-01-19 23:19:06 +01:00
|
|
|
|
2019-10-18 23:21:02 +02:00
|
|
|
init(account: Account, collectionsProvider: FeedlyCollectionProviding, newerThan: Date?, unreadOnly: Bool?, service: FeedlyGetStreamContentsService, log: OSLog) {
|
2019-09-19 04:56:43 +02:00
|
|
|
self.account = account
|
2019-10-18 23:21:02 +02:00
|
|
|
self.service = service
|
2019-09-19 04:56:43 +02:00
|
|
|
self.collectionsProvider = collectionsProvider
|
2019-10-03 13:23:49 +02:00
|
|
|
self.newerThan = newerThan
|
|
|
|
self.unreadOnly = unreadOnly
|
2019-09-19 04:56:43 +02:00
|
|
|
self.log = log
|
|
|
|
}
|
|
|
|
|
2020-01-16 06:30:37 +01:00
|
|
|
override func run() {
|
|
|
|
defer {
|
|
|
|
didFinish()
|
|
|
|
}
|
2019-09-19 04:56:43 +02:00
|
|
|
|
|
|
|
assert(queueDelegate != nil, "This is not particularly useful unless the `queueDelegate` is non-nil.")
|
|
|
|
|
|
|
|
// TODO: Prioritise the must read collection/category before others so the most important content for the user loads first.
|
|
|
|
|
|
|
|
for collection in collectionsProvider.collections {
|
2019-10-10 00:15:22 +02:00
|
|
|
let resource = FeedlyCategoryResourceId(id: collection.id)
|
2019-10-18 23:21:02 +02:00
|
|
|
let operation = FeedlyGetStreamContentsOperation(account: account,
|
2019-10-10 00:15:22 +02:00
|
|
|
resource: resource,
|
2019-10-18 23:21:02 +02:00
|
|
|
service: service,
|
2019-10-03 13:23:49 +02:00
|
|
|
newerThan: newerThan,
|
2019-11-27 09:04:55 +01:00
|
|
|
unreadOnly: unreadOnly,
|
|
|
|
log: log)
|
2019-09-19 04:56:43 +02:00
|
|
|
queueDelegate?.feedlyRequestStreamsOperation(self, enqueue: operation)
|
|
|
|
}
|
|
|
|
|
|
|
|
os_log(.debug, log: log, "Requested %i collection streams", collectionsProvider.collections.count)
|
|
|
|
}
|
|
|
|
}
|