Provide UserAccountInfo to MastodonController at initialization
This commit is contained in:
parent
878744b636
commit
06f7e306e0
|
@ -27,11 +27,7 @@ class MastodonController: ObservableObject {
|
|||
if let controller = all[account] {
|
||||
return controller
|
||||
} else {
|
||||
let controller = MastodonController(instanceURL: account.instanceURL)
|
||||
controller.accountInfo = account
|
||||
controller.client.clientID = account.clientID
|
||||
controller.client.clientSecret = account.clientSecret
|
||||
controller.client.accessToken = account.accessToken
|
||||
let controller = MastodonController(instanceURL: account.instanceURL, accountInfo: account)
|
||||
all[account] = controller
|
||||
return controller
|
||||
}
|
||||
|
@ -72,11 +68,15 @@ class MastodonController: ObservableObject {
|
|||
accountInfo != nil
|
||||
}
|
||||
|
||||
init(instanceURL: URL, transient: Bool = false) {
|
||||
init(instanceURL: URL, accountInfo: UserAccountInfo?) {
|
||||
self.instanceURL = instanceURL
|
||||
self.accountInfo = nil
|
||||
self.accountInfo = accountInfo
|
||||
self.client = Client(baseURL: instanceURL, session: .appDefault)
|
||||
self.transient = transient
|
||||
self.transient = accountInfo == nil
|
||||
|
||||
self.client.clientID = accountInfo?.clientID
|
||||
self.client.clientSecret = accountInfo?.clientSecret
|
||||
self.client.accessToken = accountInfo?.accessToken
|
||||
|
||||
$instance
|
||||
.combineLatest($nodeInfo)
|
||||
|
@ -103,6 +103,11 @@ class MastodonController: ObservableObject {
|
|||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
convenience init(instanceURL: URL, transient: Bool) {
|
||||
precondition(transient, "account info must be provided if transient is false")
|
||||
self.init(instanceURL: instanceURL, accountInfo: nil)
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
func run<Result>(_ request: Request<Result>, completion: @escaping Client.Callback<Result>) -> URLSessionTask? {
|
||||
return client.run(request, completion: completion)
|
||||
|
|
Loading…
Reference in New Issue