Update policies (IOS-241)
This commit is contained in:
parent
d87deffa6d
commit
25f15d256e
|
@ -4,6 +4,7 @@ import UIKit
|
|||
import MastodonLocalization
|
||||
import MastodonAsset
|
||||
import MastodonCore
|
||||
import MastodonSDK
|
||||
|
||||
enum NotificationFilterSection: Hashable {
|
||||
case main
|
||||
|
@ -61,6 +62,10 @@ struct NotificationFilterViewModel {
|
|||
}
|
||||
}
|
||||
|
||||
protocol NotificationPolicyViewControllerDelegate: AnyObject {
|
||||
func policyUpdated(_ viewController: NotificationPolicyViewController, newPolicy: Mastodon.Entity.NotificationPolicy)
|
||||
}
|
||||
|
||||
class NotificationPolicyViewController: UIViewController {
|
||||
|
||||
let tableView: UITableView
|
||||
|
@ -69,6 +74,7 @@ class NotificationPolicyViewController: UIViewController {
|
|||
var dataSource: UITableViewDiffableDataSource<NotificationFilterSection, NotificationFilterItem>?
|
||||
let items: [NotificationFilterItem]
|
||||
var viewModel: NotificationFilterViewModel
|
||||
weak var delegate: NotificationPolicyViewControllerDelegate?
|
||||
|
||||
init(viewModel: NotificationFilterViewModel) {
|
||||
self.viewModel = viewModel
|
||||
|
@ -148,15 +154,18 @@ class NotificationPolicyViewController: UIViewController {
|
|||
guard let self else { return }
|
||||
|
||||
do {
|
||||
_ = try await viewModel.appContext.apiService.updateNotificationPolicy(
|
||||
let updatedPolicy = try await viewModel.appContext.apiService.updateNotificationPolicy(
|
||||
authenticationBox: authenticationBox,
|
||||
filterNotFollowing: viewModel.notFollowing,
|
||||
filterNotFollowers: viewModel.noFollower,
|
||||
filterNewAccounts: viewModel.newAccount,
|
||||
filterPrivateMentions: viewModel.privateMentions
|
||||
)
|
||||
).value
|
||||
|
||||
delegate?.policyUpdated(self, newPolicy: updatedPolicy)
|
||||
|
||||
NotificationCenter.default.post(name: .notificationFilteringChanged, object: nil)
|
||||
|
||||
} catch {
|
||||
//TODO: Error Handling
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import MastodonLocalization
|
|||
import Tabman
|
||||
import Pageboy
|
||||
import MastodonCore
|
||||
import MastodonSDK
|
||||
|
||||
final class NotificationViewController: TabmanViewController, NeedsDependency {
|
||||
|
||||
|
@ -128,7 +129,9 @@ extension NotificationViewController {
|
|||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//MARK: - NotificationPolicyViewControllerDelegate
|
||||
|
||||
extension NotificationViewController: NotificationPolicyViewControllerDelegate {
|
||||
func policyUpdated(_ viewController: NotificationPolicyViewController, newPolicy: Mastodon.Entity.NotificationPolicy) {
|
||||
viewModel?.notificationPolicy = newPolicy
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue