Added logic to unsubscribe for legacy one-to-one PNs

pull/856/head
Morgan Pretty 2 years ago
parent 4330a40f6f
commit 61ad85b97b

@ -0,0 +1,14 @@
// Copyright © 2023 Rangeproof Pty Ltd. All rights reserved.
import Foundation
import SessionSnodeKit
extension PushNotificationAPI {
struct LegacyUnsubscribeRequest: Codable {
private let token: String
init(token: String) {
self.token = token
}
}
}

@ -115,7 +115,42 @@ public enum PushNotificationAPI {
}
}
)
.map { _ in () }
.flatMap { _ in
guard UserDefaults.standard[.hasUnregisteredForLegacyPushNotifications] != true else {
return Just(())
.setFailureType(to: Error.self)
.eraseToAnyPublisher()
}
return PushNotificationAPI
.send(
request: PushNotificationAPIRequest(
endpoint: .legacyUnregister,
body: LegacyUnsubscribeRequest(
token: hexEncodedToken
)
)
)
.retry(maxRetryCount)
.handleEvents(
receiveCompletion: { result in
switch result {
case .finished:
/// Save that we've already unsubscribed
///
/// **Note:** The server can return an error (`response.code != 0`) but
/// that means the server properly processed the request and the error is likely
/// due to the device not actually being previously subscribed for notifications
/// rather than actually failing to unsubscribe
UserDefaults.standard[.hasUnregisteredForLegacyPushNotifications] = true
case .failure: SNLog("Couldn't unsubscribe for legacy notifications.")
}
}
)
.map { _ in () }
.eraseToAnyPublisher()
}
.eraseToAnyPublisher()
].appending(
// FIXME: Remove this once legacy groups are deprecated

@ -31,6 +31,7 @@ public enum SNUserDefaults {
case hasSeenCallIPExposureWarning
case hasSeenCallMissedTips
case isUsingFullAPNs
case hasUnregisteredForLegacyPushNotifications
case wasUnlinked
case isMainAppActive
case isCallOngoing

Loading…
Cancel
Save