2
2
mirror of https://github.com/mastodon/mastodon-ios synced 2025-04-11 22:58:02 +02:00

Update policies (IOS-241)

This commit is contained in:
Nathan Mattes 2024-07-23 11:38:20 +02:00
parent d87deffa6d
commit 25f15d256e
2 changed files with 24 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import UIKit
import MastodonLocalization import MastodonLocalization
import MastodonAsset import MastodonAsset
import MastodonCore import MastodonCore
import MastodonSDK
enum NotificationFilterSection: Hashable { enum NotificationFilterSection: Hashable {
case main case main
@ -61,6 +62,10 @@ struct NotificationFilterViewModel {
} }
} }
protocol NotificationPolicyViewControllerDelegate: AnyObject {
func policyUpdated(_ viewController: NotificationPolicyViewController, newPolicy: Mastodon.Entity.NotificationPolicy)
}
class NotificationPolicyViewController: UIViewController { class NotificationPolicyViewController: UIViewController {
let tableView: UITableView let tableView: UITableView
@ -69,6 +74,7 @@ class NotificationPolicyViewController: UIViewController {
var dataSource: UITableViewDiffableDataSource<NotificationFilterSection, NotificationFilterItem>? var dataSource: UITableViewDiffableDataSource<NotificationFilterSection, NotificationFilterItem>?
let items: [NotificationFilterItem] let items: [NotificationFilterItem]
var viewModel: NotificationFilterViewModel var viewModel: NotificationFilterViewModel
weak var delegate: NotificationPolicyViewControllerDelegate?
init(viewModel: NotificationFilterViewModel) { init(viewModel: NotificationFilterViewModel) {
self.viewModel = viewModel self.viewModel = viewModel
@ -148,15 +154,18 @@ class NotificationPolicyViewController: UIViewController {
guard let self else { return } guard let self else { return }
do { do {
_ = try await viewModel.appContext.apiService.updateNotificationPolicy( let updatedPolicy = try await viewModel.appContext.apiService.updateNotificationPolicy(
authenticationBox: authenticationBox, authenticationBox: authenticationBox,
filterNotFollowing: viewModel.notFollowing, filterNotFollowing: viewModel.notFollowing,
filterNotFollowers: viewModel.noFollower, filterNotFollowers: viewModel.noFollower,
filterNewAccounts: viewModel.newAccount, filterNewAccounts: viewModel.newAccount,
filterPrivateMentions: viewModel.privateMentions filterPrivateMentions: viewModel.privateMentions
) ).value
delegate?.policyUpdated(self, newPolicy: updatedPolicy)
NotificationCenter.default.post(name: .notificationFilteringChanged, object: nil) NotificationCenter.default.post(name: .notificationFilteringChanged, object: nil)
} catch { } catch {
//TODO: Error Handling //TODO: Error Handling
} }

View File

@ -12,6 +12,7 @@ import MastodonLocalization
import Tabman import Tabman
import Pageboy import Pageboy
import MastodonCore import MastodonCore
import MastodonSDK
final class NotificationViewController: TabmanViewController, NeedsDependency { final class NotificationViewController: TabmanViewController, NeedsDependency {
@ -128,7 +129,9 @@ extension NotificationViewController {
privateMentions: policy.filterPrivateMentions privateMentions: policy.filterPrivateMentions
) )
_ = coordinator.present(scene: .notificationPolicy(viewModel: policyViewModel), transition: .formSheet) guard let policyViewController = coordinator.present(scene: .notificationPolicy(viewModel: policyViewModel), transition: .formSheet) as? NotificationPolicyViewController else { return }
policyViewController.delegate = self
} }
} }
@ -250,3 +253,12 @@ extension NotificationViewController {
return categorySwitchKeyCommands return categorySwitchKeyCommands
} }
} }
//MARK: - NotificationPolicyViewControllerDelegate
extension NotificationViewController: NotificationPolicyViewControllerDelegate {
func policyUpdated(_ viewController: NotificationPolicyViewController, newPolicy: Mastodon.Entity.NotificationPolicy) {
viewModel?.notificationPolicy = newPolicy
}
}