diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index a24f729df..f712ce4a1 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -763,7 +763,7 @@ static NSTimeInterval launchStartedAt; if (isUsingFullAPNs) { __unused AnyPromise *promise = [LKPushNotificationManager registerWithToken:deviceToken hexEncodedPublicKey:self.tsAccountManager.localNumber isForcedUpdate:NO]; } else { - __unused AnyPromise *promise = [LKPushNotificationManager registerWithToken:deviceToken isForcedUpdate:NO]; + __unused AnyPromise *promise = [LKPushNotificationManager unregisterWithToken:deviceToken isForcedUpdate:NO]; } } @@ -949,7 +949,7 @@ static NSTimeInterval launchStartedAt; NSString *hexEncodedDeviceToken = [userDefaults stringForKey:@"deviceToken"]; if (isUsingFullAPNs && hexEncodedDeviceToken != nil) { NSData *deviceToken = [NSData dataFromHexString:hexEncodedDeviceToken]; - [[LKPushNotificationManager registerWithToken:deviceToken isForcedUpdate:YES] retainUntilComplete]; // This actually unregisters the user; we should rename the function + [[LKPushNotificationManager unregisterWithToken:deviceToken isForcedUpdate:YES] retainUntilComplete]; } [ThreadUtil deleteAllContent]; [SSKEnvironment.shared.messageSenderJobQueue clearAllJobs]; diff --git a/SignalServiceKit/src/Account/TSAccountManager.m b/SignalServiceKit/src/Account/TSAccountManager.m index 85af560d1..fc516ab00 100644 --- a/SignalServiceKit/src/Account/TSAccountManager.m +++ b/SignalServiceKit/src/Account/TSAccountManager.m @@ -302,7 +302,7 @@ NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountMa BOOL isUsingFullAPNs = [NSUserDefaults.standardUserDefaults boolForKey:@"isUsingFullAPNs"]; NSData *pushTokenAsData = [NSData dataFromHexString:pushToken]; AnyPromise *promise = isUsingFullAPNs ? [LKPushNotificationManager registerWithToken:pushTokenAsData hexEncodedPublicKey:self.localNumber isForcedUpdate:isForcedUpdate] - : [LKPushNotificationManager registerWithToken:pushTokenAsData isForcedUpdate:isForcedUpdate]; + : [LKPushNotificationManager unregisterWithToken:pushTokenAsData isForcedUpdate:isForcedUpdate]; promise .then(^() { successHandler(); diff --git a/SignalServiceKit/src/Loki/Push Notifications/LokiPushNotificationManager.swift b/SignalServiceKit/src/Loki/Push Notifications/LokiPushNotificationManager.swift index 4f625d909..bc2dd817d 100644 --- a/SignalServiceKit/src/Loki/Push Notifications/LokiPushNotificationManager.swift +++ b/SignalServiceKit/src/Loki/Push Notifications/LokiPushNotificationManager.swift @@ -21,9 +21,9 @@ public final class LokiPushNotificationManager : NSObject { private override init() { } // MARK: Registration - /// Registers the user for silent push notifications (that then trigger the app - /// into fetching messages). Only the user's device token is needed for this. - static func register(with token: Data, isForcedUpdate: Bool) -> Promise { + /// Unregisters the user for push notifications. + /// Only the user's device token is needed for this. + static func unregister(with token: Data, isForcedUpdate: Bool) -> Promise { let hexEncodedToken = token.toHexString() let userDefaults = UserDefaults.standard let oldToken = userDefaults[.deviceToken] @@ -35,10 +35,10 @@ public final class LokiPushNotificationManager : NSObject { return Promise { $0.fulfill(()) } } let parameters = [ "token" : hexEncodedToken ] - let url = URL(string: "\(server)/register")! + let url = URL(string: "\(server)/unregister")! let request = TSRequest(url: url, method: "POST", parameters: parameters) request.allHTTPHeaderFields = [ "Content-Type" : "application/json" ] - let promise = TSNetworkManager.shared().makePromise(request: request).map2 { _, response in + let promise = OnionRequestAPI.sendOnionRequest(request, to: server, using: PNServerPublicKey).map2 { response in guard let json = response as? JSON else { return print("[Loki] Couldn't register device token.") } @@ -60,11 +60,11 @@ public final class LokiPushNotificationManager : NSObject { return promise } - /// Registers the user for silent push notifications (that then trigger the app - /// into fetching messages). Only the user's device token is needed for this. - @objc(registerWithToken:isForcedUpdate:) - static func objc_register(with token: Data, isForcedUpdate: Bool) -> AnyPromise { - return AnyPromise.from(register(with: token, isForcedUpdate: isForcedUpdate)) + /// Unregisters the user for push notifications. + /// Only the user's device token is needed for this. + @objc(unregisterWithToken:isForcedUpdate:) + static func objc_unregister(with token: Data, isForcedUpdate: Bool) -> AnyPromise { + return AnyPromise.from(unregister(with: token, isForcedUpdate: isForcedUpdate)) } /// Registers the user for normal push notifications. Requires the user's device @@ -83,7 +83,7 @@ public final class LokiPushNotificationManager : NSObject { let url = URL(string: "\(server)/register")! let request = TSRequest(url: url, method: "POST", parameters: parameters) request.allHTTPHeaderFields = [ "Content-Type" : "application/json" ] - let promise = TSNetworkManager.shared().makePromise(request: request).map2 { _, response in + let promise = OnionRequestAPI.sendOnionRequest(request, to: server, using: PNServerPublicKey).map2 { response in guard let json = response as? JSON else { return print("[Loki] Couldn't register device token.") } @@ -119,17 +119,17 @@ public final class LokiPushNotificationManager : NSObject { let url = URL(string: "\(server)/\(operation.rawValue)")! let request = TSRequest(url: url, method: "POST", parameters: parameters) request.allHTTPHeaderFields = [ "Content-Type" : "application/json" ] - let promise = TSNetworkManager.shared().makePromise(request: request).map2 { _, response in + let promise = OnionRequestAPI.sendOnionRequest(request, to: server, using: PNServerPublicKey).map2 { response in guard let json = response as? JSON else { - return print("[Loki] Couldn't subscribe to PNs for closed group with ID: \(closedGroupPublicKey).") + return print("[Loki] Couldn't subscribe/unsubscribe closed group: \(closedGroupPublicKey).") } guard json["code"] as? Int != 0 else { - return print("[Loki] Couldn't subscribe to PNs for closed group with ID: \(closedGroupPublicKey) due to error: \(json["message"] as? String ?? "nil").") + return print("[Loki] Couldn't subscribe/unsubscribe for closed group: \(closedGroupPublicKey) due to error: \(json["message"] as? String ?? "nil").") } return } promise.catch2 { error in - print("[Loki] Couldn't subscribe to PNs for closed group with ID: \(closedGroupPublicKey).") + print("[Loki] Couldn't subscribe/unsubscribe closed group: \(closedGroupPublicKey).") } return promise }