From d8545a01b4c15a4c066997f34d34901ec582b994 Mon Sep 17 00:00:00 2001 From: Davide Date: Tue, 19 Nov 2024 19:44:31 +0100 Subject: [PATCH] Update profiles requirements on new in-app receipt (#895) Required features were only updated when reloading the local profiles, but they may also change on in-app events due to changes in eligibility. --- .../Business/ProfileManager.swift | 19 ++++++++++++++----- .../UILibrary/Business/AppContext.swift | 4 ++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Passepartout/Library/Sources/CommonLibrary/Business/ProfileManager.swift b/Passepartout/Library/Sources/CommonLibrary/Business/ProfileManager.swift index 5433d5de..36a1a6fa 100644 --- a/Passepartout/Library/Sources/CommonLibrary/Business/ProfileManager.swift +++ b/Passepartout/Library/Sources/CommonLibrary/Business/ProfileManager.swift @@ -60,11 +60,7 @@ public final class ProfileManager: ObservableObject { private var allProfiles: [Profile.ID: Profile] { didSet { reloadFilteredProfiles(with: searchSubject.value) - if let processor { - requiredFeatures = allProfiles.reduce(into: [:]) { - $0[$1.key] = processor.verify($1.value) - } - } + reloadRequiredFeatures() } } @@ -185,6 +181,19 @@ extension ProfileManager { public func search(byName name: String) { searchSubject.send(name) } + + public func reloadRequiredFeatures() { + guard let processor else { + return + } + requiredFeatures = allProfiles.reduce(into: [:]) { + guard let ineligible = processor.verify($1.value), !ineligible.isEmpty else { + return + } + $0[$1.key] = ineligible + } + pp_log(.App.profiles, .info, "Required features: \(requiredFeatures)") + } } // MARK: - CRUD diff --git a/Passepartout/Library/Sources/UILibrary/Business/AppContext.swift b/Passepartout/Library/Sources/UILibrary/Business/AppContext.swift index 6b2d8b49..47b0c5d8 100644 --- a/Passepartout/Library/Sources/UILibrary/Business/AppContext.swift +++ b/Passepartout/Library/Sources/UILibrary/Business/AppContext.swift @@ -176,6 +176,10 @@ private extension AppContext { } catch { pp_log(.App.profiles, .error, "\tUnable to re-observe remote profiles: \(error)") } + + // refresh required profile features + pp_log(.App.profiles, .info, "\tReload profiles required features...") + profileManager.reloadRequiredFeatures() } await pendingTask?.value pendingTask = nil