Compare commits
No commits in common. "bc516a632698d01f31c039e25e3d8e716ef0ef6e" and "9f6910ba7328029157f37c9e7f9f594820199bf9" have entirely different histories.
bc516a6326
...
9f6910ba73
|
@ -17,10 +17,6 @@ class DisabledPushManager: _PushManager {
|
|||
nil
|
||||
}
|
||||
|
||||
var subscriptions: [PushSubscription] {
|
||||
[]
|
||||
}
|
||||
|
||||
func createSubscription(account: UserAccountInfo) throws -> PushSubscription {
|
||||
throw Disabled()
|
||||
}
|
||||
|
|
|
@ -24,13 +24,15 @@ public struct PushManager {
|
|||
@MainActor
|
||||
private static func createPushManager() -> any _PushManager {
|
||||
guard let info = Bundle.main.object(forInfoDictionaryKey: "TuskerInfo") as? [String: Any],
|
||||
let scheme = info["PushProxyScheme"] as? String,
|
||||
let host = info["PushProxyHost"] as? String,
|
||||
!scheme.isEmpty,
|
||||
!host.isEmpty else {
|
||||
logger.debug("Missing proxy info, push disabled")
|
||||
return DisabledPushManager()
|
||||
}
|
||||
var endpoint = URLComponents()
|
||||
endpoint.scheme = "https"
|
||||
endpoint.scheme = scheme
|
||||
endpoint.host = host
|
||||
let url = endpoint.url!
|
||||
logger.debug("Push notifications enabled with proxy \(url.absoluteString, privacy: .public)")
|
||||
|
@ -43,7 +45,6 @@ public protocol _PushManager {
|
|||
var enabled: Bool { get }
|
||||
var proxyRegistration: PushProxyRegistration? { get }
|
||||
|
||||
var subscriptions: [PushSubscription] { get }
|
||||
func createSubscription(account: UserAccountInfo) throws -> PushSubscription
|
||||
func removeSubscription(account: UserAccountInfo)
|
||||
func updateSubscription(account: UserAccountInfo, alerts: PushSubscription.Alerts, policy: PushSubscription.Policy)
|
||||
|
|
|
@ -40,7 +40,7 @@ class PushManagerImpl: _PushManager {
|
|||
defaults.setValue(newValue?.defaultsDict, forKey: "PushProxyRegistration")
|
||||
}
|
||||
}
|
||||
public private(set) var subscriptions: [PushSubscription] {
|
||||
private(set) var subscriptions: [PushSubscription] {
|
||||
get {
|
||||
if let array = defaults.array(forKey: "PushSubscriptions") as? [[String: Any]] {
|
||||
return array.compactMap(PushSubscription.init(defaultsDict:))
|
||||
|
|
|
@ -3,4 +3,3 @@
|
|||
DEVELOPMENT_TEAM = YOUR_TEAM_ID
|
||||
BUNDLE_ID_PREFIX = com.example
|
||||
|
||||
TUSKER_PUSH_PROXY_HOST =
|
||||
|
|
|
@ -105,6 +105,8 @@
|
|||
<dict>
|
||||
<key>PushProxyHost</key>
|
||||
<string>$(TUSKER_PUSH_PROXY_HOST)</string>
|
||||
<key>PushProxyScheme</key>
|
||||
<string>$(TUSKER_PUSH_PROXY_SCHEME)</string>
|
||||
<key>SentryDSN</key>
|
||||
<string>$(SENTRY_DSN)</string>
|
||||
</dict>
|
||||
|
|
|
@ -96,21 +96,6 @@ struct NotificationsPrefsView: View {
|
|||
do {
|
||||
try await PushManager.shared.unregister()
|
||||
pushProxyRegistration = nil
|
||||
for subscription in PushManager.shared.subscriptions {
|
||||
if let account = UserAccountsManager.shared.getAccount(id: subscription.accountID) {
|
||||
let mastodonController = MastodonController.getForAccount(account)
|
||||
do {
|
||||
try await mastodonController.deletePushSubscription()
|
||||
PushManager.shared.removeSubscription(account: account)
|
||||
PushManager.logger.debug("Push subscription removed on \(account.instanceURL)")
|
||||
// this is a bit of a hack. the PushInstanceSettingsViews need to know to update
|
||||
// their @State variables after we remove the subscription
|
||||
NotificationCenter.default.post(name: .pushSubscriptionRemoved, object: account.id)
|
||||
} catch {
|
||||
PushManager.logger.error("Erroring removing push subscription: \(String(describing: error))")
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
} catch {
|
||||
self.error = .unregistering(error)
|
||||
|
@ -135,7 +120,3 @@ private enum NotificationsSetupError: LocalizedError {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Notification.Name {
|
||||
static let pushSubscriptionRemoved = Notification.Name("Tusker.pushSubscriptionRemoved")
|
||||
}
|
||||
|
|
|
@ -52,13 +52,6 @@ struct PushInstanceSettingsView: View {
|
|||
} message: {
|
||||
Text("You must grant permission on \(account.instanceURL.host!) to turn on push notifications.")
|
||||
}
|
||||
.onReceive(NotificationCenter.default
|
||||
.publisher(for: .pushSubscriptionRemoved)
|
||||
.filter { ($0.object as? String) == account.id }
|
||||
) { _ in
|
||||
mode = .off
|
||||
subscription = nil
|
||||
}
|
||||
}
|
||||
|
||||
private func updateNotificationsEnabled(enabled: Bool) async -> Bool {
|
||||
|
|
Loading…
Reference in New Issue