Only refetch information about the active user’s instance, not all of them.
contributes to iOS-319
This commit is contained in:
parent
54d04aed4e
commit
ae7aaf091d
@ -28,11 +28,13 @@ public final class InstanceService {
|
|||||||
self.backgroundManagedObjectContext = apiService.backgroundManagedObjectContext
|
self.backgroundManagedObjectContext = apiService.backgroundManagedObjectContext
|
||||||
self.apiService = apiService
|
self.apiService = apiService
|
||||||
|
|
||||||
AuthenticationServiceProvider.shared.$mastodonAuthenticationBoxes
|
AuthenticationServiceProvider.shared.currentActiveUser
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
.compactMap { $0.first?.domain }
|
.asyncMap { [weak self] in
|
||||||
.removeDuplicates() // prevent infinity loop
|
if let domain = $0?.domain {
|
||||||
.asyncMap { [weak self] in await self?.updateInstance(domain: $0) }
|
await self?.updateInstance(domain: domain)
|
||||||
|
}
|
||||||
|
}
|
||||||
.sink {}
|
.sink {}
|
||||||
.store(in: &disposeBag)
|
.store(in: &disposeBag)
|
||||||
}
|
}
|
||||||
@ -44,17 +46,18 @@ extension InstanceService {
|
|||||||
@MainActor
|
@MainActor
|
||||||
func updateInstance(domain: String) async {
|
func updateInstance(domain: String) async {
|
||||||
guard let apiService else { return }
|
guard let apiService else { return }
|
||||||
|
guard let authBox = AuthenticationServiceProvider.shared.currentActiveUser.value, authBox.domain == domain else { return }
|
||||||
|
|
||||||
let response = try? await apiService.instance(domain: domain, authenticationBox: AuthenticationServiceProvider.shared.currentActiveUser.value)
|
let response = try? await apiService.instance(domain: domain, authenticationBox: authBox)
|
||||||
.singleOutput()
|
.singleOutput()
|
||||||
|
|
||||||
if response?.value.version?.majorServerVersion(greaterThanOrEquals: 4) == true {
|
if response?.value.version?.majorServerVersion(greaterThanOrEquals: 4) == true {
|
||||||
guard let instanceV2 = try? await apiService.instanceV2(domain: domain, authenticationBox: AuthenticationServiceProvider.shared.currentActiveUser.value).singleOutput() else {
|
guard let instanceV2 = try? await apiService.instanceV2(domain: domain, authenticationBox: authBox).singleOutput() else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
self.updateInstanceV2(domain: domain, response: instanceV2)
|
self.updateInstanceV2(domain: domain, response: instanceV2)
|
||||||
if let translationResponse = try? await apiService.translationLanguages(domain: domain, authenticationBox: AuthenticationServiceProvider.shared.currentActiveUser.value).singleOutput() {
|
if let translationResponse = try? await apiService.translationLanguages(domain: domain, authenticationBox: authBox).singleOutput() {
|
||||||
updateTranslationLanguages(domain: domain, response: translationResponse)
|
updateTranslationLanguages(domain: domain, response: translationResponse)
|
||||||
}
|
}
|
||||||
} else if let response {
|
} else if let response {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user