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.
This commit is contained in:
Davide 2024-11-19 19:44:31 +01:00 committed by GitHub
parent 9528cecc27
commit d8545a01b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 5 deletions

View File

@ -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

View File

@ -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