Implement basic multi device message sending
This commit is contained in:
parent
60766825ba
commit
b2ea98fb97
|
@ -60,15 +60,8 @@ public final class LokiAPI : NSObject {
|
|||
let timeout: TimeInterval? = useLongPolling ? longPollingTimeout : nil
|
||||
return invoke(.getMessages, on: target, associatedWith: userHexEncodedPublicKey, parameters: parameters, headers: headers, timeout: timeout)
|
||||
}
|
||||
|
||||
// MARK: Public API
|
||||
public static func getMessages() -> Promise<Set<MessageListPromise>> {
|
||||
return getTargetSnodes(for: userHexEncodedPublicKey).mapValues { targetSnode in
|
||||
return getRawMessages(from: targetSnode, usingLongPolling: false).map { parseRawMessagesResponse($0, from: targetSnode) }
|
||||
}.map { Set($0) }.retryingIfNeeded(maxRetryCount: maxRetryCount)
|
||||
}
|
||||
|
||||
public static func sendSignalMessage(_ signalMessage: SignalMessage, onP2PSuccess: @escaping () -> Void) -> Promise<Set<RawResponsePromise>> {
|
||||
|
||||
internal static func internalSendSignalMessage(_ signalMessage: SignalMessage, onP2PSuccess: @escaping () -> Void) -> Promise<Set<RawResponsePromise>> {
|
||||
guard let lokiMessage = LokiMessage.from(signalMessage: signalMessage) else { return Promise(error: Error.messageConversionFailed) }
|
||||
let destination = lokiMessage.destination
|
||||
func sendLokiMessage(_ lokiMessage: LokiMessage, to target: LokiAPITarget) -> RawResponsePromise {
|
||||
|
@ -116,6 +109,24 @@ public final class LokiAPI : NSObject {
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: Public API
|
||||
public static func getMessages() -> Promise<Set<MessageListPromise>> {
|
||||
return getTargetSnodes(for: userHexEncodedPublicKey).mapValues { targetSnode in
|
||||
return getRawMessages(from: targetSnode, usingLongPolling: false).map { parseRawMessagesResponse($0, from: targetSnode) }
|
||||
}.map { Set($0) }.retryingIfNeeded(maxRetryCount: maxRetryCount)
|
||||
}
|
||||
|
||||
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
|
||||
LokiDeviceLinkingAPI.getOtherAccounts(for: signalMessage.recipientID).done { hexEncodedPublicKeyList in
|
||||
hexEncodedPublicKeyList.forEach { hexEncodedPublicKey in
|
||||
internalSendSignalMessage(signalMessage.copy(with: hexEncodedPublicKey)) { }
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// MARK: Public API (Obj-C)
|
||||
@objc(sendSignalMessage:onP2PSuccess:)
|
||||
public static func objc_sendSignalMessage(_ signalMessage: SignalMessage, onP2PSuccess: @escaping () -> Void) -> AnyPromise {
|
||||
|
|
|
@ -6,12 +6,6 @@ final class LokiDeviceLinkingAPI : NSObject {
|
|||
// MARK: Settings
|
||||
private static let listeningTimeout = 60
|
||||
|
||||
// MARK: Types
|
||||
public struct Account {
|
||||
public let hexEncodedPublicKey: String
|
||||
public let isMaster: Bool
|
||||
}
|
||||
|
||||
// MARK: Lifecycle
|
||||
override private init() { }
|
||||
|
||||
|
@ -34,7 +28,7 @@ final class LokiDeviceLinkingAPI : NSObject {
|
|||
notImplemented()
|
||||
}
|
||||
|
||||
public static func getAccounts(for hexEncodedPublicKey: String) -> Promise<[Account]> {
|
||||
public static func getOtherAccounts(for hexEncodedPublicKey: String) -> Promise<[String]> {
|
||||
// Gets the accounts associated with the given hex encoded public key from the server
|
||||
notImplemented()
|
||||
}
|
||||
|
|
|
@ -25,4 +25,10 @@ public final class SignalMessage : NSObject {
|
|||
self.isPing = isPing
|
||||
super.init()
|
||||
}
|
||||
|
||||
public func copy(with recipientID: String) -> SignalMessage {
|
||||
return SignalMessage(type: type, timestamp: timestamp, senderID: senderID, senderDeviceID: senderDeviceID, content: content,
|
||||
recipientID: recipientID, ttl: objc_ttl, isPing: isPing)
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue