diff --git a/Mastodon/Coordinator/SceneCoordinator.swift b/Mastodon/Coordinator/SceneCoordinator.swift index 93393d542..18d76e446 100644 --- a/Mastodon/Coordinator/SceneCoordinator.swift +++ b/Mastodon/Coordinator/SceneCoordinator.swift @@ -65,8 +65,8 @@ extension SceneCoordinator { case safari(url: URL) case alertController(alertController: UIAlertController) case activityViewController(activityViewController: UIActivityViewController, sourceView: UIView?, barButtonItem: UIBarButtonItem?) - case settings - case report(userId: String, statusId: String?) + case settings(viewModel: SettingsViewModel) + case report(viewModel: ReportViewModel) #if DEBUG case publicTimeline #endif @@ -265,22 +265,13 @@ private extension SceneCoordinator { activityViewController.popoverPresentationController?.sourceView = sourceView activityViewController.popoverPresentationController?.barButtonItem = barButtonItem viewController = activityViewController - case .settings: + case .settings(let viewModel): let _viewController = SettingsViewController() - _viewController.viewModel = SettingsViewModel(context: appContext, coordinator: self) + _viewController.viewModel = viewModel viewController = _viewController - case .report(let userId, let statusId): - guard let authenticationBox = appContext.authenticationService.activeMastodonAuthenticationBox.value else { - return nil - } + case .report(let viewModel): let _viewController = ReportViewController() - _viewController.viewModel = ReportViewModel( - context: appContext, - coordinator: self, - domain: authenticationBox.domain, - userId: userId, - statusId: statusId - ) + _viewController.viewModel = viewModel viewController = _viewController #if DEBUG case .publicTimeline: diff --git a/Mastodon/Scene/HomeTimeline/HomeTimelineViewController+DebugAction.swift b/Mastodon/Scene/HomeTimeline/HomeTimelineViewController+DebugAction.swift index 459652008..fca20c92b 100644 --- a/Mastodon/Scene/HomeTimeline/HomeTimelineViewController+DebugAction.swift +++ b/Mastodon/Scene/HomeTimeline/HomeTimelineViewController+DebugAction.swift @@ -332,7 +332,12 @@ extension HomeTimelineViewController { } @objc private func showSettings(_ sender: UIAction) { - coordinator.present(scene: .settings, from: self, transition: .modal(animated: true, completion: nil)) + let viewModel = SettingsViewModel(context: context) + coordinator.present( + scene: .settings(viewModel: viewModel), + from: self, + transition: .modal(animated: true, completion: nil) + ) } @objc private func showReportAction(_ sender: UIAction) { @@ -350,12 +355,20 @@ extension HomeTimelineViewController { guard let userId = accountTextField.text else { return } guard let statusId = statusTextField.text else { return } + guard let authenticationBox = self.context.authenticationService.activeMastodonAuthenticationBox.value else { return } // itodo: delete them // 31803 // 106093402888557459 + let viewModel = ReportViewModel( + context: self.context, + coordinator: self.coordinator, + domain: authenticationBox.domain, + userId: userId, + statusId: statusId + ) self.coordinator.present( - scene: .report(userId: userId, statusId: statusId), + scene: .report(viewModel: viewModel), from: self, transition: .modal(animated: true, completion: nil)) } alertController.addAction(showAction) diff --git a/Mastodon/Scene/Settings/SettingsViewModel.swift b/Mastodon/Scene/Settings/SettingsViewModel.swift index 470617aeb..57371f92b 100644 --- a/Mastodon/Scene/Settings/SettingsViewModel.swift +++ b/Mastodon/Scene/Settings/SettingsViewModel.swift @@ -13,10 +13,9 @@ import MastodonSDK import UIKit import os.log -class SettingsViewModel: NSObject, NeedsDependency { +class SettingsViewModel: NSObject { // confirm set only once weak var context: AppContext! { willSet { precondition(context == nil) } } - weak var coordinator: SceneCoordinator! { willSet { precondition(coordinator == nil) } } var dataSource: UITableViewDiffableDataSource! var disposeBag = Set() @@ -87,9 +86,8 @@ class SettingsViewModel: NSObject, NeedsDependency { struct Output { } - init(context: AppContext, coordinator: SceneCoordinator) { + init(context: AppContext) { self.context = context - self.coordinator = coordinator super.init() }