forked from shadowfacts/Tusker
Fix crash when adding account
Adding a UserData.LocalAccountInfo with a nil username while the PreferencesView is on screen will cause a crash, since it triggers a Combine publish upon which the PreferencesView expects to be able to display the username of all accounts.
This commit is contained in:
parent
98529ca5af
commit
88e4f52b5d
|
@ -68,13 +68,16 @@ extension OnboardingViewController: InstanceSelectorTableViewControllerDelegate
|
||||||
let authCode = item.value else { return }
|
let authCode = item.value else { return }
|
||||||
|
|
||||||
mastodonController.authorize(authorizationCode: authCode) { (accessToken) in
|
mastodonController.authorize(authorizationCode: authCode) { (accessToken) in
|
||||||
let accountInfo = LocalData.shared.addAccount(instanceURL: instanceURL, clientID: clientID, clientSecret: clientSecret, username: nil, accessToken: accessToken)
|
// construct a temporary UserAccountInfo instance for the MastodonController to use to fetch it's own account
|
||||||
mastodonController.accountInfo = accountInfo
|
let tempAccountInfo = LocalData.UserAccountInfo(id: "temp", instanceURL: instanceURL, clientID: clientID, clientSecret: clientSecret, username: nil, accessToken: accessToken)
|
||||||
|
mastodonController.accountInfo = tempAccountInfo
|
||||||
|
|
||||||
mastodonController.getOwnAccount { (account) in
|
mastodonController.getOwnAccount { (account) in
|
||||||
LocalData.shared.setUsername(for: accountInfo, username: account.username)
|
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
// this needs to happen on the main thread because it publishes a new value for the ObservableObject
|
||||||
|
let accountInfo = LocalData.shared.addAccount(instanceURL: instanceURL, clientID: clientID, clientSecret: clientSecret, username: account.username, accessToken: accessToken)
|
||||||
|
mastodonController.accountInfo = accountInfo
|
||||||
|
|
||||||
self.onboardingDelegate?.didFinishOnboarding(account: accountInfo)
|
self.onboardingDelegate?.didFinishOnboarding(account: accountInfo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue