mirror of https://github.com/oxen-io/session-ios
				
				
				
			Create AttachmentUploadJob & AttachmentDownloadJob
Also conform SnodeMessage to NSCodingpull/308/head
							parent
							
								
									b4545903b1
								
							
						
					
					
						commit
						28172b4ed2
					
				@ -0,0 +1,22 @@
 | 
			
		||||
import SessionUtilities
 | 
			
		||||
 | 
			
		||||
// TODO: Implementation
 | 
			
		||||
 | 
			
		||||
public final class AttachmentDownloadJob : NSObject, Job,  NSCoding { // NSObject/NSCoding conformance is needed for YapDatabase compatibility
 | 
			
		||||
 | 
			
		||||
    // MARK: Settings
 | 
			
		||||
    private static let maxRetryCount: UInt = 20
 | 
			
		||||
 | 
			
		||||
    // MARK: Coding
 | 
			
		||||
    public init?(coder: NSCoder) { }
 | 
			
		||||
 | 
			
		||||
    public func encode(with coder: NSCoder) { }
 | 
			
		||||
 | 
			
		||||
    // MARK: Running
 | 
			
		||||
    public func execute() { }
 | 
			
		||||
 | 
			
		||||
    private func handleSuccess() { }
 | 
			
		||||
 | 
			
		||||
    private func handleFailure(error: Error) { }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,22 @@
 | 
			
		||||
import SessionUtilities
 | 
			
		||||
 | 
			
		||||
// TODO: Implementation
 | 
			
		||||
 | 
			
		||||
public final class AttachmentUploadJob : NSObject, Job,  NSCoding { // NSObject/NSCoding conformance is needed for YapDatabase compatibility
 | 
			
		||||
 | 
			
		||||
    // MARK: Settings
 | 
			
		||||
    private static let maxRetryCount: UInt = 20
 | 
			
		||||
 | 
			
		||||
    // MARK: Coding
 | 
			
		||||
    public init?(coder: NSCoder) { }
 | 
			
		||||
 | 
			
		||||
    public func encode(with coder: NSCoder) { }
 | 
			
		||||
 | 
			
		||||
    // MARK: Running
 | 
			
		||||
    public func execute() { }
 | 
			
		||||
 | 
			
		||||
    private func handleSuccess() { }
 | 
			
		||||
 | 
			
		||||
    private func handleFailure(error: Error) { }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,47 @@
 | 
			
		||||
import PromiseKit
 | 
			
		||||
import SessionSnodeKit
 | 
			
		||||
import SessionUtilities
 | 
			
		||||
 | 
			
		||||
// TODO: Implementation
 | 
			
		||||
// TODO: Result handling
 | 
			
		||||
// TODO: Retrying
 | 
			
		||||
 | 
			
		||||
public final class NotifyPNServerJob : NSObject, Job, NSCoding { // NSObject/NSCoding conformance is needed for YapDatabase compatibility
 | 
			
		||||
    private let message: SnodeMessage
 | 
			
		||||
    private var failureCount: UInt
 | 
			
		||||
 | 
			
		||||
    // MARK: Settings
 | 
			
		||||
    private static let maxRetryCount: UInt = 20
 | 
			
		||||
 | 
			
		||||
    // MARK: Initialization
 | 
			
		||||
    init(message: SnodeMessage) {
 | 
			
		||||
        self.message = message
 | 
			
		||||
        self.failureCount = 0
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // MARK: Coding
 | 
			
		||||
    public init?(coder: NSCoder) {
 | 
			
		||||
        guard let message = coder.decodeObject(forKey: "message") as! SnodeMessage? else { return nil }
 | 
			
		||||
        self.message = message
 | 
			
		||||
        self.failureCount = coder.decodeObject(forKey: "failureCount") as! UInt? ?? 0
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public func encode(with coder: NSCoder) {
 | 
			
		||||
        coder.encode(message, forKey: "message")
 | 
			
		||||
        coder.encode(failureCount, forKey: "failureCount")
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // MARK: Running
 | 
			
		||||
    public func execute() {
 | 
			
		||||
        
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private func handleSuccess() {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private func handleFailure(error: Error) {
 | 
			
		||||
        self.failureCount += 1
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,35 +0,0 @@
 | 
			
		||||
import PromiseKit
 | 
			
		||||
import SessionUtilities
 | 
			
		||||
 | 
			
		||||
public struct SnodeMessage {
 | 
			
		||||
    /// The hex encoded public key of the recipient.
 | 
			
		||||
    let recipient: String
 | 
			
		||||
    /// The content of the message.
 | 
			
		||||
    let data: LosslessStringConvertible
 | 
			
		||||
    /// The time to live for the message in milliseconds.
 | 
			
		||||
    let ttl: UInt64
 | 
			
		||||
    /// When the proof of work was calculated.
 | 
			
		||||
    ///
 | 
			
		||||
    /// - Note: Expressed as milliseconds since 00:00:00 UTC on 1 January 1970.
 | 
			
		||||
    let timestamp: UInt64
 | 
			
		||||
    /// The base 64 encoded proof of work.
 | 
			
		||||
    let nonce: String
 | 
			
		||||
 | 
			
		||||
    public init(recipient: String, data: LosslessStringConvertible, ttl: UInt64, timestamp: UInt64, nonce: String) {
 | 
			
		||||
        self.recipient = recipient
 | 
			
		||||
        self.data = data
 | 
			
		||||
        self.ttl = ttl
 | 
			
		||||
        self.timestamp = timestamp
 | 
			
		||||
        self.nonce = nonce
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public func toJSON() -> JSON {
 | 
			
		||||
        return [
 | 
			
		||||
            "pubKey" : recipient,
 | 
			
		||||
            "data" : data.description,
 | 
			
		||||
            "ttl" : String(ttl),
 | 
			
		||||
            "timestamp" : String(timestamp),
 | 
			
		||||
            "nonce" : nonce
 | 
			
		||||
        ]
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,60 @@
 | 
			
		||||
import PromiseKit
 | 
			
		||||
import SessionUtilities
 | 
			
		||||
 | 
			
		||||
public final class SnodeMessage : NSObject, NSCoding { // NSObject/NSCoding conformance is needed for YapDatabase compatibility
 | 
			
		||||
    /// The hex encoded public key of the recipient.
 | 
			
		||||
    public let recipient: String
 | 
			
		||||
    /// The content of the message.
 | 
			
		||||
    public let data: LosslessStringConvertible
 | 
			
		||||
    /// The time to live for the message in milliseconds.
 | 
			
		||||
    public let ttl: UInt64
 | 
			
		||||
    /// When the proof of work was calculated.
 | 
			
		||||
    ///
 | 
			
		||||
    /// - Note: Expressed as milliseconds since 00:00:00 UTC on 1 January 1970.
 | 
			
		||||
    public let timestamp: UInt64
 | 
			
		||||
    /// The base 64 encoded proof of work.
 | 
			
		||||
    public let nonce: String
 | 
			
		||||
 | 
			
		||||
    // MARK: Initialization
 | 
			
		||||
    public init(recipient: String, data: LosslessStringConvertible, ttl: UInt64, timestamp: UInt64, nonce: String) {
 | 
			
		||||
        self.recipient = recipient
 | 
			
		||||
        self.data = data
 | 
			
		||||
        self.ttl = ttl
 | 
			
		||||
        self.timestamp = timestamp
 | 
			
		||||
        self.nonce = nonce
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // MARK: Coding
 | 
			
		||||
    public init?(coder: NSCoder) {
 | 
			
		||||
        guard let recipient = coder.decodeObject(forKey: "recipient") as! String?,
 | 
			
		||||
            let data = coder.decodeObject(forKey: "data") as! String?,
 | 
			
		||||
            let ttl = coder.decodeObject(forKey: "ttl") as! UInt64?,
 | 
			
		||||
            let timestamp = coder.decodeObject(forKey: "timestamp") as! UInt64?,
 | 
			
		||||
            let nonce = coder.decodeObject(forKey: "nonce") as! String? else { return nil }
 | 
			
		||||
        self.recipient = recipient
 | 
			
		||||
        self.data = data
 | 
			
		||||
        self.ttl = ttl
 | 
			
		||||
        self.timestamp = timestamp
 | 
			
		||||
        self.nonce = nonce
 | 
			
		||||
        super.init()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public func encode(with coder: NSCoder) {
 | 
			
		||||
        coder.encode(recipient, forKey: "recipient")
 | 
			
		||||
        coder.encode(data, forKey: "data")
 | 
			
		||||
        coder.encode(ttl, forKey: "ttl")
 | 
			
		||||
        coder.encode(timestamp, forKey: "timestamp")
 | 
			
		||||
        coder.encode(nonce, forKey: "nonce")
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // MARK: JSON Conversion
 | 
			
		||||
    public func toJSON() -> JSON {
 | 
			
		||||
        return [
 | 
			
		||||
            "pubKey" : recipient,
 | 
			
		||||
            "data" : data.description,
 | 
			
		||||
            "ttl" : String(ttl),
 | 
			
		||||
            "timestamp" : String(timestamp),
 | 
			
		||||
            "nonce" : nonce
 | 
			
		||||
        ]
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
					Loading…
					
					
				
		Reference in New Issue