diff --git a/Mastodon.xcodeproj/project.pbxproj b/Mastodon.xcodeproj/project.pbxproj index cf8c26b63..73c748682 100644 --- a/Mastodon.xcodeproj/project.pbxproj +++ b/Mastodon.xcodeproj/project.pbxproj @@ -168,6 +168,7 @@ D85DF9712C481B1100A01408 /* NotificationRequestsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D85DF96E2C481B1100A01408 /* NotificationRequestsTableViewController.swift */; }; D85DF9722C481B1100A01408 /* NotificationRequestTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D85DF96F2C481B1100A01408 /* NotificationRequestTableViewCell.swift */; }; D85DF9742C481B3500A01408 /* DataSourceFacade+Notifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = D85DF9732C481B3500A01408 /* DataSourceFacade+Notifications.swift */; }; + D85DF9762C4965A900A01408 /* NotificationRequestsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D85DF9752C4965A900A01408 /* NotificationRequestsViewModel.swift */; }; D87364F92AE28DB500C8F919 /* Kanna in Frameworks */ = {isa = PBXBuildFile; productRef = D87364F82AE28DB500C8F919 /* Kanna */; }; D87BFC8B291D5C6B00FEE264 /* MastodonLoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D87BFC8A291D5C6B00FEE264 /* MastodonLoginView.swift */; }; D87BFC8D291EB81200FEE264 /* MastodonLoginViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D87BFC8C291EB81200FEE264 /* MastodonLoginViewModel.swift */; }; @@ -813,6 +814,7 @@ D85DF96E2C481B1100A01408 /* NotificationRequestsTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NotificationRequestsTableViewController.swift; sourceTree = ""; }; D85DF96F2C481B1100A01408 /* NotificationRequestTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NotificationRequestTableViewCell.swift; sourceTree = ""; }; D85DF9732C481B3500A01408 /* DataSourceFacade+Notifications.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DataSourceFacade+Notifications.swift"; sourceTree = ""; }; + D85DF9752C4965A900A01408 /* NotificationRequestsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationRequestsViewModel.swift; sourceTree = ""; }; D87BFC8A291D5C6B00FEE264 /* MastodonLoginView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MastodonLoginView.swift; sourceTree = ""; }; D87BFC8C291EB81200FEE264 /* MastodonLoginViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MastodonLoginViewModel.swift; sourceTree = ""; }; D87BFC8E291EC26A00FEE264 /* MastodonLoginServerTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MastodonLoginServerTableViewCell.swift; sourceTree = ""; }; @@ -1850,6 +1852,7 @@ children = ( D85DF96E2C481B1100A01408 /* NotificationRequestsTableViewController.swift */, D85DF96F2C481B1100A01408 /* NotificationRequestTableViewCell.swift */, + D85DF9752C4965A900A01408 /* NotificationRequestsViewModel.swift */, ); name = Requests; path = "Notification Filtering/Requests"; @@ -3597,6 +3600,7 @@ DB6180DD263918E30018D199 /* MediaPreviewViewController.swift in Sources */, DBE3CDEC261C6B2900430CC6 /* FavoriteViewController.swift in Sources */, DB938EE62623F50700E5B6C1 /* ThreadViewController.swift in Sources */, + D85DF9762C4965A900A01408 /* NotificationRequestsViewModel.swift in Sources */, DB6180F426391D110018D199 /* MediaPreviewImageView.swift in Sources */, DBF9814A265E24F500E4BA07 /* ProfileFieldCollectionViewHeaderFooterView.swift in Sources */, 2D939AB525EDD8A90076FA61 /* String.swift in Sources */, diff --git a/Mastodon/Coordinator/SceneCoordinator.swift b/Mastodon/Coordinator/SceneCoordinator.swift index 54b63c4df..3f4f8626f 100644 --- a/Mastodon/Coordinator/SceneCoordinator.swift +++ b/Mastodon/Coordinator/SceneCoordinator.swift @@ -564,8 +564,7 @@ private extension SceneCoordinator { let composeViewController = ComposeViewController(viewModel: viewModel) viewController = composeViewController case .notificationRequests(let viewModel): - //FIXME: Put either AuthContext or Everything in ViewModel - viewController = NotificationRequestsTableViewController(viewModel: viewModel, appContext: appContext, coordinator: self) + viewController = NotificationRequestsTableViewController(viewModel: viewModel) case .notificationPolicy(let viewModel): viewController = NotificationPolicyViewController(viewModel: viewModel) case .notificationTimeline(let viewModel): diff --git a/Mastodon/Protocol/Provider/DataSourceFacade+Notifications.swift b/Mastodon/Protocol/Provider/DataSourceFacade+Notifications.swift index 4718fc946..15ef9f1e5 100644 --- a/Mastodon/Protocol/Provider/DataSourceFacade+Notifications.swift +++ b/Mastodon/Protocol/Provider/DataSourceFacade+Notifications.swift @@ -13,7 +13,7 @@ extension DataSourceFacade { do { let notificationRequests = try await provider.context.apiService.notificationRequests(authenticationBox: provider.authContext.mastodonAuthenticationBox).value - let viewModel = NotificationRequestsViewModel(requests: notificationRequests, authContext: provider.authContext) + let viewModel = NotificationRequestsViewModel(appContext: provider.context, authContext: provider.authContext, coordinator: provider.coordinator, requests: notificationRequests) provider.coordinator.hideLoading() @@ -31,17 +31,10 @@ extension DataSourceFacade { ) async { provider.coordinator.showLoading() - do { - // load notifications for request.account - // show NotificationTimelineViewController with NotificationTimelineViewModel - let notificationTimelineViewModel = NotificationTimelineViewModel(context: provider.context, authContext: provider.authContext, scope: .fromAccount(request.account)) + let notificationTimelineViewModel = NotificationTimelineViewModel(context: provider.context, authContext: provider.authContext, scope: .fromAccount(request.account)) - provider.coordinator.hideLoading() - provider.coordinator.present(scene: .notificationTimeline(viewModel: notificationTimelineViewModel), transition: .show) - } catch { - //TODO: Error Handling - provider.coordinator.hideLoading() - } + provider.coordinator.hideLoading() + provider.coordinator.present(scene: .notificationTimeline(viewModel: notificationTimelineViewModel), transition: .show) } } diff --git a/Mastodon/Scene/Notification/Notification Filtering/Requests/NotificationRequestsTableViewController.swift b/Mastodon/Scene/Notification/Notification Filtering/Requests/NotificationRequestsTableViewController.swift index 41f821301..275f5830d 100644 --- a/Mastodon/Scene/Notification/Notification Filtering/Requests/NotificationRequestsTableViewController.swift +++ b/Mastodon/Scene/Notification/Notification Filtering/Requests/NotificationRequestsTableViewController.swift @@ -4,11 +4,6 @@ import UIKit import MastodonSDK import MastodonCore -struct NotificationRequestsViewModel { - var requests: [Mastodon.Entity.NotificationRequest] - let authContext: AuthContext -} - enum NotificationRequestsSection: Hashable { case main } @@ -30,11 +25,11 @@ class NotificationRequestsTableViewController: UIViewController, NeedsDependency var viewModel: NotificationRequestsViewModel var dataSource: UITableViewDiffableDataSource? - init(viewModel: NotificationRequestsViewModel, appContext: AppContext, coordinator: SceneCoordinator) { + init(viewModel: NotificationRequestsViewModel) { self.viewModel = viewModel - self.context = appContext - self.coordinator = coordinator + self.context = viewModel.appContext + self.coordinator = viewModel.coordinator tableView = UITableView(frame: .zero) tableView.translatesAutoresizingMaskIntoConstraints = false diff --git a/Mastodon/Scene/Notification/Notification Filtering/Requests/NotificationRequestsViewModel.swift b/Mastodon/Scene/Notification/Notification Filtering/Requests/NotificationRequestsViewModel.swift new file mode 100644 index 000000000..4ffe3be11 --- /dev/null +++ b/Mastodon/Scene/Notification/Notification Filtering/Requests/NotificationRequestsViewModel.swift @@ -0,0 +1,20 @@ +// Copyright © 2024 Mastodon gGmbH. All rights reserved. + +import Foundation +import MastodonSDK +import MastodonCore + +struct NotificationRequestsViewModel { + let appContext: AppContext + let authContext: AuthContext + let coordinator: SceneCoordinator + + var requests: [Mastodon.Entity.NotificationRequest] + + init(appContext: AppContext, authContext: AuthContext, coordinator: SceneCoordinator, requests: [Mastodon.Entity.NotificationRequest]) { + self.appContext = appContext + self.authContext = authContext + self.coordinator = coordinator + self.requests = requests + } +}