From 25ff4482b64831cf25ebbaf923210ef81e34c640 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Mon, 28 Sep 2020 09:18:11 +1000 Subject: [PATCH] Don't acknowledge messages to the PN server --- SignalServiceKit/src/Loki/API/SnodeAPI.swift | 9 ++------- .../LokiPushNotificationManager.swift | 17 ----------------- 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/SignalServiceKit/src/Loki/API/SnodeAPI.swift b/SignalServiceKit/src/Loki/API/SnodeAPI.swift index d61d810d8..ec240ec46 100644 --- a/SignalServiceKit/src/Loki/API/SnodeAPI.swift +++ b/SignalServiceKit/src/Loki/API/SnodeAPI.swift @@ -243,25 +243,20 @@ public final class SnodeAPI : NSObject { internal static func parseRawMessagesResponse(_ rawResponse: Any, from snode: Snode, associatedWith publicKey: String) -> [SSKProtoEnvelope] { guard let json = rawResponse as? JSON, let rawMessages = json["messages"] as? [JSON] else { return [] } - if let (lastHash, expirationDate) = updateLastMessageHashValueIfPossible(for: snode, associatedWith: publicKey, from: rawMessages), - UserDefaults.standard[.isUsingFullAPNs] { - LokiPushNotificationManager.acknowledgeDelivery(forMessageWithHash: lastHash, expiration: expirationDate, publicKey: getUserHexEncodedPublicKey()) - } + updateLastMessageHashValueIfPossible(for: snode, associatedWith: publicKey, from: rawMessages) let rawNewMessages = removeDuplicates(from: rawMessages, associatedWith: publicKey) let newMessages = parseProtoEnvelopes(from: rawNewMessages) return newMessages } - private static func updateLastMessageHashValueIfPossible(for snode: Snode, associatedWith publicKey: String, from rawMessages: [JSON]) -> (String, UInt64)? { + private static func updateLastMessageHashValueIfPossible(for snode: Snode, associatedWith publicKey: String, from rawMessages: [JSON]) { if let lastMessage = rawMessages.last, let lastHash = lastMessage["hash"] as? String, let expirationDate = lastMessage["expiration"] as? UInt64 { try! Storage.writeSync { transaction in Storage.setLastMessageHashInfo(for: snode, associatedWith: publicKey, to: [ "hash" : lastHash, "expirationDate" : NSNumber(value: expirationDate) ], using: transaction) } - return (lastHash, expirationDate) } else if (!rawMessages.isEmpty) { print("[Loki] Failed to update last message hash value from: \(rawMessages).") } - return nil } private static func removeDuplicates(from rawMessages: [JSON], associatedWith publicKey: String) -> [JSON] { diff --git a/SignalServiceKit/src/Loki/Push Notifications/LokiPushNotificationManager.swift b/SignalServiceKit/src/Loki/Push Notifications/LokiPushNotificationManager.swift index 21a01c20a..0ea0ffe94 100644 --- a/SignalServiceKit/src/Loki/Push Notifications/LokiPushNotificationManager.swift +++ b/SignalServiceKit/src/Loki/Push Notifications/LokiPushNotificationManager.swift @@ -143,21 +143,4 @@ public final class LokiPushNotificationManager : NSObject { static func objc_notify(for signalMessage: SignalMessage) -> AnyPromise { return AnyPromise.from(notify(for: signalMessage)) } - - static func acknowledgeDelivery(forMessageWithHash hash: String, expiration: UInt64, publicKey: String) { - let parameters: JSON = [ "lastHash" : hash, "pubKey" : publicKey, "expiration" : expiration] - let url = URL(string: "\(server)/acknowledge_message_delivery")! - let request = TSRequest(url: url, method: "POST", parameters: parameters) - request.allHTTPHeaderFields = [ "Content-Type" : "application/json" ] - TSNetworkManager.shared().makeRequest(request, success: { _, response in - guard let json = response as? JSON else { - return print("[Loki] Couldn't acknowledge delivery for message with hash: \(hash).") - } - guard json["code"] as? Int != 0 else { - return print("[Loki] Couldn't acknowledge delivery for message with hash: \(hash) due to error: \(json["message"] as? String ?? "nil").") - } - }, failure: { _, error in - print("[Loki] Couldn't acknowledge delivery for message with hash: \(hash) due to error: \(error).") - }) - } }