mirror of https://github.com/oxen-io/session-ios
Split into LokiDeviceLinkingSession & LokiAPI+MultiDeviceAPI
parent
143755ae8e
commit
34eca6c820
@ -0,0 +1,19 @@
|
||||
import PromiseKit
|
||||
|
||||
public extension LokiAPI {
|
||||
|
||||
public static func addSlaveAccount(with hexEncodedPublicKey: String) -> Promise<Void> {
|
||||
// Adds the given slave account 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
|
||||
notImplemented()
|
||||
}
|
||||
|
||||
public static func getOtherAccounts(for hexEncodedPublicKey: String) -> Promise<[String]> {
|
||||
// Gets the accounts associated with the given hex encoded public key from the server
|
||||
notImplemented()
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
import PromiseKit
|
||||
|
||||
@objc(LKDeviceLinkingAPI)
|
||||
final class LokiDeviceLinkingAPI : NSObject {
|
||||
|
||||
private static var timerStartDate: Date?
|
||||
public static var isListeningForLinkingRequests = false
|
||||
|
||||
// MARK: Settings
|
||||
private static let listeningTimeout: TimeInterval = 60
|
||||
|
||||
// MARK: Lifecycle
|
||||
override private init() { }
|
||||
|
||||
// MARK: Public API
|
||||
@objc public static func startListeningForLinkingRequests(onLinkingRequestReceived: (String) -> Void, onTimeout: @escaping () -> Void) {
|
||||
isListeningForLinkingRequests = true
|
||||
timerStartDate = Date()
|
||||
Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { timer in
|
||||
if Date().timeIntervalSince1970 - timerStartDate!.timeIntervalSince1970 >= listeningTimeout {
|
||||
isListeningForLinkingRequests = false
|
||||
onTimeout()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc public static func authorizeLinkingRequest(with signature: String) {
|
||||
// Authorize the linking request with the given signature
|
||||
}
|
||||
|
||||
public static func addSlaveAccount(with hexEncodedPublicKey: String) -> Promise<String> {
|
||||
// Adds the given slave account to the user's device mapping on the server
|
||||
notImplemented()
|
||||
}
|
||||
|
||||
public static func removeSlaveAccount(with hexEncodedPublicKey: String) -> Promise<String> {
|
||||
// Removes the given slave account from the user's device mapping on the server
|
||||
notImplemented()
|
||||
}
|
||||
|
||||
public static func getOtherAccounts(for hexEncodedPublicKey: String) -> Promise<[String]> {
|
||||
// Gets the accounts associated with the given hex encoded public key from the server
|
||||
notImplemented()
|
||||
}
|
||||
}
|
||||
|
||||
//LokiDeviceLinkingAPI.startListeningForLinkingRequests(onLinkingRequestReceived: { signature in
|
||||
// // 1. Validate the signature
|
||||
// // 2. Ask the user to accept
|
||||
// // 2.1. If the user declined, we're done
|
||||
// // 2.2, If the user accepted: LokiDeviceLinkingAPI.authorizeLinkingRequest(with: signature)
|
||||
//}, onTimeout: {
|
||||
// // Notify the user
|
||||
//})
|
@ -0,0 +1,42 @@
|
||||
import PromiseKit
|
||||
|
||||
@objc(LKDeviceLinkingAPI)
|
||||
final class LokiDeviceLinkingSession : NSObject {
|
||||
private let delegate: LokiDeviceLinkingSessionDelegate
|
||||
private var timer: Timer?
|
||||
public var isListeningForLinkingRequests = false
|
||||
|
||||
// MARK: Lifecycle
|
||||
public init(delegate: LokiDeviceLinkingSessionDelegate) {
|
||||
self.delegate = delegate
|
||||
}
|
||||
|
||||
// MARK: Settings
|
||||
private let listeningTimeout: TimeInterval = 60
|
||||
|
||||
// MARK: Public API
|
||||
public func startListeningForLinkingRequests() {
|
||||
isListeningForLinkingRequests = true
|
||||
timer = Timer.scheduledTimer(withTimeInterval: listeningTimeout, repeats: false) { [weak self] timer in
|
||||
guard let self = self else { return }
|
||||
self.stopListeningForLinkingRequests()
|
||||
self.delegate.handleDeviceLinkingSessionTimeout()
|
||||
}
|
||||
}
|
||||
|
||||
public func stopListeningForLinkingRequests() {
|
||||
timer?.invalidate()
|
||||
timer = nil
|
||||
isListeningForLinkingRequests = false
|
||||
}
|
||||
|
||||
public func processLinkingRequest(with signature: String) {
|
||||
guard isListeningForLinkingRequests else { return }
|
||||
stopListeningForLinkingRequests()
|
||||
delegate.handleDeviceLinkingRequestReceived(with: signature)
|
||||
}
|
||||
|
||||
public func authorizeLinkingRequest(with signature: String) {
|
||||
// TODO: Authorize the linking request with the given signature
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
|
||||
public protocol LokiDeviceLinkingSessionDelegate {
|
||||
|
||||
func handleDeviceLinkingRequestReceived(with signature: String)
|
||||
func handleDeviceLinkingSessionTimeout()
|
||||
}
|
Loading…
Reference in New Issue