Add feeds to tags. Set iconURLs
remove unused functions.
This commit is contained in:
parent
a0efc7fda9
commit
6b147e7dc9
@ -344,26 +344,6 @@ final class GoogleReaderCompatibleAPICaller: NSObject {
|
|||||||
transport.send(request: request, method: HTTPMethod.delete, completion: completion)
|
transport.send(request: request, method: HTTPMethod.delete, completion: completion)
|
||||||
}
|
}
|
||||||
|
|
||||||
func retrieveTaggings(completion: @escaping (Result<[GoogleReaderCompatibleTagging]?, Error>) -> Void) {
|
|
||||||
|
|
||||||
let callURL = GoogleReaderCompatibleBaseURL.appendingPathComponent("taggings.json")
|
|
||||||
let conditionalGet = accountMetadata?.conditionalGetInfo[ConditionalGetKeys.taggings]
|
|
||||||
let request = URLRequest(url: callURL, credentials: credentials, conditionalGet: conditionalGet)
|
|
||||||
|
|
||||||
transport.send(request: request, resultType: [GoogleReaderCompatibleTagging].self) { result in
|
|
||||||
|
|
||||||
switch result {
|
|
||||||
case .success(let (response, taggings)):
|
|
||||||
self.storeConditionalGet(key: ConditionalGetKeys.taggings, headers: response.allHeaderFields)
|
|
||||||
completion(.success(taggings))
|
|
||||||
case .failure(let error):
|
|
||||||
completion(.failure(error))
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func createTagging(feedID: Int, name: String, completion: @escaping (Result<Int, Error>) -> Void) {
|
func createTagging(feedID: Int, name: String, completion: @escaping (Result<Int, Error>) -> Void) {
|
||||||
|
|
||||||
let callURL = GoogleReaderCompatibleBaseURL.appendingPathComponent("taggings.json")
|
let callURL = GoogleReaderCompatibleBaseURL.appendingPathComponent("taggings.json")
|
||||||
|
@ -97,17 +97,17 @@ final class GoogleReaderCompatibleAccountDelegate: AccountDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// self.refreshArticles(account) {
|
self.refreshArticles(account) {
|
||||||
// self.refreshArticleStatus(for: account) {
|
// self.refreshArticleStatus(for: account) {
|
||||||
// self.refreshMissingArticles(account) {
|
// self.refreshMissingArticles(account) {
|
||||||
// self.refreshProgress.clear()
|
self.refreshProgress.clear()
|
||||||
// DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
// completion(.success(()))
|
completion(.success(()))
|
||||||
// }
|
}
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
case .failure(let error):
|
case .failure(let error):
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.refreshProgress.clear()
|
self.refreshProgress.clear()
|
||||||
@ -585,35 +585,15 @@ private extension GoogleReaderCompatibleAccountDelegate {
|
|||||||
case .success(let subscriptions):
|
case .success(let subscriptions):
|
||||||
|
|
||||||
self.refreshProgress.completeTask()
|
self.refreshProgress.completeTask()
|
||||||
self.caller.retrieveTaggings { result in
|
|
||||||
switch result {
|
|
||||||
case .success(let taggings):
|
|
||||||
|
|
||||||
self.refreshProgress.completeTask()
|
|
||||||
self.caller.retrieveIcons { result in
|
|
||||||
switch result {
|
|
||||||
case .success(let icons):
|
|
||||||
|
|
||||||
BatchUpdate.shared.perform {
|
BatchUpdate.shared.perform {
|
||||||
self.syncFeeds(account, subscriptions)
|
self.syncFeeds(account, subscriptions)
|
||||||
self.syncTaggings(account, taggings)
|
self.syncTaggings(account, subscriptions)
|
||||||
self.syncFavicons(account, icons)
|
|
||||||
}
|
|
||||||
|
|
||||||
self.refreshProgress.completeTask()
|
|
||||||
completion(.success(()))
|
|
||||||
|
|
||||||
case .failure(let error):
|
|
||||||
completion(.failure(error))
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
case .failure(let error):
|
|
||||||
completion(.failure(error))
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.refreshProgress.completeTask()
|
||||||
|
completion(.success(()))
|
||||||
|
|
||||||
|
|
||||||
case .failure(let error):
|
case .failure(let error):
|
||||||
completion(.failure(error))
|
completion(.failure(error))
|
||||||
@ -663,6 +643,7 @@ private extension GoogleReaderCompatibleAccountDelegate {
|
|||||||
feed.homePageURL = subscription.homePageURL
|
feed.homePageURL = subscription.homePageURL
|
||||||
} else {
|
} else {
|
||||||
let feed = account.createFeed(with: subscription.name, url: subscription.url, feedID: subFeedId, homePageURL: subscription.homePageURL)
|
let feed = account.createFeed(with: subscription.name, url: subscription.url, feedID: subFeedId, homePageURL: subscription.homePageURL)
|
||||||
|
feed.iconURL = subscription.iconURL
|
||||||
feed.subscriptionID = String(subscription.feedID)
|
feed.subscriptionID = String(subscription.feedID)
|
||||||
account.addFeed(feed)
|
account.addFeed(feed)
|
||||||
}
|
}
|
||||||
@ -672,11 +653,11 @@ private extension GoogleReaderCompatibleAccountDelegate {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func syncTaggings(_ account: Account, _ taggings: [GoogleReaderCompatibleTagging]?) {
|
func syncTaggings(_ account: Account, _ subscriptions: [GoogleReaderCompatibleSubscription]?) {
|
||||||
|
|
||||||
guard let taggings = taggings else { return }
|
guard let subscriptions = subscriptions else { return }
|
||||||
|
|
||||||
os_log(.debug, log: log, "Syncing taggings with %ld taggings.", taggings.count)
|
os_log(.debug, log: log, "Syncing taggings with %ld subscriptions.", subscriptions.count)
|
||||||
|
|
||||||
// Set up some structures to make syncing easier
|
// Set up some structures to make syncing easier
|
||||||
let folderDict: [String: Folder] = {
|
let folderDict: [String: Folder] = {
|
||||||
@ -687,14 +668,21 @@ private extension GoogleReaderCompatibleAccountDelegate {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
let taggingsDict = taggings.reduce([String: [GoogleReaderCompatibleTagging]]()) { (dict, tagging) in
|
let taggingsDict = subscriptions.reduce([String: [GoogleReaderCompatibleSubscription]]()) { (dict, subscription) in
|
||||||
var taggedFeeds = dict
|
var taggedFeeds = dict
|
||||||
if var taggedFeed = taggedFeeds[tagging.name] {
|
|
||||||
taggedFeed.append(tagging)
|
// For each category that this feed belongs to, add the feed to that name in the dict
|
||||||
taggedFeeds[tagging.name] = taggedFeed
|
subscription.categories.forEach({ (category) in
|
||||||
} else {
|
let categoryName = category.categoryLabel.replacingOccurrences(of: "user/-/label/", with: "")
|
||||||
taggedFeeds[tagging.name] = [tagging]
|
|
||||||
}
|
if var taggedFeed = taggedFeeds[categoryName] {
|
||||||
|
taggedFeed.append(subscription)
|
||||||
|
taggedFeeds[categoryName] = taggedFeed
|
||||||
|
} else {
|
||||||
|
taggedFeeds[categoryName] = [subscription]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
return taggedFeeds
|
return taggedFeeds
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -719,14 +707,14 @@ private extension GoogleReaderCompatibleAccountDelegate {
|
|||||||
// Add any feeds not in the folder
|
// Add any feeds not in the folder
|
||||||
let folderFeedIds = folder.topLevelFeeds.map { $0.feedID }
|
let folderFeedIds = folder.topLevelFeeds.map { $0.feedID }
|
||||||
|
|
||||||
for tagging in groupedTaggings {
|
for subscription in groupedTaggings {
|
||||||
let taggingFeedID = String(tagging.feedID)
|
let taggingFeedID = String(subscription.feedID)
|
||||||
if !folderFeedIds.contains(taggingFeedID) {
|
if !folderFeedIds.contains(taggingFeedID) {
|
||||||
guard let feed = account.idToFeedDictionary[taggingFeedID] else {
|
guard let feed = account.idToFeedDictionary[taggingFeedID] else {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
DispatchQueue.main.sync {
|
DispatchQueue.main.sync {
|
||||||
saveFolderRelationship(for: feed, withFolderName: folderName, id: String(tagging.taggingID))
|
saveFolderRelationship(for: feed, withFolderName: folderName, id: String(subscription.feedID))
|
||||||
folder.addFeed(feed)
|
folder.addFeed(feed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -734,7 +722,7 @@ private extension GoogleReaderCompatibleAccountDelegate {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let taggedFeedIDs = Set(taggings.map { String($0.feedID) })
|
let taggedFeedIDs = Set(subscriptions.map { String($0.feedID) })
|
||||||
|
|
||||||
// Remove all feeds from the account container that have a tag
|
// Remove all feeds from the account container that have a tag
|
||||||
DispatchQueue.main.sync {
|
DispatchQueue.main.sync {
|
||||||
@ -747,28 +735,6 @@ private extension GoogleReaderCompatibleAccountDelegate {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func syncFavicons(_ account: Account, _ icons: [GoogleReaderCompatibleIcon]?) {
|
|
||||||
|
|
||||||
guard let icons = icons else { return }
|
|
||||||
|
|
||||||
os_log(.debug, log: log, "Syncing favicons with %ld icons.", icons.count)
|
|
||||||
|
|
||||||
let iconDict = Dictionary(uniqueKeysWithValues: icons.map { ($0.host, $0.url) } )
|
|
||||||
|
|
||||||
for feed in account.flattenedFeeds() {
|
|
||||||
for (key, value) in iconDict {
|
|
||||||
if feed.homePageURL?.contains(key) ?? false {
|
|
||||||
DispatchQueue.main.sync {
|
|
||||||
feed.faviconURL = value
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func sendArticleStatuses(_ statuses: [SyncStatus],
|
func sendArticleStatuses(_ statuses: [SyncStatus],
|
||||||
apiCall: ([Int], @escaping (Result<Void, Error>) -> Void) -> Void,
|
apiCall: ([Int], @escaping (Result<Void, Error>) -> Void) -> Void,
|
||||||
completion: @escaping (() -> Void)) {
|
completion: @escaping (() -> Void)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user