diff --git a/Frameworks/Account/Feedbin/FeedbinAPICaller.swift b/Frameworks/Account/Feedbin/FeedbinAPICaller.swift index 41fafdf03..3701abb30 100644 --- a/Frameworks/Account/Feedbin/FeedbinAPICaller.swift +++ b/Frameworks/Account/Feedbin/FeedbinAPICaller.swift @@ -324,7 +324,7 @@ final class FeedbinAPICaller: NSObject { } - func retrieveEntries(completion: @escaping (Result<([FeedbinEntry]?, String?), Error>) -> Void) { + func retrieveEntries(completion: @escaping (Result<([FeedbinEntry]?, String?, Int?), Error>) -> Void) { let since: Date = { if let lastArticleFetch = accountMetadata?.lastArticleFetch { @@ -348,7 +348,8 @@ final class FeedbinAPICaller: NSObject { self?.accountMetadata?.lastArticleFetch = dateInfo?.date let pagingInfo = HTTPLinkPagingInfo(urlResponse: response) - completion(.success((entries, pagingInfo.nextPage))) + let lastPageNumber = self?.extractPageNumber(link: pagingInfo.lastPage) + completion(.success((entries, pagingInfo.nextPage, lastPageNumber))) case .failure(let error): completion(.failure(error)) @@ -358,6 +359,25 @@ final class FeedbinAPICaller: NSObject { } + func extractPageNumber(link: String?) -> Int? { + + guard let link = link else { + return nil + } + + if let lowerBound = link.range(of: "page=")?.upperBound { + if let upperBound = link.range(of: "&")?.lowerBound { + return Int(link[lowerBound..")?.lowerBound { + return Int(link[lowerBound..) -> Void) { guard let callURL = URL(string: page) else { diff --git a/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift b/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift index 426db169b..3f2487ae0 100644 --- a/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift +++ b/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift @@ -72,6 +72,8 @@ final class FeedbinAccountDelegate: AccountDelegate { func refreshAll(for account: Account, completion: (() -> Void)? = nil) { + refreshProgress.addToNumberOfTasksAndRemaining(5) + refreshAccount(account) { [weak self] result in switch result { case .success(): @@ -85,6 +87,7 @@ final class FeedbinAccountDelegate: AccountDelegate { case .failure(let error): DispatchQueue.main.async { completion?() + self?.refreshProgress.clear() self?.handleError(error) } } @@ -438,6 +441,7 @@ private extension FeedbinAccountDelegate { BatchUpdate.shared.perform { self?.syncFolders(account, tags) } + self?.refreshProgress.completeTask() self?.refreshFeeds(account, completion: completion) case .failure(let error): completion(.failure(error)) @@ -494,10 +498,12 @@ private extension FeedbinAccountDelegate { switch result { case .success(let subscriptions): + self?.refreshProgress.completeTask() self?.caller.retrieveTaggings { [weak self] result in switch result { case .success(let taggings): + self?.refreshProgress.completeTask() self?.caller.retrieveIcons { [weak self] result in switch result { case .success(let icons): @@ -508,6 +514,7 @@ private extension FeedbinAccountDelegate { self?.syncFavicons(account, icons) } + self?.refreshProgress.completeTask() completion(.success(())) case .failure(let error): @@ -922,14 +929,21 @@ private extension FeedbinAccountDelegate { caller.retrieveEntries() { [weak self] result in switch result { - case .success(let (entries, page)): + case .success(let (entries, page, lastPageNumber)): + + if let last = lastPageNumber { + self?.refreshProgress.addToNumberOfTasksAndRemaining(last - 1) + } self?.processEntries(account: account, entries: entries) { + + self?.refreshProgress.completeTask() self?.refreshArticles(account, page: page) { guard let self = self else { return } os_log(.debug, log: self.log, "Done refreshing articles.") completion() } + } case .failure(let error): @@ -955,6 +969,7 @@ private extension FeedbinAccountDelegate { case .success(let (entries, nextPage)): self?.processEntries(account: account, entries: entries) { + self?.refreshProgress.completeTask() self?.refreshArticles(account, page: nextPage, completion: completion) } diff --git a/submodules/RSWeb b/submodules/RSWeb index 517583fec..809f9e168 160000 --- a/submodules/RSWeb +++ b/submodules/RSWeb @@ -1 +1 @@ -Subproject commit 517583fecf997254642ff7dfd629b5445b661e10 +Subproject commit 809f9e1680594990a98e9266c974b5cbad6fa788