From fc7f6bca0aa0fe634d24c6ed96ba942f0538b029 Mon Sep 17 00:00:00 2001 From: shannon Date: Thu, 27 Feb 2025 18:35:05 -0500 Subject: [PATCH] Check for ability to group notifications before view appears The instance information may not have been available when the initial check happened. See IOS-363 for root cause to fix later --- .../GroupedNotificationFeedLoader.swift | 2 +- .../NotificationListViewController.swift | 14 ++++++++++++++ .../MastodonCore/MastodonAuthentication.swift | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Mastodon/In Progress New Layout and Datamodel/GroupedNotificationFeedLoader.swift b/Mastodon/In Progress New Layout and Datamodel/GroupedNotificationFeedLoader.swift index a394f6cfc..ee790adc1 100644 --- a/Mastodon/In Progress New Layout and Datamodel/GroupedNotificationFeedLoader.swift +++ b/Mastodon/In Progress New Layout and Datamodel/GroupedNotificationFeedLoader.swift @@ -53,7 +53,7 @@ final public class GroupedNotificationFeedLoader { private var isFetching: Bool = false - private let useGroupedNotificationsApi: Bool + public let useGroupedNotificationsApi: Bool private let cacheManager: (any NotificationsCacheManager)? private let user: MastodonUserIdentifier? diff --git a/Mastodon/In Progress New Layout and Datamodel/NotificationListViewController.swift b/Mastodon/In Progress New Layout and Datamodel/NotificationListViewController.swift index 154b564c6..b8669d943 100644 --- a/Mastodon/In Progress New Layout and Datamodel/NotificationListViewController.swift +++ b/Mastodon/In Progress New Layout and Datamodel/NotificationListViewController.swift @@ -41,6 +41,10 @@ class NotificationListViewController: UIHostingController "init(coder:) not implemented for NotificationListViewController") } + override func viewWillAppear(_ animated: Bool) { + viewModel.checkCanGroupNotifications() + } + @objc private func showNotificationPolicySettings(_ sender: Any) { guard let policy = viewModel.filteredNotificationsViewModel.policy else { return } Task { @@ -393,6 +397,16 @@ private class NotificationListViewModel: ObservableObject { break } } + + func checkCanGroupNotifications() { + guard let currentInstance = AuthenticationServiceProvider.shared.currentActiveUser.value?.authentication.instanceConfiguration else { + presentError?(APIService.APIError.implicit(.authenticationMissing)) + return + } + if currentInstance.canGroupNotifications, !feedLoader.useGroupedNotificationsApi { + createNewFeedLoader() + } + } private func createNewFeedLoader() { fetchFilteredNotificationsPolicy() diff --git a/MastodonSDK/Sources/MastodonCore/MastodonAuthentication.swift b/MastodonSDK/Sources/MastodonCore/MastodonAuthentication.swift index 02d9a6b3c..10ef680ba 100644 --- a/MastodonSDK/Sources/MastodonCore/MastodonAuthentication.swift +++ b/MastodonSDK/Sources/MastodonCore/MastodonAuthentication.swift @@ -44,7 +44,7 @@ public struct MastodonAuthentication: Codable, Hashable, UserIdentifier { public var canGroupNotifications: Bool { switch self { - case let .v1(instance): + case let .v1(_): return false case let .v2(instance, _): guard let apiVersion = instance.apiVersions?["mastodon"] else { return false }