diff --git a/Account/Sources/Account/Account.swift b/Account/Sources/Account/Account.swift index 81bbe56d6..b2f0c2076 100644 --- a/Account/Sources/Account/Account.swift +++ b/Account/Sources/Account/Account.swift @@ -443,21 +443,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, } public func syncArticleStatus(completion: ((Result) -> Void)? = nil) { - delegate.sendArticleStatus(for: self) { [unowned self] result in - switch result { - case .success: - self.delegate.refreshArticleStatus(for: self) { result in - switch result { - case .success: - completion?(.success(())) - case .failure(let error): - completion?(.failure(error)) - } - } - case .failure(let error): - completion?(.failure(error)) - } - } + delegate.syncArticleStatus(for: self, completion: completion) } public func importOPML(_ opmlFile: URL, completion: @escaping (Result) -> Void) { diff --git a/Account/Sources/Account/AccountDelegate.swift b/Account/Sources/Account/AccountDelegate.swift index 1f8584406..93a998561 100644 --- a/Account/Sources/Account/AccountDelegate.swift +++ b/Account/Sources/Account/AccountDelegate.swift @@ -26,6 +26,7 @@ protocol AccountDelegate { func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any], completion: @escaping () -> Void) func refreshAll(for account: Account, completion: @escaping (Result) -> Void) + func syncArticleStatus(for account: Account, completion: ((Result) -> Void)?) func sendArticleStatus(for account: Account, completion: @escaping ((Result) -> Void)) func refreshArticleStatus(for account: Account, completion: @escaping ((Result) -> Void)) diff --git a/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift b/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift index 808d2add8..98baf7565 100644 --- a/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift +++ b/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift @@ -92,6 +92,24 @@ final class CloudKitAccountDelegate: AccountDelegate { standardRefreshAll(for: account, completion: completion) } + func syncArticleStatus(for account: Account, completion: ((Result) -> Void)? = nil) { + sendArticleStatus(for: account) { result in + switch result { + case .success: + self.refreshArticleStatus(for: account) { result in + switch result { + case .success: + completion?(.success(())) + case .failure(let error): + completion?(.failure(error)) + } + } + case .failure(let error): + completion?(.failure(error)) + } + } + } + func sendArticleStatus(for account: Account, completion: @escaping ((Result) -> Void)) { sendArticleStatus(for: account, showProgress: false, completion: completion) } diff --git a/Account/Sources/Account/FeedWrangler/FeedWranglerAccountDelegate.swift b/Account/Sources/Account/FeedWrangler/FeedWranglerAccountDelegate.swift index 11e7d130b..1be0ec832 100644 --- a/Account/Sources/Account/FeedWrangler/FeedWranglerAccountDelegate.swift +++ b/Account/Sources/Account/FeedWrangler/FeedWranglerAccountDelegate.swift @@ -150,6 +150,24 @@ final class FeedWranglerAccountDelegate: AccountDelegate { } } + func syncArticleStatus(for account: Account, completion: ((Result) -> Void)? = nil) { + sendArticleStatus(for: account) { result in + switch result { + case .success: + self.refreshArticleStatus(for: account) { result in + switch result { + case .success: + completion?(.success(())) + case .failure(let error): + completion?(.failure(error)) + } + } + case .failure(let error): + completion?(.failure(error)) + } + } + } + func refreshArticles(for account: Account, page: Int = 0, completion: @escaping ((Result) -> Void)) { os_log(.debug, log: log, "Refreshing articles, page: %d...", page) diff --git a/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift b/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift index 78d81d4ee..418711849 100644 --- a/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift +++ b/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift @@ -112,6 +112,24 @@ final class FeedbinAccountDelegate: AccountDelegate { } + func syncArticleStatus(for account: Account, completion: ((Result) -> Void)? = nil) { + sendArticleStatus(for: account) { result in + switch result { + case .success: + self.refreshArticleStatus(for: account) { result in + switch result { + case .success: + completion?(.success(())) + case .failure(let error): + completion?(.failure(error)) + } + } + case .failure(let error): + completion?(.failure(error)) + } + } + } + func sendArticleStatus(for account: Account, completion: @escaping ((Result) -> Void)) { os_log(.debug, log: log, "Sending article statuses...") diff --git a/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift b/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift index 1cd3e2aed..e2df06bf3 100644 --- a/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift +++ b/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift @@ -145,6 +145,24 @@ final class FeedlyAccountDelegate: AccountDelegate { operationQueue.add(syncAllOperation) } + func syncArticleStatus(for account: Account, completion: ((Result) -> Void)? = nil) { + sendArticleStatus(for: account) { result in + switch result { + case .success: + self.refreshArticleStatus(for: account) { result in + switch result { + case .success: + completion?(.success(())) + case .failure(let error): + completion?(.failure(error)) + } + } + case .failure(let error): + completion?(.failure(error)) + } + } + } + func sendArticleStatus(for account: Account, completion: @escaping ((Result) -> Void)) { // Ensure remote articles have the same status as they do locally. let send = FeedlySendArticleStatusesOperation(database: database, service: caller, log: log) diff --git a/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift b/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift index 2006f2973..456c8b738 100644 --- a/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift +++ b/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift @@ -96,6 +96,10 @@ final class LocalAccountDelegate: AccountDelegate { } + func syncArticleStatus(for account: Account, completion: ((Result) -> Void)? = nil) { + completion?(.success(())) + } + func sendArticleStatus(for account: Account, completion: @escaping ((Result) -> Void)) { completion(.success(())) } diff --git a/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift b/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift index b13ba7da1..b415d03d6 100644 --- a/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift +++ b/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift @@ -114,6 +114,24 @@ final class NewsBlurAccountDelegate: AccountDelegate { } } + func syncArticleStatus(for account: Account, completion: ((Result) -> Void)? = nil) { + sendArticleStatus(for: account) { result in + switch result { + case .success: + self.refreshArticleStatus(for: account) { result in + switch result { + case .success: + completion?(.success(())) + case .failure(let error): + completion?(.failure(error)) + } + } + case .failure(let error): + completion?(.failure(error)) + } + } + } + func sendArticleStatus(for account: Account, completion: @escaping (Result) -> ()) { os_log(.debug, log: log, "Sending story statuses...") diff --git a/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift b/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift index 6afb25e87..84d8b7353 100644 --- a/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift +++ b/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift @@ -131,6 +131,29 @@ final class ReaderAPIAccountDelegate: AccountDelegate { } + func syncArticleStatus(for account: Account, completion: ((Result) -> Void)? = nil) { + guard variant != .inoreader else { + completion?(.success(())) + return + } + + sendArticleStatus(for: account) { result in + switch result { + case .success: + self.refreshArticleStatus(for: account) { result in + switch result { + case .success: + completion?(.success(())) + case .failure(let error): + completion?(.failure(error)) + } + } + case .failure(let error): + completion?(.failure(error)) + } + } + } + func sendArticleStatus(for account: Account, completion: @escaping ((Result) -> Void)) { os_log(.debug, log: log, "Sending article statuses...") diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index ee332f0a0..c933c3b43 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -370,22 +370,28 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { return IndexPath(row: 0, section: destIndexPath.section) } else { let identifier = makeIdentifier(sortedNodes[index]) - let candidateIndexPath = dataSource.indexPath(for: identifier)! - let movementAdjustment = sourceIndexPath < destIndexPath ? 1 : 0 - return IndexPath(row: candidateIndexPath.row - movementAdjustment, section: candidateIndexPath.section) + if let candidateIndexPath = dataSource.indexPath(for: identifier) { + let movementAdjustment = sourceIndexPath < destIndexPath ? 1 : 0 + return IndexPath(row: candidateIndexPath.row - movementAdjustment, section: candidateIndexPath.section) + } else { + return sourceIndexPath + } } } else { if index >= sortedNodes.count { let identifier = makeIdentifier(sortedNodes[sortedNodes.count - 1]) - let lastSortedIndexPath = dataSource.indexPath(for: identifier)! - let movementAdjustment = sourceIndexPath > destIndexPath ? 1 : 0 - return IndexPath(row: lastSortedIndexPath.row + movementAdjustment, section: lastSortedIndexPath.section) + if let lastSortedIndexPath = dataSource.indexPath(for: identifier) { + let movementAdjustment = sourceIndexPath > destIndexPath ? 1 : 0 + return IndexPath(row: lastSortedIndexPath.row + movementAdjustment, section: lastSortedIndexPath.section) + } else { + return sourceIndexPath + } } else { let movementAdjustment = sourceIndexPath < destIndexPath ? 1 : 0 let identifer = makeIdentifier(sortedNodes[index - movementAdjustment]) - return dataSource.indexPath(for: identifer)! + return dataSource.indexPath(for: identifer) ?? sourceIndexPath } } diff --git a/xcconfig/common/NetNewsWire_ios_target_common.xcconfig b/xcconfig/common/NetNewsWire_ios_target_common.xcconfig index 28898b46b..e8b2c3545 100644 --- a/xcconfig/common/NetNewsWire_ios_target_common.xcconfig +++ b/xcconfig/common/NetNewsWire_ios_target_common.xcconfig @@ -1,7 +1,7 @@ // High Level Settings common to both the iOS application and any extensions we bundle with it MARKETING_VERSION = 6.0 -CURRENT_PROJECT_VERSION = 600 +CURRENT_PROJECT_VERSION = 601 ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon