Change so that we always refresh after updating sync service credentials. Fixes #2713

This commit is contained in:
Maurice Parker 2021-01-09 15:15:14 -06:00
parent a88afc77d5
commit fa3d76d034
8 changed files with 60 additions and 83 deletions

View File

@ -90,10 +90,8 @@ class AccountsFeedWranglerWindowController: NSWindowController {
self.errorMessageLabel.stringValue = NSLocalizedString("Invalid email/password combination.", comment: "Credentials Error") self.errorMessageLabel.stringValue = NSLocalizedString("Invalid email/password combination.", comment: "Credentials Error")
return return
} }
var newAccount = false
if self.account == nil { if self.account == nil {
self.account = AccountManager.shared.createAccount(type: .feedWrangler) self.account = AccountManager.shared.createAccount(type: .feedWrangler)
newAccount = true
} }
do { do {
@ -101,16 +99,16 @@ class AccountsFeedWranglerWindowController: NSWindowController {
try self.account?.removeCredentials(type: .feedWranglerToken) try self.account?.removeCredentials(type: .feedWranglerToken)
try self.account?.storeCredentials(credentials) try self.account?.storeCredentials(credentials)
try self.account?.storeCredentials(validatedCredentials) try self.account?.storeCredentials(validatedCredentials)
if newAccount {
self.account?.refreshAll() { result in self.account?.refreshAll() { result in
switch result { switch result {
case .success: case .success:
break break
case .failure(let error): case .failure(let error):
NSApplication.shared.presentError(error) NSApplication.shared.presentError(error)
}
} }
} }
self.hostWindow?.endSheet(self.window!, returnCode: NSApplication.ModalResponse.OK) self.hostWindow?.endSheet(self.window!, returnCode: NSApplication.ModalResponse.OK)
} catch { } catch {
self.errorMessageLabel.stringValue = NSLocalizedString("Keychain error while storing credentials.", comment: "Credentials Error") self.errorMessageLabel.stringValue = NSLocalizedString("Keychain error while storing credentials.", comment: "Credentials Error")

View File

@ -93,25 +93,23 @@ class AccountsFeedbinWindowController: NSWindowController {
return return
} }
var newAccount = false
if self.account == nil { if self.account == nil {
self.account = AccountManager.shared.createAccount(type: .feedbin) self.account = AccountManager.shared.createAccount(type: .feedbin)
newAccount = true
} }
do { do {
try self.account?.removeCredentials(type: .basic) try self.account?.removeCredentials(type: .basic)
try self.account?.storeCredentials(validatedCredentials) try self.account?.storeCredentials(validatedCredentials)
if newAccount {
self.account?.refreshAll() { result in self.account?.refreshAll() { result in
switch result { switch result {
case .success: case .success:
break break
case .failure(let error): case .failure(let error):
NSApplication.shared.presentError(error) NSApplication.shared.presentError(error)
}
} }
} }
self.hostWindow?.endSheet(self.window!, returnCode: NSApplication.ModalResponse.OK) self.hostWindow?.endSheet(self.window!, returnCode: NSApplication.ModalResponse.OK)
} catch { } catch {
self.errorMessageLabel.stringValue = NSLocalizedString("Keychain error while storing credentials.", comment: "Credentials Error") self.errorMessageLabel.stringValue = NSLocalizedString("Keychain error while storing credentials.", comment: "Credentials Error")

View File

@ -90,10 +90,9 @@ class AccountsNewsBlurWindowController: NSWindowController {
self.errorMessageLabel.stringValue = NSLocalizedString("Invalid email/password combination.", comment: "Credentials Error") self.errorMessageLabel.stringValue = NSLocalizedString("Invalid email/password combination.", comment: "Credentials Error")
return return
} }
var newAccount = false
if self.account == nil { if self.account == nil {
self.account = AccountManager.shared.createAccount(type: .newsBlur) self.account = AccountManager.shared.createAccount(type: .newsBlur)
newAccount = true
} }
do { do {
@ -101,16 +100,16 @@ class AccountsNewsBlurWindowController: NSWindowController {
try self.account?.removeCredentials(type: .newsBlurSessionId) try self.account?.removeCredentials(type: .newsBlurSessionId)
try self.account?.storeCredentials(credentials) try self.account?.storeCredentials(credentials)
try self.account?.storeCredentials(validatedCredentials) try self.account?.storeCredentials(validatedCredentials)
if newAccount {
self.account?.refreshAll() { result in self.account?.refreshAll() { result in
switch result { switch result {
case .success: case .success:
break break
case .failure(let error): case .failure(let error):
NSApplication.shared.presentError(error) NSApplication.shared.presentError(error)
}
} }
} }
self.hostWindow?.endSheet(self.window!, returnCode: NSApplication.ModalResponse.OK) self.hostWindow?.endSheet(self.window!, returnCode: NSApplication.ModalResponse.OK)
} catch { } catch {
self.errorMessageLabel.stringValue = NSLocalizedString("Keychain error while storing credentials.", comment: "Credentials Error") self.errorMessageLabel.stringValue = NSLocalizedString("Keychain error while storing credentials.", comment: "Credentials Error")

View File

@ -144,11 +144,8 @@ class AccountsReaderAPIWindowController: NSWindowController {
return return
} }
var newAccount = false
if self.account == nil { if self.account == nil {
self.account = AccountManager.shared.createAccount(type: self.accountType!) self.account = AccountManager.shared.createAccount(type: self.accountType!)
newAccount = true
} }
do { do {
@ -159,16 +156,15 @@ class AccountsReaderAPIWindowController: NSWindowController {
try self.account?.storeCredentials(credentials) try self.account?.storeCredentials(credentials)
try self.account?.storeCredentials(validatedCredentials) try self.account?.storeCredentials(validatedCredentials)
if newAccount { self.account?.refreshAll() { result in
self.account?.refreshAll() { result in switch result {
switch result { case .success:
case .success: break
break case .failure(let error):
case .failure(let error): NSApplication.shared.presentError(error)
NSApplication.shared.presentError(error)
}
} }
} }
self.hostWindow?.endSheet(self.window!, returnCode: NSApplication.ModalResponse.OK) self.hostWindow?.endSheet(self.window!, returnCode: NSApplication.ModalResponse.OK)
} catch { } catch {
self.errorMessageLabel.stringValue = NSLocalizedString("Keychain error while storing credentials.", comment: "Credentials Error") self.errorMessageLabel.stringValue = NSLocalizedString("Keychain error while storing credentials.", comment: "Credentials Error")

View File

@ -109,10 +109,8 @@ class FeedWranglerAccountViewController: UITableViewController {
return return
} }
var newAccount = false
if self.account == nil { if self.account == nil {
self.account = AccountManager.shared.createAccount(type: .feedWrangler) self.account = AccountManager.shared.createAccount(type: .feedWrangler)
newAccount = true
} }
do { do {
@ -121,14 +119,12 @@ class FeedWranglerAccountViewController: UITableViewController {
try self.account?.storeCredentials(credentials) try self.account?.storeCredentials(credentials)
try self.account?.storeCredentials(validatedCredentials) try self.account?.storeCredentials(validatedCredentials)
if newAccount { self.account?.refreshAll { result in
self.account?.refreshAll { result in switch result {
switch result { case .success:
case .success: break
break case .failure(let error):
case .failure(let error): self.presentError(error)
self.presentError(error)
}
} }
} }

View File

@ -106,10 +106,8 @@ class FeedbinAccountViewController: UITableViewController {
switch result { switch result {
case .success(let credentials): case .success(let credentials):
if let credentials = credentials { if let credentials = credentials {
var newAccount = false
if self.account == nil { if self.account == nil {
self.account = AccountManager.shared.createAccount(type: .feedbin) self.account = AccountManager.shared.createAccount(type: .feedbin)
newAccount = true
} }
do { do {
@ -119,14 +117,12 @@ class FeedbinAccountViewController: UITableViewController {
} catch {} } catch {}
try self.account?.storeCredentials(credentials) try self.account?.storeCredentials(credentials)
if newAccount { self.account?.refreshAll() { result in
self.account?.refreshAll() { result in switch result {
switch result { case .success:
case .success: break
break case .failure(let error):
case .failure(let error): self.presentError(error)
self.presentError(error)
}
} }
} }

View File

@ -108,10 +108,9 @@ class NewsBlurAccountViewController: UITableViewController {
switch result { switch result {
case .success(let sessionCredentials): case .success(let sessionCredentials):
if let sessionCredentials = sessionCredentials { if let sessionCredentials = sessionCredentials {
var newAccount = false
if self.account == nil { if self.account == nil {
self.account = AccountManager.shared.createAccount(type: .newsBlur) self.account = AccountManager.shared.createAccount(type: .newsBlur)
newAccount = true
} }
do { do {
@ -123,14 +122,12 @@ class NewsBlurAccountViewController: UITableViewController {
try self.account?.storeCredentials(basicCredentials) try self.account?.storeCredentials(basicCredentials)
try self.account?.storeCredentials(sessionCredentials) try self.account?.storeCredentials(sessionCredentials)
if newAccount { self.account?.refreshAll() { result in
self.account?.refreshAll() { result in switch result {
switch result { case .success:
case .success: break
break case .failure(let error):
case .failure(let error): self.presentError(error)
self.presentError(error)
}
} }
} }

View File

@ -159,30 +159,27 @@ class ReaderAPIAccountViewController: UITableViewController {
switch result { switch result {
case .success(let validatedCredentials): case .success(let validatedCredentials):
if let validatedCredentials = validatedCredentials { if let validatedCredentials = validatedCredentials {
var newAccount = false
if self.account == nil { if self.account == nil {
self.account = AccountManager.shared.createAccount(type: type) self.account = AccountManager.shared.createAccount(type: type)
newAccount = true
} }
do { do {
self.account?.endpointURL = url self.account?.endpointURL = url
try self.account?.removeCredentials(type: .readerBasic) try? self.account?.removeCredentials(type: .readerBasic)
try self.account?.removeCredentials(type: .readerAPIKey) try? self.account?.removeCredentials(type: .readerAPIKey)
try self.account?.storeCredentials(credentials) try self.account?.storeCredentials(credentials)
try self.account?.storeCredentials(validatedCredentials) try self.account?.storeCredentials(validatedCredentials)
self.dismiss(animated: true, completion: nil) self.dismiss(animated: true, completion: nil)
if newAccount { self.account?.refreshAll() { result in
self.account?.refreshAll() { result in switch result {
switch result { case .success:
case .success: break
break case .failure(let error):
case .failure(let error): self.showError(NSLocalizedString(error.localizedDescription, comment: "Accoount Refresh Error"))
self.showError(NSLocalizedString(error.localizedDescription, comment: "Accoount Refresh Error"))
}
} }
} }