From fa3d76d03419c3d4b1ab65e42af5a75c89a9897f Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sat, 9 Jan 2021 15:15:14 -0600 Subject: [PATCH] Change so that we always refresh after updating sync service credentials. Fixes #2713 --- ...AccountsFeedWranglerWindowController.swift | 18 +++++++--------- .../AccountsFeedbinWindowController.swift | 18 +++++++--------- .../AccountsNewsBlurWindowController.swift | 19 ++++++++--------- .../AccountsReaderAPIWindowController.swift | 18 +++++++--------- .../FeedWranglerAccountViewController.swift | 16 ++++++-------- .../FeedbinAccountViewController.swift | 16 ++++++-------- .../NewsBlurAccountViewController.swift | 17 +++++++-------- .../ReaderAPIAccountViewController.swift | 21 ++++++++----------- 8 files changed, 60 insertions(+), 83 deletions(-) diff --git a/Mac/Preferences/Accounts/AccountsFeedWranglerWindowController.swift b/Mac/Preferences/Accounts/AccountsFeedWranglerWindowController.swift index 4adaf8bf3..c17ff705a 100644 --- a/Mac/Preferences/Accounts/AccountsFeedWranglerWindowController.swift +++ b/Mac/Preferences/Accounts/AccountsFeedWranglerWindowController.swift @@ -90,10 +90,8 @@ class AccountsFeedWranglerWindowController: NSWindowController { self.errorMessageLabel.stringValue = NSLocalizedString("Invalid email/password combination.", comment: "Credentials Error") return } - var newAccount = false if self.account == nil { self.account = AccountManager.shared.createAccount(type: .feedWrangler) - newAccount = true } do { @@ -101,16 +99,16 @@ class AccountsFeedWranglerWindowController: NSWindowController { try self.account?.removeCredentials(type: .feedWranglerToken) try self.account?.storeCredentials(credentials) try self.account?.storeCredentials(validatedCredentials) - if newAccount { - self.account?.refreshAll() { result in - switch result { - case .success: - break - case .failure(let error): - NSApplication.shared.presentError(error) - } + + self.account?.refreshAll() { result in + switch result { + case .success: + break + case .failure(let error): + NSApplication.shared.presentError(error) } } + self.hostWindow?.endSheet(self.window!, returnCode: NSApplication.ModalResponse.OK) } catch { self.errorMessageLabel.stringValue = NSLocalizedString("Keychain error while storing credentials.", comment: "Credentials Error") diff --git a/Mac/Preferences/Accounts/AccountsFeedbinWindowController.swift b/Mac/Preferences/Accounts/AccountsFeedbinWindowController.swift index 8f9cce6ef..2dbba5b3c 100644 --- a/Mac/Preferences/Accounts/AccountsFeedbinWindowController.swift +++ b/Mac/Preferences/Accounts/AccountsFeedbinWindowController.swift @@ -93,25 +93,23 @@ class AccountsFeedbinWindowController: NSWindowController { return } - var newAccount = false if self.account == nil { self.account = AccountManager.shared.createAccount(type: .feedbin) - newAccount = true } do { try self.account?.removeCredentials(type: .basic) try self.account?.storeCredentials(validatedCredentials) - if newAccount { - self.account?.refreshAll() { result in - switch result { - case .success: - break - case .failure(let error): - NSApplication.shared.presentError(error) - } + + self.account?.refreshAll() { result in + switch result { + case .success: + break + case .failure(let error): + NSApplication.shared.presentError(error) } } + self.hostWindow?.endSheet(self.window!, returnCode: NSApplication.ModalResponse.OK) } catch { self.errorMessageLabel.stringValue = NSLocalizedString("Keychain error while storing credentials.", comment: "Credentials Error") diff --git a/Mac/Preferences/Accounts/AccountsNewsBlurWindowController.swift b/Mac/Preferences/Accounts/AccountsNewsBlurWindowController.swift index fe7682e56..0060bca95 100644 --- a/Mac/Preferences/Accounts/AccountsNewsBlurWindowController.swift +++ b/Mac/Preferences/Accounts/AccountsNewsBlurWindowController.swift @@ -90,10 +90,9 @@ class AccountsNewsBlurWindowController: NSWindowController { self.errorMessageLabel.stringValue = NSLocalizedString("Invalid email/password combination.", comment: "Credentials Error") return } - var newAccount = false + if self.account == nil { self.account = AccountManager.shared.createAccount(type: .newsBlur) - newAccount = true } do { @@ -101,16 +100,16 @@ class AccountsNewsBlurWindowController: NSWindowController { try self.account?.removeCredentials(type: .newsBlurSessionId) try self.account?.storeCredentials(credentials) try self.account?.storeCredentials(validatedCredentials) - if newAccount { - self.account?.refreshAll() { result in - switch result { - case .success: - break - case .failure(let error): - NSApplication.shared.presentError(error) - } + + self.account?.refreshAll() { result in + switch result { + case .success: + break + case .failure(let error): + NSApplication.shared.presentError(error) } } + self.hostWindow?.endSheet(self.window!, returnCode: NSApplication.ModalResponse.OK) } catch { self.errorMessageLabel.stringValue = NSLocalizedString("Keychain error while storing credentials.", comment: "Credentials Error") diff --git a/Mac/Preferences/Accounts/AccountsReaderAPIWindowController.swift b/Mac/Preferences/Accounts/AccountsReaderAPIWindowController.swift index d445afa92..85e79cb7e 100644 --- a/Mac/Preferences/Accounts/AccountsReaderAPIWindowController.swift +++ b/Mac/Preferences/Accounts/AccountsReaderAPIWindowController.swift @@ -144,11 +144,8 @@ class AccountsReaderAPIWindowController: NSWindowController { return } - - var newAccount = false if self.account == nil { self.account = AccountManager.shared.createAccount(type: self.accountType!) - newAccount = true } do { @@ -159,16 +156,15 @@ class AccountsReaderAPIWindowController: NSWindowController { try self.account?.storeCredentials(credentials) try self.account?.storeCredentials(validatedCredentials) - if newAccount { - self.account?.refreshAll() { result in - switch result { - case .success: - break - case .failure(let error): - NSApplication.shared.presentError(error) - } + self.account?.refreshAll() { result in + switch result { + case .success: + break + case .failure(let error): + NSApplication.shared.presentError(error) } } + self.hostWindow?.endSheet(self.window!, returnCode: NSApplication.ModalResponse.OK) } catch { self.errorMessageLabel.stringValue = NSLocalizedString("Keychain error while storing credentials.", comment: "Credentials Error") diff --git a/iOS/Account/FeedWranglerAccountViewController.swift b/iOS/Account/FeedWranglerAccountViewController.swift index 3e71ac7d3..120945ec1 100644 --- a/iOS/Account/FeedWranglerAccountViewController.swift +++ b/iOS/Account/FeedWranglerAccountViewController.swift @@ -109,10 +109,8 @@ class FeedWranglerAccountViewController: UITableViewController { return } - var newAccount = false if self.account == nil { self.account = AccountManager.shared.createAccount(type: .feedWrangler) - newAccount = true } do { @@ -121,14 +119,12 @@ class FeedWranglerAccountViewController: UITableViewController { try self.account?.storeCredentials(credentials) try self.account?.storeCredentials(validatedCredentials) - if newAccount { - self.account?.refreshAll { result in - switch result { - case .success: - break - case .failure(let error): - self.presentError(error) - } + self.account?.refreshAll { result in + switch result { + case .success: + break + case .failure(let error): + self.presentError(error) } } diff --git a/iOS/Account/FeedbinAccountViewController.swift b/iOS/Account/FeedbinAccountViewController.swift index 4dcb85e56..ac8836734 100644 --- a/iOS/Account/FeedbinAccountViewController.swift +++ b/iOS/Account/FeedbinAccountViewController.swift @@ -106,10 +106,8 @@ class FeedbinAccountViewController: UITableViewController { switch result { case .success(let credentials): if let credentials = credentials { - var newAccount = false if self.account == nil { self.account = AccountManager.shared.createAccount(type: .feedbin) - newAccount = true } do { @@ -119,14 +117,12 @@ class FeedbinAccountViewController: UITableViewController { } catch {} try self.account?.storeCredentials(credentials) - if newAccount { - self.account?.refreshAll() { result in - switch result { - case .success: - break - case .failure(let error): - self.presentError(error) - } + self.account?.refreshAll() { result in + switch result { + case .success: + break + case .failure(let error): + self.presentError(error) } } diff --git a/iOS/Account/NewsBlurAccountViewController.swift b/iOS/Account/NewsBlurAccountViewController.swift index 12dcb1439..cabd73951 100644 --- a/iOS/Account/NewsBlurAccountViewController.swift +++ b/iOS/Account/NewsBlurAccountViewController.swift @@ -108,10 +108,9 @@ class NewsBlurAccountViewController: UITableViewController { switch result { case .success(let sessionCredentials): if let sessionCredentials = sessionCredentials { - var newAccount = false + if self.account == nil { self.account = AccountManager.shared.createAccount(type: .newsBlur) - newAccount = true } do { @@ -123,14 +122,12 @@ class NewsBlurAccountViewController: UITableViewController { try self.account?.storeCredentials(basicCredentials) try self.account?.storeCredentials(sessionCredentials) - if newAccount { - self.account?.refreshAll() { result in - switch result { - case .success: - break - case .failure(let error): - self.presentError(error) - } + self.account?.refreshAll() { result in + switch result { + case .success: + break + case .failure(let error): + self.presentError(error) } } diff --git a/iOS/Account/ReaderAPIAccountViewController.swift b/iOS/Account/ReaderAPIAccountViewController.swift index c02733d1d..4e60f7c3b 100644 --- a/iOS/Account/ReaderAPIAccountViewController.swift +++ b/iOS/Account/ReaderAPIAccountViewController.swift @@ -159,30 +159,27 @@ class ReaderAPIAccountViewController: UITableViewController { switch result { case .success(let validatedCredentials): if let validatedCredentials = validatedCredentials { - var newAccount = false + if self.account == nil { self.account = AccountManager.shared.createAccount(type: type) - newAccount = true } do { self.account?.endpointURL = url - try self.account?.removeCredentials(type: .readerBasic) - try self.account?.removeCredentials(type: .readerAPIKey) + try? self.account?.removeCredentials(type: .readerBasic) + try? self.account?.removeCredentials(type: .readerAPIKey) try self.account?.storeCredentials(credentials) try self.account?.storeCredentials(validatedCredentials) self.dismiss(animated: true, completion: nil) - if newAccount { - self.account?.refreshAll() { result in - switch result { - case .success: - break - case .failure(let error): - self.showError(NSLocalizedString(error.localizedDescription, comment: "Accoount Refresh Error")) - } + self.account?.refreshAll() { result in + switch result { + case .success: + break + case .failure(let error): + self.showError(NSLocalizedString(error.localizedDescription, comment: "Accoount Refresh Error")) } }