Fix loading of follower/following count on profile pages (#1053)

This commit is contained in:
Jed Fox 2023-05-30 02:32:10 -04:00 committed by GitHub
parent 823a478e0f
commit 4aff4c65c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 26 deletions

View File

@ -183,32 +183,6 @@ extension ProfileHeaderViewController {
// set display after view appear
profileHeaderView.setupImageOverlayViews()
guard let userID = viewModel.user?.id else { return }
Task {
do {
let response = try await viewModel.context.apiService.followers(
userID: userID,
maxID: nil,
authenticationBox: viewModel.authContext.mastodonAuthenticationBox
)
profileHeaderView.viewModel.followersCount = response.value.count
} catch {
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): fetch follower fail: \(error.localizedDescription)")
}
do {
let response = try await viewModel.context.apiService.following(
userID: userID,
maxID: nil,
authenticationBox: viewModel.authContext.mastodonAuthenticationBox
)
profileHeaderView.viewModel.followingCount = response.value.count
} catch {
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): fetch following fail: \(error.localizedDescription)")
}
} // end Task
}
override func viewDidLayoutSubviews() {

View File

@ -384,6 +384,21 @@ extension ProfileViewController {
self.navigationItem.title = name
}
.store(in: &disposeBag)
Publishers.CombineLatest(
profileHeaderViewController.viewModel.$user,
profileHeaderViewController.profileHeaderView.viewModel.viewDidAppear
)
.sink { [weak self] (user, _) in
guard let self = self, let user = user else { return }
Task {
_ = try await self.context.apiService.accountInfo(
domain: user.domain,
userID: user.id,
authorization: self.authContext.mastodonAuthenticationBox.userAuthorization
)
}
}
.store(in: &disposeBag)
}
private func bindMoreBarButtonItem() {