mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Don't acknowledge messages to the PN server
This commit is contained in:
parent
b0e38c0e72
commit
25ff4482b6
2 changed files with 2 additions and 24 deletions
|
@ -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] {
|
||||
|
|
|
@ -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).")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue