Fix TabBar avatar loading

This commit is contained in:
Marcus Kida 2023-06-02 10:49:00 +02:00 committed by Nathan Mattes
parent 58ddb2bd06
commit 1bb8e64574
2 changed files with 31 additions and 20 deletions

View File

@ -292,28 +292,34 @@ extension MainTabBarController {
}
.store(in: &disposeBag)
if let user = authContext?.mastodonAuthenticationBox.authentication.user(in: context.managedObjectContext) {
self.avatarURLObserver = user.publisher(for: \.avatar)
.sink { [weak self, weak user] _ in
guard let self = self else { return }
guard let user = user else { return }
guard user.managedObjectContext != nil else { return }
self.avatarURL = user.avatarImageURL()
}
NotificationCenter.default.publisher(for: .userFetched)
.receive(on: DispatchQueue.main)
.sink { [weak self] _ in
guard let self = self else { return }
if let user = self.authContext?.mastodonAuthenticationBox.authentication.user(in: self.context.managedObjectContext) {
self.avatarURLObserver = user.publisher(for: \.avatar)
.sink { [weak self, weak user] _ in
guard let self = self else { return }
guard let user = user else { return }
guard user.managedObjectContext != nil else { return }
self.avatarURL = user.avatarImageURL()
}
// a11y
let _profileTabItem = self.tabBar.items?.first { item in item.tag == Tab.me.tag }
guard let profileTabItem = _profileTabItem else { return }
profileTabItem.accessibilityHint = L10n.Scene.AccountList.tabBarHint(user.displayNameWithFallback)
// a11y
let _profileTabItem = self.tabBar.items?.first { item in item.tag == Tab.me.tag }
guard let profileTabItem = _profileTabItem else { return }
profileTabItem.accessibilityHint = L10n.Scene.AccountList.tabBarHint(user.displayNameWithFallback)
context.authenticationService.updateActiveUserAccountPublisher
.sink { [weak self] in
self?.updateUserAccount()
self.context.authenticationService.updateActiveUserAccountPublisher
.sink { [weak self] in
self?.updateUserAccount()
}
.store(in: &self.disposeBag)
} else {
self.avatarURLObserver = nil
}
.store(in: &disposeBag)
} else {
self.avatarURLObserver = nil
}
}
.store(in: &disposeBag)
let tabBarLongPressGestureRecognizer = UILongPressGestureRecognizer()
tabBarLongPressGestureRecognizer.addTarget(self, action: #selector(MainTabBarController.tabBarLongPressGestureRecognizerHandler(_:)))

View File

@ -12,6 +12,10 @@ import CoreDataStack
import CommonOSLog
import MastodonSDK
public extension Foundation.Notification.Name {
static let userFetched = Notification.Name(rawValue: "org.joinmastodon.app.user-fetched")
}
extension APIService {
public func homeTimeline(
@ -44,6 +48,7 @@ extension APIService {
// Problem is, that we don't persist the user on disk anymore. So we have to fetch
// it when we need it to display on the home timeline.
_ = try await authenticatedUserInfo(authenticationBox: authenticationBox).value
NotificationCenter.default.post(name: .userFetched, object: nil)
try await managedObjectContext.performChanges {
guard let me = authenticationBox.authentication.user(in: managedObjectContext) else {