mirror of https://github.com/oxen-io/session-ios
Merge commit '07fefc168fcadb5e96aa3a076a27b6756cf91b6c' into p2p
commit
0566d94105
@ -1 +1 @@
|
|||||||
Subproject commit 04f0c4baf6a53b9e2e2f161d5da3574b2dbd333d
|
Subproject commit 6eacc62ee03ae19105782f2ea60ac8ae46814788
|
@ -0,0 +1,45 @@
|
|||||||
|
import PromiseKit
|
||||||
|
|
||||||
|
internal extension LokiAPI {
|
||||||
|
|
||||||
|
private static let receivedMessageHashValuesKey = "receivedMessageHashValuesKey"
|
||||||
|
private static let receivedMessageHashValuesCollection = "receivedMessageHashValuesCollection"
|
||||||
|
|
||||||
|
internal static func getLastMessageHashValue(for target: Target) -> String? {
|
||||||
|
var result: String? = nil
|
||||||
|
// Uses a read/write connection because getting the last message hash value also removes expired messages as needed
|
||||||
|
storage.dbReadWriteConnection.readWrite { transaction in
|
||||||
|
result = storage.getLastMessageHash(forServiceNode: target.address, transaction: transaction)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static func setLastMessageHashValue(for target: Target, hashValue: String, expiresAt: UInt64) {
|
||||||
|
storage.dbReadWriteConnection.readWrite { transaction in
|
||||||
|
storage.setLastMessageHash(forServiceNode: target.address, hash: hashValue, expiresAt: expiresAt, transaction: transaction)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static func getReceivedMessageHashValues() -> Set<String>? {
|
||||||
|
var result: Set<String>? = nil
|
||||||
|
storage.dbReadConnection.read { transaction in
|
||||||
|
result = transaction.object(forKey: receivedMessageHashValuesKey, inCollection: receivedMessageHashValuesCollection) as! Set<String>?
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static func setReceivedMessageHashValues(to receivedMessageHashValues: Set<String>) {
|
||||||
|
storage.dbReadWriteConnection.readWrite { transaction in
|
||||||
|
transaction.setObject(receivedMessageHashValues, forKey: receivedMessageHashValuesKey, inCollection: receivedMessageHashValuesCollection)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal extension AnyPromise {
|
||||||
|
|
||||||
|
internal static func from<T : Any>(_ promise: Promise<T>) -> AnyPromise {
|
||||||
|
let result = AnyPromise(promise)
|
||||||
|
result.retainUntilComplete()
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
|
||||||
|
internal extension LokiAPI {
|
||||||
|
|
||||||
|
internal struct Target : Hashable {
|
||||||
|
internal let address: String
|
||||||
|
internal let port: UInt32
|
||||||
|
|
||||||
|
internal init(address: String, port: UInt32) {
|
||||||
|
self.address = address
|
||||||
|
self.port = port
|
||||||
|
}
|
||||||
|
|
||||||
|
internal init(from targetWrapper: TargetWrapper) {
|
||||||
|
self.address = targetWrapper.address
|
||||||
|
self.port = targetWrapper.port
|
||||||
|
}
|
||||||
|
|
||||||
|
internal enum Method : String {
|
||||||
|
/// Only supported by snode targets.
|
||||||
|
case getSwarm = "get_snodes_for_pubkey"
|
||||||
|
/// Only supported by snode targets.
|
||||||
|
case getMessages = "retrieve"
|
||||||
|
case sendMessage = "store"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
@objc internal final class TargetWrapper : NSObject, NSCoding {
|
||||||
|
internal let address: String
|
||||||
|
internal let port: UInt32
|
||||||
|
|
||||||
|
internal init(from target: LokiAPI.Target) {
|
||||||
|
address = target.address
|
||||||
|
port = target.port
|
||||||
|
super.init()
|
||||||
|
}
|
||||||
|
|
||||||
|
internal init?(coder: NSCoder) {
|
||||||
|
address = coder.decodeObject(forKey: "address") as! String
|
||||||
|
port = coder.decodeObject(forKey: "port") as! UInt32
|
||||||
|
super.init()
|
||||||
|
}
|
||||||
|
|
||||||
|
internal func encode(with coder: NSCoder) {
|
||||||
|
coder.encode(address, forKey: "address")
|
||||||
|
coder.encode(port, forKey: "port")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue