forked from shadowfacts/Tusker
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] {
|
if let controller = all[account] {
|
||||||
return controller
|
return controller
|
||||||
} else {
|
} else {
|
||||||
let controller = MastodonController(instanceURL: account.instanceURL)
|
let controller = MastodonController(instanceURL: account.instanceURL, accountInfo: account)
|
||||||
controller.accountInfo = account
|
|
||||||
controller.client.clientID = account.clientID
|
|
||||||
controller.client.clientSecret = account.clientSecret
|
|
||||||
controller.client.accessToken = account.accessToken
|
|
||||||
all[account] = controller
|
all[account] = controller
|
||||||
return controller
|
return controller
|
||||||
}
|
}
|
||||||
|
@ -72,11 +68,15 @@ class MastodonController: ObservableObject {
|
||||||
accountInfo != nil
|
accountInfo != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
init(instanceURL: URL, transient: Bool = false) {
|
init(instanceURL: URL, accountInfo: UserAccountInfo?) {
|
||||||
self.instanceURL = instanceURL
|
self.instanceURL = instanceURL
|
||||||
self.accountInfo = nil
|
self.accountInfo = accountInfo
|
||||||
self.client = Client(baseURL: instanceURL, session: .appDefault)
|
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
|
$instance
|
||||||
.combineLatest($nodeInfo)
|
.combineLatest($nodeInfo)
|
||||||
|
@ -103,6 +103,11 @@ class MastodonController: ObservableObject {
|
||||||
.store(in: &cancellables)
|
.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
|
@discardableResult
|
||||||
func run<Result>(_ request: Request<Result>, completion: @escaping Client.Callback<Result>) -> URLSessionTask? {
|
func run<Result>(_ request: Request<Result>, completion: @escaping Client.Callback<Result>) -> URLSessionTask? {
|
||||||
return client.run(request, completion: completion)
|
return client.run(request, completion: completion)
|
||||||
|
|
Loading…
Reference in New Issue