Merge pull request #585 from mastodon/fix-authenticated-user-profile-reload
Fix authenticated user account not reloaded
This commit is contained in:
commit
51c7034dc4
|
@ -552,6 +552,9 @@ extension ProfileViewController {
|
||||||
userTimelineViewController.viewModel.stateMachine.enter(UserTimelineViewModel.State.Reloading.self)
|
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) {
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
||||||
sender.endRefreshing()
|
sender.endRefreshing()
|
||||||
}
|
}
|
||||||
|
|
|
@ -313,6 +313,11 @@ extension MainTabBarController {
|
||||||
let currentUserDisplayName = user.displayNameWithFallback ?? "no user"
|
let currentUserDisplayName = user.displayNameWithFallback ?? "no user"
|
||||||
profileTabItem.accessibilityHint = L10n.Scene.AccountList.tabBarHint(currentUserDisplayName)
|
profileTabItem.accessibilityHint = L10n.Scene.AccountList.tabBarHint(currentUserDisplayName)
|
||||||
|
|
||||||
|
context.instanceService.updateActiveUserAccountPublisher
|
||||||
|
.sink { [weak self] in
|
||||||
|
self?.updateUserAccount()
|
||||||
|
}
|
||||||
|
.store(in: &disposeBag)
|
||||||
} else {
|
} else {
|
||||||
self.avatarURLObserver = nil
|
self.avatarURLObserver = nil
|
||||||
}
|
}
|
||||||
|
@ -487,6 +492,26 @@ extension MainTabBarController {
|
||||||
avatarButton.setNeedsLayout()
|
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 {
|
extension MainTabBarController {
|
||||||
|
|
|
@ -110,6 +110,9 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||||
// trigger status filter update
|
// trigger status filter update
|
||||||
AppContext.shared.statusFilterService.filterUpdatePublisher.send()
|
AppContext.shared.statusFilterService.filterUpdatePublisher.send()
|
||||||
|
|
||||||
|
// trigger authenticated user account update
|
||||||
|
AppContext.shared.instanceService.updateActiveUserAccountPublisher.send()
|
||||||
|
|
||||||
if let shortcutItem = savedShortCutItem {
|
if let shortcutItem = savedShortCutItem {
|
||||||
Task {
|
Task {
|
||||||
_ = await handler(shortcutItem: shortcutItem)
|
_ = await handler(shortcutItem: shortcutItem)
|
||||||
|
|
|
@ -10,6 +10,10 @@ import CoreDataStack
|
||||||
import MastodonSDK
|
import MastodonSDK
|
||||||
|
|
||||||
extension MastodonUser.Property {
|
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) {
|
init(entity: Mastodon.Entity.Account, domain: String, networkDate: Date) {
|
||||||
self.init(
|
self.init(
|
||||||
identifier: entity.id + "@" + domain,
|
identifier: entity.id + "@" + domain,
|
||||||
|
|
|
@ -13,6 +13,15 @@ import MastodonCommon
|
||||||
import MastodonSDK
|
import MastodonSDK
|
||||||
|
|
||||||
extension APIService {
|
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(
|
public func accountInfo(
|
||||||
domain: String,
|
domain: String,
|
||||||
|
|
|
@ -24,6 +24,7 @@ public final class InstanceService {
|
||||||
weak var authenticationService: AuthenticationService?
|
weak var authenticationService: AuthenticationService?
|
||||||
|
|
||||||
// output
|
// output
|
||||||
|
public let updateActiveUserAccountPublisher = PassthroughSubject<Void, Never>()
|
||||||
|
|
||||||
init(
|
init(
|
||||||
apiService: APIService,
|
apiService: APIService,
|
||||||
|
|
Loading…
Reference in New Issue