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,7 +292,11 @@ extension MainTabBarController {
} }
.store(in: &disposeBag) .store(in: &disposeBag)
if let user = authContext?.mastodonAuthenticationBox.authentication.user(in: context.managedObjectContext) { 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) self.avatarURLObserver = user.publisher(for: \.avatar)
.sink { [weak self, weak user] _ in .sink { [weak self, weak user] _ in
guard let self = self else { return } guard let self = self else { return }
@ -306,14 +310,16 @@ extension MainTabBarController {
guard let profileTabItem = _profileTabItem else { return } guard let profileTabItem = _profileTabItem else { return }
profileTabItem.accessibilityHint = L10n.Scene.AccountList.tabBarHint(user.displayNameWithFallback) profileTabItem.accessibilityHint = L10n.Scene.AccountList.tabBarHint(user.displayNameWithFallback)
context.authenticationService.updateActiveUserAccountPublisher self.context.authenticationService.updateActiveUserAccountPublisher
.sink { [weak self] in .sink { [weak self] in
self?.updateUserAccount() self?.updateUserAccount()
} }
.store(in: &disposeBag) .store(in: &self.disposeBag)
} else { } else {
self.avatarURLObserver = nil self.avatarURLObserver = nil
} }
}
.store(in: &disposeBag)
let tabBarLongPressGestureRecognizer = UILongPressGestureRecognizer() let tabBarLongPressGestureRecognizer = UILongPressGestureRecognizer()
tabBarLongPressGestureRecognizer.addTarget(self, action: #selector(MainTabBarController.tabBarLongPressGestureRecognizerHandler(_:))) tabBarLongPressGestureRecognizer.addTarget(self, action: #selector(MainTabBarController.tabBarLongPressGestureRecognizerHandler(_:)))

View File

@ -12,6 +12,10 @@ import CoreDataStack
import CommonOSLog import CommonOSLog
import MastodonSDK import MastodonSDK
public extension Foundation.Notification.Name {
static let userFetched = Notification.Name(rawValue: "org.joinmastodon.app.user-fetched")
}
extension APIService { extension APIService {
public func homeTimeline( 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 // 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. // it when we need it to display on the home timeline.
_ = try await authenticatedUserInfo(authenticationBox: authenticationBox).value _ = try await authenticatedUserInfo(authenticationBox: authenticationBox).value
NotificationCenter.default.post(name: .userFetched, object: nil)
try await managedObjectContext.performChanges { try await managedObjectContext.performChanges {
guard let me = authenticationBox.authentication.user(in: managedObjectContext) else { guard let me = authenticationBox.authentication.user(in: managedObjectContext) else {