Call apiService in viewDidAppear (#825)

This commit is contained in:
J 2023-05-25 05:18:51 -07:00 committed by GitHub
parent b3ff75b7f9
commit c3c94f15a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 0 deletions

View File

@ -183,6 +183,32 @@ extension ProfileHeaderViewController {
// set display after view appear // set display after view appear
profileHeaderView.setupImageOverlayViews() 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() { override func viewDidLayoutSubviews() {