mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-29 03:21:02 +00:00
Handle pending accounts
This commit is contained in:
parent
a2dc370a22
commit
9df1750abc
2 changed files with 36 additions and 36 deletions
|
@ -25,12 +25,6 @@ final class MainNavigationViewController: UITabBarController {
|
|||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
setupViewControllers()
|
||||
|
||||
if viewModel.identityContext.identity.authenticated {
|
||||
setupNewStatusButton()
|
||||
}
|
||||
|
||||
viewModel.$presentingSecondaryNavigation.sink { [weak self] in
|
||||
if $0 {
|
||||
self?.presentSecondaryNavigation()
|
||||
|
@ -40,10 +34,20 @@ final class MainNavigationViewController: UITabBarController {
|
|||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
viewModel.identityContext.$identity.map(\.pending)
|
||||
.removeDuplicates()
|
||||
.print()
|
||||
.sink { [weak self] in self?.setupViewControllers(pending: $0) }
|
||||
.store(in: &cancellables)
|
||||
|
||||
viewModel.timelineNavigations.map { _ in }
|
||||
.merge(with: viewModel.followRequestNavigations.map { _ in })
|
||||
.sink { [weak self] in self?.selectedIndex = 0 }
|
||||
.store(in: &cancellables)
|
||||
|
||||
NotificationCenter.default.publisher(for: UIScene.willEnterForegroundNotification)
|
||||
.sink { [weak self] _ in self?.viewModel.refreshIdentity() }
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
|
@ -54,29 +58,29 @@ final class MainNavigationViewController: UITabBarController {
|
|||
}
|
||||
|
||||
private extension MainNavigationViewController {
|
||||
func setupViewControllers() {
|
||||
func setupViewControllers(pending: Bool) {
|
||||
var controllers: [UIViewController] = [
|
||||
TimelinesViewController(
|
||||
viewModel: viewModel,
|
||||
rootViewModel: rootViewModel),
|
||||
ExploreViewController(
|
||||
viewModel: viewModel.exploreViewModel,
|
||||
viewModel: viewModel.exploreViewModel(),
|
||||
rootViewModel: rootViewModel)
|
||||
]
|
||||
|
||||
if viewModel.identityContext.identity.authenticated {
|
||||
if viewModel.identityContext.identity.authenticated && !pending {
|
||||
controllers.append(NotificationsViewController(viewModel: viewModel, rootViewModel: rootViewModel))
|
||||
}
|
||||
|
||||
if let conversationsViewModel = viewModel.conversationsViewModel {
|
||||
let conversationsViewController = TableViewController(
|
||||
viewModel: conversationsViewModel,
|
||||
viewModel: viewModel.conversationsViewModel(),
|
||||
rootViewModel: rootViewModel)
|
||||
|
||||
conversationsViewController.tabBarItem = NavigationViewModel.Tab.messages.tabBarItem
|
||||
conversationsViewController.navigationItem.title = NavigationViewModel.Tab.messages.title
|
||||
|
||||
controllers.append(conversationsViewController)
|
||||
|
||||
setupNewStatusButton()
|
||||
}
|
||||
|
||||
let secondaryNavigationButton = SecondaryNavigationButton(viewModel: viewModel, rootViewModel: rootViewModel)
|
||||
|
|
|
@ -14,30 +14,6 @@ public final class NavigationViewModel: ObservableObject {
|
|||
@Published public var presentingSecondaryNavigation = false
|
||||
@Published public var alertItem: AlertItem?
|
||||
|
||||
public lazy var exploreViewModel: ExploreViewModel = {
|
||||
let exploreViewModel = ExploreViewModel(
|
||||
service: identityContext.service.exploreService(),
|
||||
identityContext: identityContext)
|
||||
|
||||
// TODO: initial request
|
||||
|
||||
return exploreViewModel
|
||||
}()
|
||||
|
||||
public lazy var conversationsViewModel: CollectionViewModel? = {
|
||||
if identityContext.identity.authenticated {
|
||||
let conversationsViewModel = CollectionItemsViewModel(
|
||||
collectionService: identityContext.service.conversationsService(),
|
||||
identityContext: identityContext)
|
||||
|
||||
conversationsViewModel.request(maxId: nil, minId: nil, search: nil)
|
||||
|
||||
return conversationsViewModel
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}()
|
||||
|
||||
private let timelineNavigationsSubject = PassthroughSubject<Timeline, Never>()
|
||||
private let followRequestNavigationsSubject = PassthroughSubject<CollectionViewModel, Never>()
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
@ -141,6 +117,16 @@ public extension NavigationViewModel {
|
|||
identityContext: identityContext)
|
||||
}
|
||||
|
||||
func exploreViewModel() -> ExploreViewModel {
|
||||
let exploreViewModel = ExploreViewModel(
|
||||
service: identityContext.service.exploreService(),
|
||||
identityContext: identityContext)
|
||||
|
||||
// TODO: initial request
|
||||
|
||||
return exploreViewModel
|
||||
}
|
||||
|
||||
func notificationsViewModel(excludeTypes: Set<MastodonNotification.NotificationType>) -> CollectionItemsViewModel {
|
||||
let viewModel = CollectionItemsViewModel(
|
||||
collectionService: identityContext.service.notificationsService(excludeTypes: excludeTypes),
|
||||
|
@ -150,4 +136,14 @@ public extension NavigationViewModel {
|
|||
|
||||
return viewModel
|
||||
}
|
||||
|
||||
func conversationsViewModel() -> CollectionViewModel {
|
||||
let conversationsViewModel = CollectionItemsViewModel(
|
||||
collectionService: identityContext.service.conversationsService(),
|
||||
identityContext: identityContext)
|
||||
|
||||
conversationsViewModel.request(maxId: nil, minId: nil, search: nil)
|
||||
|
||||
return conversationsViewModel
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue