From d87deffa6d68863e2ee98e1d5b089cbbdac1acc7 Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Tue, 23 Jul 2024 10:28:51 +0200 Subject: [PATCH] Update notifications after policy/request-change (IOS-241) --- .../Policy/NotificationPolicyViewController.swift | 2 +- .../NotificationRequestsTableViewController.swift | 5 ++++- .../NotificationTimelineViewModel.swift | 11 +++++++++++ .../Service/API/APIService+Notification.swift | 4 ++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Mastodon/Scene/Notification/Notification Filtering/Policy/NotificationPolicyViewController.swift b/Mastodon/Scene/Notification/Notification Filtering/Policy/NotificationPolicyViewController.swift index b64fdb9d8..3cfde4b6c 100644 --- a/Mastodon/Scene/Notification/Notification Filtering/Policy/NotificationPolicyViewController.swift +++ b/Mastodon/Scene/Notification/Notification Filtering/Policy/NotificationPolicyViewController.swift @@ -156,7 +156,7 @@ class NotificationPolicyViewController: UIViewController { filterPrivateMentions: viewModel.privateMentions ) - + NotificationCenter.default.post(name: .notificationFilteringChanged, object: nil) } catch { //TODO: Error Handling } diff --git a/Mastodon/Scene/Notification/Notification Filtering/Requests/NotificationRequestsTableViewController.swift b/Mastodon/Scene/Notification/Notification Filtering/Requests/NotificationRequestsTableViewController.swift index 275f5830d..c19c0a8a6 100644 --- a/Mastodon/Scene/Notification/Notification Filtering/Requests/NotificationRequestsTableViewController.swift +++ b/Mastodon/Scene/Notification/Notification Filtering/Requests/NotificationRequestsTableViewController.swift @@ -101,7 +101,6 @@ extension NotificationRequestsTableViewController: NotificationRequestTableViewC cell.rejectNotificationRequestButton.isUserInteractionEnabled = false cell.acceptNotificationRequestButton.isUserInteractionEnabled = false - //TODO: Send request, update cell, reload notification requests AND general notifications Task { [weak self] in guard let self else { return } do { @@ -110,6 +109,8 @@ extension NotificationRequestsTableViewController: NotificationRequestTableViewC let requests = try await context.apiService.notificationRequests(authenticationBox: authContext.mastodonAuthenticationBox).value + NotificationCenter.default.post(name: .notificationFilteringChanged, object: nil) + if requests.count > 0 { await MainActor.run { [weak self] in @@ -154,6 +155,8 @@ extension NotificationRequestsTableViewController: NotificationRequestTableViewC let requests = try await context.apiService.notificationRequests(authenticationBox: authContext.mastodonAuthenticationBox).value + NotificationCenter.default.post(name: .notificationFilteringChanged, object: nil) + if requests.count > 0 { await MainActor.run { [weak self] in diff --git a/Mastodon/Scene/Notification/NotificationTimeline/NotificationTimelineViewModel.swift b/Mastodon/Scene/Notification/NotificationTimeline/NotificationTimelineViewModel.swift index 639a20d6f..a60f48025 100644 --- a/Mastodon/Scene/Notification/NotificationTimeline/NotificationTimelineViewModel.swift +++ b/Mastodon/Scene/Notification/NotificationTimeline/NotificationTimelineViewModel.swift @@ -89,6 +89,17 @@ final class NotificationTimelineViewModel { } }) .store(in: &disposeBag) + + NotificationCenter.default.addObserver(self, selector: #selector(Self.notificationFilteringChanged(_:)), name: .notificationFilteringChanged, object: nil) + } + + //MARK: - Notifications + + @objc func notificationFilteringChanged(_ notification: Notification) { + dataController.records = [] + Task { [weak self] in + await self?.loadLatest() + } } } diff --git a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Notification.swift b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Notification.swift index 9a8a8b0cd..9af896130 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Notification.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Notification.swift @@ -142,3 +142,7 @@ extension APIService { return response } } + +extension Notification.Name { + public static let notificationFilteringChanged = Notification.Name(rawValue: "org.joinmastodon.app.notificationFilteringsChanged") +}