Handle pending accounts
This commit is contained in:
parent
a2dc370a22
commit
9df1750abc
|
@ -25,12 +25,6 @@ final class MainNavigationViewController: UITabBarController {
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
setupViewControllers()
|
|
||||||
|
|
||||||
if viewModel.identityContext.identity.authenticated {
|
|
||||||
setupNewStatusButton()
|
|
||||||
}
|
|
||||||
|
|
||||||
viewModel.$presentingSecondaryNavigation.sink { [weak self] in
|
viewModel.$presentingSecondaryNavigation.sink { [weak self] in
|
||||||
if $0 {
|
if $0 {
|
||||||
self?.presentSecondaryNavigation()
|
self?.presentSecondaryNavigation()
|
||||||
|
@ -40,10 +34,20 @@ final class MainNavigationViewController: UITabBarController {
|
||||||
}
|
}
|
||||||
.store(in: &cancellables)
|
.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 }
|
viewModel.timelineNavigations.map { _ in }
|
||||||
.merge(with: viewModel.followRequestNavigations.map { _ in })
|
.merge(with: viewModel.followRequestNavigations.map { _ in })
|
||||||
.sink { [weak self] in self?.selectedIndex = 0 }
|
.sink { [weak self] in self?.selectedIndex = 0 }
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
|
|
||||||
|
NotificationCenter.default.publisher(for: UIScene.willEnterForegroundNotification)
|
||||||
|
.sink { [weak self] _ in self?.viewModel.refreshIdentity() }
|
||||||
|
.store(in: &cancellables)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewWillAppear(_ animated: Bool) {
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
|
@ -54,29 +58,29 @@ final class MainNavigationViewController: UITabBarController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private extension MainNavigationViewController {
|
private extension MainNavigationViewController {
|
||||||
func setupViewControllers() {
|
func setupViewControllers(pending: Bool) {
|
||||||
var controllers: [UIViewController] = [
|
var controllers: [UIViewController] = [
|
||||||
TimelinesViewController(
|
TimelinesViewController(
|
||||||
viewModel: viewModel,
|
viewModel: viewModel,
|
||||||
rootViewModel: rootViewModel),
|
rootViewModel: rootViewModel),
|
||||||
ExploreViewController(
|
ExploreViewController(
|
||||||
viewModel: viewModel.exploreViewModel,
|
viewModel: viewModel.exploreViewModel(),
|
||||||
rootViewModel: rootViewModel)
|
rootViewModel: rootViewModel)
|
||||||
]
|
]
|
||||||
|
|
||||||
if viewModel.identityContext.identity.authenticated {
|
if viewModel.identityContext.identity.authenticated && !pending {
|
||||||
controllers.append(NotificationsViewController(viewModel: viewModel, rootViewModel: rootViewModel))
|
controllers.append(NotificationsViewController(viewModel: viewModel, rootViewModel: rootViewModel))
|
||||||
}
|
|
||||||
|
|
||||||
if let conversationsViewModel = viewModel.conversationsViewModel {
|
|
||||||
let conversationsViewController = TableViewController(
|
let conversationsViewController = TableViewController(
|
||||||
viewModel: conversationsViewModel,
|
viewModel: viewModel.conversationsViewModel(),
|
||||||
rootViewModel: rootViewModel)
|
rootViewModel: rootViewModel)
|
||||||
|
|
||||||
conversationsViewController.tabBarItem = NavigationViewModel.Tab.messages.tabBarItem
|
conversationsViewController.tabBarItem = NavigationViewModel.Tab.messages.tabBarItem
|
||||||
conversationsViewController.navigationItem.title = NavigationViewModel.Tab.messages.title
|
conversationsViewController.navigationItem.title = NavigationViewModel.Tab.messages.title
|
||||||
|
|
||||||
controllers.append(conversationsViewController)
|
controllers.append(conversationsViewController)
|
||||||
|
|
||||||
|
setupNewStatusButton()
|
||||||
}
|
}
|
||||||
|
|
||||||
let secondaryNavigationButton = SecondaryNavigationButton(viewModel: viewModel, rootViewModel: rootViewModel)
|
let secondaryNavigationButton = SecondaryNavigationButton(viewModel: viewModel, rootViewModel: rootViewModel)
|
||||||
|
|
|
@ -14,30 +14,6 @@ public final class NavigationViewModel: ObservableObject {
|
||||||
@Published public var presentingSecondaryNavigation = false
|
@Published public var presentingSecondaryNavigation = false
|
||||||
@Published public var alertItem: AlertItem?
|
@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 timelineNavigationsSubject = PassthroughSubject<Timeline, Never>()
|
||||||
private let followRequestNavigationsSubject = PassthroughSubject<CollectionViewModel, Never>()
|
private let followRequestNavigationsSubject = PassthroughSubject<CollectionViewModel, Never>()
|
||||||
private var cancellables = Set<AnyCancellable>()
|
private var cancellables = Set<AnyCancellable>()
|
||||||
|
@ -141,6 +117,16 @@ public extension NavigationViewModel {
|
||||||
identityContext: identityContext)
|
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 {
|
func notificationsViewModel(excludeTypes: Set<MastodonNotification.NotificationType>) -> CollectionItemsViewModel {
|
||||||
let viewModel = CollectionItemsViewModel(
|
let viewModel = CollectionItemsViewModel(
|
||||||
collectionService: identityContext.service.notificationsService(excludeTypes: excludeTypes),
|
collectionService: identityContext.service.notificationsService(excludeTypes: excludeTypes),
|
||||||
|
@ -150,4 +136,14 @@ public extension NavigationViewModel {
|
||||||
|
|
||||||
return viewModel
|
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 New Issue