From 5473e7f3f94fbe4367537faa78a2cd93cd86fc9d Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Tue, 9 Jul 2024 17:52:27 +0200 Subject: [PATCH] Add viewController for notification-requests (IOS-241) --- Mastodon.xcodeproj/project.pbxproj | 8 ++++++ Mastodon/Coordinator/SceneCoordinator.swift | 7 +++++- .../DataSourceFacade+Notifications.swift | 25 +++++++++++++++++++ ...taSourceProvider+UITableViewDelegate.swift | 3 +-- .../NotificationPolicyViewController.swift | 2 +- ...ificationRequestsTableViewController.swift | 25 +++++++++++++++++++ .../NotificationViewController.swift | 2 +- 7 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 Mastodon/Protocol/Provider/DataSourceFacade+Notifications.swift create mode 100644 Mastodon/Scene/Notification/Notification Filtering/NotificationRequestsTableViewController.swift diff --git a/Mastodon.xcodeproj/project.pbxproj b/Mastodon.xcodeproj/project.pbxproj index 07c93f2d3..59298729c 100644 --- a/Mastodon.xcodeproj/project.pbxproj +++ b/Mastodon.xcodeproj/project.pbxproj @@ -161,6 +161,8 @@ D83B54F82C2AC2FA00D18A7B /* NotificationFilteringBannerTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D83B54F72C2AC2FA00D18A7B /* NotificationFilteringBannerTableViewCell.swift */; }; D84738D42BBD9ABE00ECD52B /* TimelineStatusPill.swift in Sources */ = {isa = PBXBuildFile; fileRef = D84738D32BBD9ABE00ECD52B /* TimelineStatusPill.swift */; }; D84BB76B2C3BE33800493718 /* NotificationPolicyFilterTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D84BB76A2C3BE33800493718 /* NotificationPolicyFilterTableViewCell.swift */; }; + D84BB76D2C3D88B000493718 /* DataSourceFacade+Notifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = D84BB76C2C3D88B000493718 /* DataSourceFacade+Notifications.swift */; }; + D84BB76F2C3D8DBC00493718 /* NotificationRequestsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D84BB76E2C3D8DBC00493718 /* NotificationRequestsTableViewController.swift */; }; D84FA0932AE6915800987F47 /* MBProgressHUD in Frameworks */ = {isa = PBXBuildFile; productRef = D84FA0922AE6915800987F47 /* MBProgressHUD */; }; D852C23C2AC5D02C00309232 /* AboutInstanceViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D852C23B2AC5D02C00309232 /* AboutInstanceViewController.swift */; }; D852C23E2AC5D03300309232 /* InstanceRulesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D852C23D2AC5D03300309232 /* InstanceRulesViewController.swift */; }; @@ -796,6 +798,8 @@ D83B54F72C2AC2FA00D18A7B /* NotificationFilteringBannerTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationFilteringBannerTableViewCell.swift; sourceTree = ""; }; D84738D32BBD9ABE00ECD52B /* TimelineStatusPill.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineStatusPill.swift; sourceTree = ""; }; D84BB76A2C3BE33800493718 /* NotificationPolicyFilterTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationPolicyFilterTableViewCell.swift; sourceTree = ""; }; + D84BB76C2C3D88B000493718 /* DataSourceFacade+Notifications.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DataSourceFacade+Notifications.swift"; sourceTree = ""; }; + D84BB76E2C3D8DBC00493718 /* NotificationRequestsTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationRequestsTableViewController.swift; sourceTree = ""; }; D84C099D2B0F9E33009E685E /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; D84C099F2B0F9E41009E685E /* Setup.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = Setup.md; sourceTree = ""; }; D84C09A02B0F9E41009E685E /* How-it-works.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "How-it-works.md"; sourceTree = ""; }; @@ -1770,6 +1774,7 @@ children = ( D80EC2622C2978EE009724A5 /* NotificationPolicyViewController.swift */, D84BB76A2C3BE33800493718 /* NotificationPolicyFilterTableViewCell.swift */, + D84BB76E2C3D8DBC00493718 /* NotificationRequestsTableViewController.swift */, ); path = "Notification Filtering"; sourceTree = ""; @@ -2424,6 +2429,7 @@ DB0FCB67279507EF006C02E2 /* DataSourceFacade+Meta.swift */, 27D701F4292FC2D60031BCBB /* DataSourceFacade+URL.swift */, DB0FCB79279576A2006C02E2 /* DataSourceFacade+Thread.swift */, + D84BB76C2C3D88B000493718 /* DataSourceFacade+Notifications.swift */, DB63F74627990B0600455B82 /* DataSourceFacade+Hashtag.swift */, DB63F7532799491600455B82 /* DataSourceFacade+SearchHistory.swift */, DB159C2A27A17BAC0068DC77 /* DataSourceFacade+Media.swift */, @@ -3514,6 +3520,7 @@ DBDFF1902805543100557A48 /* DiscoveryPostsViewController.swift in Sources */, DB697DD9278F4CED004EF2F7 /* HomeTimelineViewController+DataSourceProvider.swift in Sources */, DB45FAD725CA6C76005A8AC7 /* UIBarButtonItem.swift in Sources */, + D84BB76F2C3D8DBC00493718 /* NotificationRequestsTableViewController.swift in Sources */, D8FAAE432AD047B200DC1832 /* AboutInstanceTableFooterView.swift in Sources */, D808B94E296EFBBA0031EB1E /* StatusEditHistoryTableViewCell.swift in Sources */, D852C23E2AC5D03300309232 /* InstanceRulesViewController.swift in Sources */, @@ -3868,6 +3875,7 @@ DBD5B1F827BCFD9D00BD6B38 /* DataSourceProvider+TableViewControllerNavigateable.swift in Sources */, 0FB3D31E25E534C700AAD544 /* PickServerCategoryCollectionViewCell.swift in Sources */, DB0FCB882796BDA9006C02E2 /* SearchItem.swift in Sources */, + D84BB76D2C3D88B000493718 /* DataSourceFacade+Notifications.swift in Sources */, DB6180ED26391C6C0018D199 /* TransitioningMath.swift in Sources */, 2A409F832B5955290044E472 /* MastodonStatusThreadViewModel+State.swift in Sources */, 2D6DE40026141DF600A63F6A /* SearchViewModel.swift in Sources */, diff --git a/Mastodon/Coordinator/SceneCoordinator.swift b/Mastodon/Coordinator/SceneCoordinator.swift index acf985fee..0e9ff6f71 100644 --- a/Mastodon/Coordinator/SceneCoordinator.swift +++ b/Mastodon/Coordinator/SceneCoordinator.swift @@ -205,7 +205,10 @@ extension SceneCoordinator { // setting case settings(setting: Setting) - + + // Notifications + case notificationRequests(viewModel: NotificationRequestsViewModel) + // report case report(viewModel: ReportViewModel) case reportServerRules(viewModel: ReportServerRulesViewModel) @@ -558,6 +561,8 @@ private extension SceneCoordinator { case .editStatus(let viewModel): let composeViewController = ComposeViewController(viewModel: viewModel) viewController = composeViewController + case .notificationRequests(let viewModel): + viewController = NotificationRequestsTableViewController(viewModel: viewModel) } setupDependency(for: viewController as? NeedsDependency) diff --git a/Mastodon/Protocol/Provider/DataSourceFacade+Notifications.swift b/Mastodon/Protocol/Provider/DataSourceFacade+Notifications.swift new file mode 100644 index 000000000..937f75eff --- /dev/null +++ b/Mastodon/Protocol/Provider/DataSourceFacade+Notifications.swift @@ -0,0 +1,25 @@ +// Copyright © 2024 Mastodon gGmbH. All rights reserved. + +import Foundation +import MastodonCore + +extension DataSourceFacade { + @MainActor + static func coordinateToNotificationRequests( + provider: DataSourceProvider & AuthContextProvider + ) async { + provider.coordinator.showLoading() + + do { + let notificationRequests = try await provider.context.apiService.notificationRequests(authenticationBox: provider.authContext.mastodonAuthenticationBox) + let viewModel = NotificationRequestsViewModel() + + provider.coordinator.hideLoading() + + provider.coordinator.present(scene: .notificationRequests(viewModel: viewModel), transition: .show) + } catch { + //TODO: Error Handling + provider.coordinator.hideLoading() + } + } +} diff --git a/Mastodon/Protocol/Provider/DataSourceProvider+UITableViewDelegate.swift b/Mastodon/Protocol/Provider/DataSourceProvider+UITableViewDelegate.swift index 712a16970..bea5118e4 100644 --- a/Mastodon/Protocol/Provider/DataSourceProvider+UITableViewDelegate.swift +++ b/Mastodon/Protocol/Provider/DataSourceProvider+UITableViewDelegate.swift @@ -58,8 +58,7 @@ extension UITableViewDelegate where Self: DataSourceProvider & AuthContextProvid ) } case .notificationBanner(let policy): - //TODO: Coordinate to pending notification-screen - break + await DataSourceFacade.coordinateToNotificationRequests(provider: self) } } } diff --git a/Mastodon/Scene/Notification/Notification Filtering/NotificationPolicyViewController.swift b/Mastodon/Scene/Notification/Notification Filtering/NotificationPolicyViewController.swift index 781aba6cd..aa599c1e4 100644 --- a/Mastodon/Scene/Notification/Notification Filtering/NotificationPolicyViewController.swift +++ b/Mastodon/Scene/Notification/Notification Filtering/NotificationPolicyViewController.swift @@ -150,7 +150,7 @@ class NotificationPolicyViewController: UIViewController { guard let self else { return } do { - let result = try await viewModel.appContext.apiService.updateNotificationPolicy( + _ = try await viewModel.appContext.apiService.updateNotificationPolicy( authenticationBox: authenticationBox, filterNotFollowing: viewModel.notFollowing, filterNotFollowers: viewModel.noFollower, diff --git a/Mastodon/Scene/Notification/Notification Filtering/NotificationRequestsTableViewController.swift b/Mastodon/Scene/Notification/Notification Filtering/NotificationRequestsTableViewController.swift new file mode 100644 index 000000000..42f121b9f --- /dev/null +++ b/Mastodon/Scene/Notification/Notification Filtering/NotificationRequestsTableViewController.swift @@ -0,0 +1,25 @@ +// Copyright © 2024 Mastodon gGmbH. All rights reserved. + +import UIKit + +struct NotificationRequestsViewModel { + +} + +class NotificationRequestsTableViewController: UIViewController { + let tableView: UITableView + + init(viewModel: NotificationRequestsViewModel) { + //TODO: Cell, DataSource, Delegate.... + tableView = UITableView(frame: .zero) + tableView.translatesAutoresizingMaskIntoConstraints = false + tableView.backgroundColor = .systemBackground + + super.init(nibName: nil, bundle: nil) + + view.addSubview(tableView) + tableView.pinToParent() + } + + required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } +} diff --git a/Mastodon/Scene/Notification/NotificationViewController.swift b/Mastodon/Scene/Notification/NotificationViewController.swift index e5a6d6cfa..d7d53e2ec 100644 --- a/Mastodon/Scene/Notification/NotificationViewController.swift +++ b/Mastodon/Scene/Notification/NotificationViewController.swift @@ -127,7 +127,7 @@ extension NotificationViewController { newAccount: policy.filterNewAccounts, privateMentions: policy.filterPrivateMentions ) - //TODO: Move to SceneCoordinator + //TODO: Move to SceneCoordinator, we'd need a new case for this let notificationPolicyViewController = NotificationPolicyViewController(viewModel: policyViewModel) notificationPolicyViewController.modalPresentationStyle = .formSheet let navigationController = UINavigationController(rootViewController: notificationPolicyViewController)