Fix push subscription policy/alerts not persisting

This commit is contained in:
Shadowfacts 2024-04-09 21:07:14 -04:00
parent ff11835333
commit 4c957b86ae
4 changed files with 15 additions and 0 deletions

View File

@ -24,6 +24,9 @@ class DisabledPushManager: _PushManager {
func removeSubscription(account: UserAccountInfo) { func removeSubscription(account: UserAccountInfo) {
} }
func updateSubscription(account: UserAccountInfo, alerts: PushSubscription.Alerts, policy: PushSubscription.Policy) {
}
func pushSubscription(account: UserAccountInfo) -> PushSubscription? { func pushSubscription(account: UserAccountInfo) -> PushSubscription? {
nil nil
} }

View File

@ -47,6 +47,7 @@ public protocol _PushManager {
func createSubscription(account: UserAccountInfo) throws -> PushSubscription func createSubscription(account: UserAccountInfo) throws -> PushSubscription
func removeSubscription(account: UserAccountInfo) func removeSubscription(account: UserAccountInfo)
func updateSubscription(account: UserAccountInfo, alerts: PushSubscription.Alerts, policy: PushSubscription.Policy)
func pushSubscription(account: UserAccountInfo) -> PushSubscription? func pushSubscription(account: UserAccountInfo) -> PushSubscription?
func register(transactionID: UInt64) async throws -> PushProxyRegistration func register(transactionID: UInt64) async throws -> PushProxyRegistration

View File

@ -95,6 +95,16 @@ class PushManagerImpl: _PushManager {
subscriptions.removeAll { $0.accountID == account.id } subscriptions.removeAll { $0.accountID == account.id }
} }
func updateSubscription(account: UserAccountInfo, alerts: PushSubscription.Alerts, policy: PushSubscription.Policy) {
guard let index = subscriptions.firstIndex(where: { $0.accountID == account.id }) else {
return
}
var copy = subscriptions[index]
copy.alerts = alerts
copy.policy = policy
subscriptions[index] = copy
}
func pushSubscription(account: UserAccountInfo) -> PushSubscription? { func pushSubscription(account: UserAccountInfo) -> PushSubscription? {
subscriptions.first { $0.accountID == account.id } subscriptions.first { $0.accountID == account.id }
} }

View File

@ -108,6 +108,7 @@ struct PushInstanceSettingsView: View {
do { do {
let result = try await mastodonController.updatePushSubscription(alerts: alerts, policy: policy) let result = try await mastodonController.updatePushSubscription(alerts: alerts, policy: policy)
PushManager.logger.debug("Push subscription \(result.id) updated on \(account.instanceURL)") PushManager.logger.debug("Push subscription \(result.id) updated on \(account.instanceURL)")
await PushManager.shared.updateSubscription(account: account, alerts: alerts, policy: policy)
subscription?.alerts = alerts subscription?.alerts = alerts
subscription?.policy = policy subscription?.policy = policy
return true return true