From 6f16a997594bc24b29db703d44995f702b9e238b Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Thu, 15 Feb 2024 16:24:49 +0100 Subject: [PATCH] Update accounts on profile-screen on pull to refresh (IOS-192) --- .../Scene/Profile/ProfileViewController.swift | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Mastodon/Scene/Profile/ProfileViewController.swift b/Mastodon/Scene/Profile/ProfileViewController.swift index ce9e968e8..4383f21ce 100644 --- a/Mastodon/Scene/Profile/ProfileViewController.swift +++ b/Mastodon/Scene/Profile/ProfileViewController.swift @@ -577,11 +577,26 @@ extension ProfileViewController { userTimelineViewController.viewModel.stateMachine.enter(UserTimelineViewModel.State.Reloading.self) } - // trigger authenticated user account update - viewModel.context.authenticationService.updateActiveUserAccountPublisher.send() + Task { + let account = viewModel.account + if let domain = account.domain, + let updatedAccount = try? await context.apiService.fetchUser(username: account.acct, domain: domain, authenticationBox: authContext.mastodonAuthenticationBox), + let updatedRelationship = try? await context.apiService.relationship(forAccounts: [updatedAccount], authenticationBox: authContext.mastodonAuthenticationBox).value.first + { + viewModel.account = updatedAccount + viewModel.relationship = updatedRelationship + } - DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { - sender.endRefreshing() + let me = viewModel.me + + if let domain = me.domain, let updatedMe = try? await context.apiService.authenticatedUserInfo(authenticationBox: authContext.mastodonAuthenticationBox).value { + viewModel.me = updatedMe + FileManager.default.store(account: updatedMe, forUserID: authContext.mastodonAuthenticationBox.authentication.userIdentifier()) + } + + DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { + sender.endRefreshing() + } } }