Fix push subscription policy/alerts not persisting
This commit is contained in:
parent
ff11835333
commit
4c957b86ae
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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 }
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue