Merge pull request #585 from mastodon/fix-authenticated-user-profile-reload

Fix authenticated user account not reloaded
This commit is contained in:
Marcus Kida 2022-11-14 14:08:31 +01:00 committed by GitHub
commit 51c7034dc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 47 additions and 2 deletions

View File

@ -552,6 +552,9 @@ extension ProfileViewController {
userTimelineViewController.viewModel.stateMachine.enter(UserTimelineViewModel.State.Reloading.self)
}
// trigger authenticated user account update
viewModel.context.instanceService.updateActiveUserAccountPublisher.send()
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
sender.endRefreshing()
}

View File

@ -312,7 +312,12 @@ extension MainTabBarController {
guard let profileTabItem = _profileTabItem else { return }
let currentUserDisplayName = user.displayNameWithFallback ?? "no user"
profileTabItem.accessibilityHint = L10n.Scene.AccountList.tabBarHint(currentUserDisplayName)
context.instanceService.updateActiveUserAccountPublisher
.sink { [weak self] in
self?.updateUserAccount()
}
.store(in: &disposeBag)
} else {
self.avatarURLObserver = nil
}
@ -487,6 +492,26 @@ extension MainTabBarController {
avatarButton.setNeedsLayout()
}
private func updateUserAccount() {
guard let authContext = authContext else { return }
Task { @MainActor in
let profileResponse = try await context.apiService.authenticatedUserInfo(
authenticationBox: authContext.mastodonAuthenticationBox
)
if let user = authContext.mastodonAuthenticationBox.authenticationRecord.object(
in: context.managedObjectContext
)?.user {
user.update(
property: .init(
entity: profileResponse.value,
domain: authContext.mastodonAuthenticationBox.domain
)
)
}
}
}
}
extension MainTabBarController {

View File

@ -109,6 +109,9 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
// trigger status filter update
AppContext.shared.statusFilterService.filterUpdatePublisher.send()
// trigger authenticated user account update
AppContext.shared.instanceService.updateActiveUserAccountPublisher.send()
if let shortcutItem = savedShortCutItem {
Task {

View File

@ -10,6 +10,10 @@ import CoreDataStack
import MastodonSDK
extension MastodonUser.Property {
public init(entity: Mastodon.Entity.Account, domain: String) {
self.init(entity: entity, domain: domain, networkDate: Date())
}
init(entity: Mastodon.Entity.Account, domain: String, networkDate: Date) {
self.init(
identifier: entity.id + "@" + domain,

View File

@ -13,6 +13,15 @@ import MastodonCommon
import MastodonSDK
extension APIService {
public func authenticatedUserInfo(
authenticationBox: MastodonAuthenticationBox
) async throws -> Mastodon.Response.Content<Mastodon.Entity.Account> {
try await accountInfo(
domain: authenticationBox.domain,
userID: authenticationBox.userID,
authorization: authenticationBox.userAuthorization
)
}
public func accountInfo(
domain: String,

View File

@ -24,7 +24,8 @@ public final class InstanceService {
weak var authenticationService: AuthenticationService?
// output
public let updateActiveUserAccountPublisher = PassthroughSubject<Void, Never>()
init(
apiService: APIService,
authenticationService: AuthenticationService