pull/55/head
Niels Andriesse 6 years ago
parent 51c969c906
commit 7fe7245c64

@ -119,8 +119,9 @@ public final class LokiAPI : NSObject {
public static func sendSignalMessage(_ signalMessage: SignalMessage, onP2PSuccess: @escaping () -> Void) -> Promise<Set<RawResponsePromise>> {
let result = internalSendSignalMessage(signalMessage, onP2PSuccess: onP2PSuccess)
// Use a best attempt approach for multi device for now
getOtherAccounts(for: signalMessage.recipientID).done { hexEncodedPublicKeyList in
hexEncodedPublicKeyList.forEach { hexEncodedPublicKey in
LokiStorageAPI.getDeviceLinks(associatedWith: signalMessage.recipientID).done { deviceLinks in
let associatedHexEncodedPublicKeys = Set(deviceLinks.flatMap { [ $0.master.hexEncodedPublicKey, $0.slave.hexEncodedPublicKey ] }).subtracting([ signalMessage.recipientID ])
associatedHexEncodedPublicKeys.forEach { hexEncodedPublicKey in
let signalMessageCopy = signalMessage.copy(with: hexEncodedPublicKey)
internalSendSignalMessage(signalMessageCopy) { }
}

@ -7,18 +7,19 @@ public final class LokiStorageAPI : NSObject {
override private init() { }
// MARK: Public API
public static func addSlaveAccount(with hexEncodedPublicKey: String) -> Promise<Void> {
// Adds the given slave account to the user's device mapping on the server
public static func addDeviceLink(_ deviceLink: LokiDeviceLink) -> Promise<Void> {
// Adds the given device link to the user's device mapping on the server
notImplemented()
}
public static func removeSlaveAccount(with hexEncodedPublicKey: String) -> Promise<Void> {
// Removes the given slave account from the user's device mapping on the server
public static func removeDeviceLink(_ deviceLink: LokiDeviceLink) -> Promise<Void> {
// Removes the given device link from the user's device mapping on the server
notImplemented()
}
public static func getAssociatedAccounts(for hexEncodedPublicKey: String) -> Promise<[String]> {
// Gets the accounts associated with the given hex encoded public key from the server
public static func getDeviceLinks(associatedWith hexEncodedPublicKey: String) -> Promise<Set<LokiDeviceLink>> {
// Gets the device links associated with the given hex encoded public key from the
// server and stores and returns the valid ones
notImplemented()
}
}

@ -1,12 +1,12 @@
public struct LokiDeviceLink {
public struct LokiDeviceLink : Hashable {
public let master: Device
public let slave: Device
public var isAuthorized: Bool { return master.signature != nil }
// MARK: Types
public struct Device {
public struct Device : Hashable {
public let hexEncodedPublicKey: String
public let signature: Data?
@ -14,6 +14,11 @@ public struct LokiDeviceLink {
self.hexEncodedPublicKey = hexEncodedPublicKey
self.signature = signature
}
public func hash(into hasher: inout Hasher) {
hexEncodedPublicKey.hash(into: &hasher)
signature?.hash(into: &hasher)
}
}
// MARK: Lifecycle
@ -21,4 +26,10 @@ public struct LokiDeviceLink {
self.master = master
self.slave = slave
}
// MARK: Hashing
public func hash(into hasher: inout Hasher) {
master.hash(into: &hasher)
slave.hash(into: &hasher)
}
}

Loading…
Cancel
Save