Merge pull request #1438 from kielgillard/feedly-account-update-error
Check the account update error when updating a Feedly account…
This commit is contained in:
commit
2148bb29dc
|
@ -808,23 +808,23 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mark articleIDs as read. Will create statuses in the database and in memory as needed. Sends a .StatusesDidChange notification.
|
/// Mark articleIDs as read. Will create statuses in the database and in memory as needed. Sends a .StatusesDidChange notification.
|
||||||
func markAsRead(_ articleIDs: Set<String>) {
|
func markAsRead(_ articleIDs: Set<String>, completion: DatabaseCompletionBlock? = nil) {
|
||||||
mark(articleIDs: articleIDs, statusKey: .read, flag: true)
|
mark(articleIDs: articleIDs, statusKey: .read, flag: true, completion: completion)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mark articleIDs as unread. Will create statuses in the database and in memory as needed. Sends a .StatusesDidChange notification.
|
/// Mark articleIDs as unread. Will create statuses in the database and in memory as needed. Sends a .StatusesDidChange notification.
|
||||||
func markAsUnread(_ articleIDs: Set<String>) {
|
func markAsUnread(_ articleIDs: Set<String>, completion: DatabaseCompletionBlock? = nil) {
|
||||||
mark(articleIDs: articleIDs, statusKey: .read, flag: false)
|
mark(articleIDs: articleIDs, statusKey: .read, flag: false, completion: completion)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mark articleIDs as starred. Will create statuses in the database and in memory as needed. Sends a .StatusesDidChange notification.
|
/// Mark articleIDs as starred. Will create statuses in the database and in memory as needed. Sends a .StatusesDidChange notification.
|
||||||
func markAsStarred(_ articleIDs: Set<String>) {
|
func markAsStarred(_ articleIDs: Set<String>, completion: DatabaseCompletionBlock? = nil) {
|
||||||
mark(articleIDs: articleIDs, statusKey: .starred, flag: true)
|
mark(articleIDs: articleIDs, statusKey: .starred, flag: true, completion: completion)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mark articleIDs as unstarred. Will create statuses in the database and in memory as needed. Sends a .StatusesDidChange notification.
|
/// Mark articleIDs as unstarred. Will create statuses in the database and in memory as needed. Sends a .StatusesDidChange notification.
|
||||||
func markAsUnstarred(_ articleIDs: Set<String>) {
|
func markAsUnstarred(_ articleIDs: Set<String>, completion: DatabaseCompletionBlock? = nil) {
|
||||||
mark(articleIDs: articleIDs, statusKey: .starred, flag: false)
|
mark(articleIDs: articleIDs, statusKey: .starred, flag: false, completion: completion)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Empty caches that can reasonably be emptied. Call when the app goes in the background, for instance.
|
/// Empty caches that can reasonably be emptied. Call when the app goes in the background, for instance.
|
||||||
|
|
|
@ -32,12 +32,13 @@ final class FeedlySetStarredArticlesOperation: FeedlyOperation {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
account.fetchStarredArticleIDs { (articleIDsResult) in
|
account.fetchStarredArticleIDs { result in
|
||||||
if let localStarredArticleIDs = try? articleIDsResult.get() {
|
switch result {
|
||||||
|
case .success(let localStarredArticleIDs):
|
||||||
self.processStarredArticleIDs(localStarredArticleIDs)
|
self.processStarredArticleIDs(localStarredArticleIDs)
|
||||||
}
|
|
||||||
else {
|
case .failure(let error):
|
||||||
self.didFinish()
|
self.didFinish(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,15 +51,42 @@ private extension FeedlySetStarredArticlesOperation {
|
||||||
didFinish()
|
didFinish()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark as starred
|
|
||||||
let remoteStarredArticleIDs = allStarredEntryIdsProvider.entryIds
|
let remoteStarredArticleIDs = allStarredEntryIdsProvider.entryIds
|
||||||
account.mark(articleIDs: remoteStarredArticleIDs, statusKey: .starred, flag: true)
|
guard !remoteStarredArticleIDs.isEmpty else {
|
||||||
|
didFinish()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let group = DispatchGroup()
|
||||||
|
|
||||||
|
final class StarredStatusResults {
|
||||||
|
var markAsStarredError: Error?
|
||||||
|
var markAsUnstarredError: Error?
|
||||||
|
}
|
||||||
|
|
||||||
|
let results = StarredStatusResults()
|
||||||
|
|
||||||
|
group.enter()
|
||||||
|
account.markAsStarred(remoteStarredArticleIDs) { error in
|
||||||
|
results.markAsStarredError = error
|
||||||
|
group.leave()
|
||||||
|
}
|
||||||
|
|
||||||
// Mark as unstarred
|
|
||||||
let deltaUnstarredArticleIDs = localStarredArticleIDs.subtracting(remoteStarredArticleIDs)
|
let deltaUnstarredArticleIDs = localStarredArticleIDs.subtracting(remoteStarredArticleIDs)
|
||||||
account.mark(articleIDs: deltaUnstarredArticleIDs, statusKey: .starred, flag: false)
|
group.enter()
|
||||||
|
account.markAsUnstarred(deltaUnstarredArticleIDs) { error in
|
||||||
|
results.markAsUnstarredError = error
|
||||||
|
group.leave()
|
||||||
|
}
|
||||||
|
|
||||||
didFinish()
|
group.notify(queue: .main) {
|
||||||
|
let markingError = results.markAsStarredError ?? results.markAsUnstarredError
|
||||||
|
guard let error = markingError else {
|
||||||
|
self.didFinish()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
self.didFinish(error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,12 +32,13 @@ final class FeedlySetUnreadArticlesOperation: FeedlyOperation {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
account.fetchUnreadArticleIDs { articleIDsResult in
|
account.fetchUnreadArticleIDs { result in
|
||||||
if let localUnreadArticleIDs = try? articleIDsResult.get() {
|
switch result {
|
||||||
|
case .success(let localUnreadArticleIDs):
|
||||||
self.processUnreadArticleIDs(localUnreadArticleIDs)
|
self.processUnreadArticleIDs(localUnreadArticleIDs)
|
||||||
}
|
|
||||||
else {
|
case .failure(let error):
|
||||||
self.didFinish()
|
self.didFinish(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,11 +53,40 @@ private extension FeedlySetUnreadArticlesOperation {
|
||||||
}
|
}
|
||||||
|
|
||||||
let remoteUnreadArticleIDs = allUnreadIdsProvider.entryIds
|
let remoteUnreadArticleIDs = allUnreadIdsProvider.entryIds
|
||||||
account.markAsUnread(remoteUnreadArticleIDs)
|
guard !remoteUnreadArticleIDs.isEmpty else {
|
||||||
|
didFinish()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let group = DispatchGroup()
|
||||||
|
|
||||||
|
final class ReadStatusResults {
|
||||||
|
var markAsUnreadError: Error?
|
||||||
|
var markAsReadError: Error?
|
||||||
|
}
|
||||||
|
|
||||||
|
let results = ReadStatusResults()
|
||||||
|
|
||||||
|
group.enter()
|
||||||
|
account.markAsUnread(remoteUnreadArticleIDs) { error in
|
||||||
|
results.markAsUnreadError = error
|
||||||
|
group.leave()
|
||||||
|
}
|
||||||
|
|
||||||
let articleIDsToMarkRead = localUnreadArticleIDs.subtracting(remoteUnreadArticleIDs)
|
let articleIDsToMarkRead = localUnreadArticleIDs.subtracting(remoteUnreadArticleIDs)
|
||||||
account.markAsRead(articleIDsToMarkRead)
|
group.enter()
|
||||||
|
account.markAsRead(articleIDsToMarkRead) { error in
|
||||||
|
results.markAsReadError = error
|
||||||
|
group.leave()
|
||||||
|
}
|
||||||
|
|
||||||
didFinish()
|
group.notify(queue: .main) {
|
||||||
|
let markingError = results.markAsReadError ?? results.markAsUnreadError
|
||||||
|
guard let error = markingError else {
|
||||||
|
self.didFinish()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
self.didFinish(error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,7 @@ final class FeedlySyncAllOperation: FeedlyOperation {
|
||||||
|
|
||||||
// Get each and every starred article.
|
// Get each and every starred article.
|
||||||
let syncStarred = FeedlySyncStarredArticlesOperation(account: account, credentials: credentials, service: getStarredArticlesService, log: log)
|
let syncStarred = FeedlySyncStarredArticlesOperation(account: account, credentials: credentials, service: getStarredArticlesService, log: log)
|
||||||
|
syncStarred.delegate = self
|
||||||
syncStarred.downloadProgress = downloadProgress
|
syncStarred.downloadProgress = downloadProgress
|
||||||
syncStarred.addDependency(createFeedsOperation)
|
syncStarred.addDependency(createFeedsOperation)
|
||||||
self.operationQueue.addOperation(syncStarred)
|
self.operationQueue.addOperation(syncStarred)
|
||||||
|
|
|
@ -31,7 +31,12 @@ final class FeedlyUpdateAccountFeedsWithItemsOperation: FeedlyOperation {
|
||||||
|
|
||||||
let webFeedIDsAndItems = organisedItemsProvider.parsedItemsKeyedByFeedId
|
let webFeedIDsAndItems = organisedItemsProvider.parsedItemsKeyedByFeedId
|
||||||
|
|
||||||
account.update(webFeedIDsAndItems: webFeedIDsAndItems, defaultRead: true) { _ in
|
account.update(webFeedIDsAndItems: webFeedIDsAndItems, defaultRead: true) { databaseError in
|
||||||
|
if let error = databaseError {
|
||||||
|
self.didFinish(error)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
os_log(.debug, log: self.log, "Updated %i feeds for \"%@\"", webFeedIDsAndItems.count, self.organisedItemsProvider.providerName)
|
os_log(.debug, log: self.log, "Updated %i feeds for \"%@\"", webFeedIDsAndItems.count, self.organisedItemsProvider.providerName)
|
||||||
self.didFinish()
|
self.didFinish()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue