From bef616b5bdcc57854a48c56182b928e31d4d3d6c Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Sun, 8 Nov 2020 16:38:03 +1100 Subject: [PATCH] Implement NotifyPNServerJob --- SessionMessagingKit/Jobs/NotifyPNServerJob.swift | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/SessionMessagingKit/Jobs/NotifyPNServerJob.swift b/SessionMessagingKit/Jobs/NotifyPNServerJob.swift index 30a0abf92..f4b9930ab 100644 --- a/SessionMessagingKit/Jobs/NotifyPNServerJob.swift +++ b/SessionMessagingKit/Jobs/NotifyPNServerJob.swift @@ -2,8 +2,6 @@ import PromiseKit import SessionSnodeKit import SessionUtilities -// TODO: Implementation - public final class NotifyPNServerJob : NSObject, Job, NSCoding { // NSObject/NSCoding conformance is needed for YapDatabase compatibility public var delegate: JobDelegate? private let message: SnodeMessage @@ -31,7 +29,18 @@ public final class NotifyPNServerJob : NSObject, Job, NSCoding { // NSObject/NSC // MARK: Running public func execute() { - + let server = Configuration.shared.pnServerURL + let parameters = [ "data" : message.data.description, "send_to" : message.recipient ] + let url = URL(string: "\(server)/notify")! + let request = TSRequest(url: url, method: "POST", parameters: parameters) + request.allHTTPHeaderFields = [ "Content-Type" : "application/json" ] + attempt(maxRetryCount: 4, recoveringOn: DispatchQueue.global()) { + OnionRequestAPI.sendOnionRequest(request, to: server, using: Configuration.shared.pnServerPublicKey).map { _ in } + }.done(on: DispatchQueue.global()) { // Intentionally capture self + self.handleSuccess() + }.catch(on: DispatchQueue.global()) { error in + self.handleFailure(error: error) + } } private func handleSuccess() {