diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index b7dbc7122..3fb3c79a5 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -60,7 +60,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; static NSTimeInterval launchStartedAt; -@interface AppDelegate () +@interface AppDelegate () @property (nonatomic) BOOL hasInitialRootViewController; @property (nonatomic) BOOL areVersionMigrationsComplete; @@ -72,6 +72,7 @@ static NSTimeInterval launchStartedAt; @property (nonatomic) LKGroupChatPoller *lokiPublicChatPoller; @property (nonatomic) LKRSSFeedPoller *lokiNewsFeedPoller; @property (nonatomic) LKRSSFeedPoller *lokiMessengerUpdatesFeedPoller; +@property (nonatomic) LKDeviceLinkingSession *lokiDeviceLinkingSession; @end @@ -1638,4 +1639,21 @@ static NSTimeInterval launchStartedAt; } } +- (void)startListeningForLinkingRequests +{ + [self.lokiDeviceLinkingSession stopListeningForLinkingRequests]; + self.lokiDeviceLinkingSession = [[LKDeviceLinkingSession alloc] initWithDelegate:self]; + [self.lokiDeviceLinkingSession startListeningForLinkingRequests]; +} + +- (void)requestUserAuthorizationFor:(LKDeviceLink *)deviceLink +{ + +} + +- (void)handleDeviceLinkingSessionTimeout +{ + +} + @end diff --git a/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m b/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m index c1119fd2c..33d2e978c 100644 --- a/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m +++ b/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m @@ -241,6 +241,7 @@ [section addItem:[OWSTableItem itemWithTitle:NSLocalizedString(@"Share Public Key", @"") actionBlock:^{ [weakSelf sharePublicKey]; }]]; [section addItem:[OWSTableItem itemWithTitle:NSLocalizedString(@"Show QR Code", @"") actionBlock:^{ [weakSelf showQRCode]; }]]; + [section addItem:[OWSTableItem itemWithTitle:NSLocalizedString(@"Link Device", @"") actionBlock:^{ [weakSelf linkDevice]; }]]; [section addItem:[OWSTableItem itemWithTitle:NSLocalizedString(@"Show Seed", @"") actionBlock:^{ [weakSelf showSeed]; }]]; [section addItem:[OWSTableItem itemWithTitle:NSLocalizedString(@"Clear All Data", @"") actionBlock:^{ [weakSelf clearAllData]; }]]; @@ -511,6 +512,11 @@ [self.navigationController pushViewController:qrCodeVC animated:YES]; } +- (void)linkDevice +{ + +} + - (void)showSeed { NSString *title = NSLocalizedString(@"Your Seed", @""); diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index 354437c05..e9ac60bac 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -2621,3 +2621,4 @@ "Please enter the public key of the person you'd like to message." = "Please enter the public key of the person you'd like to message."; "Loki Messenger is currently in beta. For development purposes the beta version collects basic usage statistics and crash logs. In addition, the beta version doesn't provide full privacy and shouldn't be used to transmit sensitive information." = "Loki Messenger is currently in beta. For development purposes the beta version collects basic usage statistics and crash logs. In addition, the beta version doesn't provide full privacy and shouldn't be used to transmit sensitive information."; "Copy Public Key" = "Copy Public Key"; +"Link Device" = "Link Device"; diff --git a/SignalServiceKit/src/Loki/API/Multi Device/LokiDeviceLink.swift b/SignalServiceKit/src/Loki/API/Multi Device/LokiDeviceLink.swift index c30af47a7..c091ddebf 100644 --- a/SignalServiceKit/src/Loki/API/Multi Device/LokiDeviceLink.swift +++ b/SignalServiceKit/src/Loki/API/Multi Device/LokiDeviceLink.swift @@ -1,75 +1,75 @@ @objc(LKDeviceLink) public final class LokiDeviceLink : NSObject, NSCoding { - public let master: Device - public let slave: Device + @objc public let master: Device + @objc public let slave: Device - public var isAuthorized: Bool { return master.signature != nil } + @objc public var isAuthorized: Bool { return master.signature != nil } // MARK: Types @objc(LKDevice) public final class Device : NSObject, NSCoding { - public let hexEncodedPublicKey: String - public let signature: Data? + @objc public let hexEncodedPublicKey: String + @objc public let signature: Data? - public init(hexEncodedPublicKey: String, signature: Data? = nil) { + @objc public init(hexEncodedPublicKey: String, signature: Data? = nil) { self.hexEncodedPublicKey = hexEncodedPublicKey self.signature = signature } - public init?(coder: NSCoder) { + @objc public init?(coder: NSCoder) { hexEncodedPublicKey = coder.decodeObject(forKey: "hexEncodedPublicKey") as! String signature = coder.decodeObject(forKey: "signature") as! Data? } - public func encode(with coder: NSCoder) { + @objc public func encode(with coder: NSCoder) { coder.encode(hexEncodedPublicKey, forKey: "hexEncodedPublicKey") if let signature = signature { coder.encode(signature, forKey: "signature") } } - public override func isEqual(_ other: Any?) -> Bool { + @objc public override func isEqual(_ other: Any?) -> Bool { guard let other = other as? Device else { return false } return hexEncodedPublicKey == other.hexEncodedPublicKey && signature == other.signature } - override public var hash: Int { // Override NSObject.hash and not Hashable.hashValue or Hashable.hash(into:) + @objc override public var hash: Int { // Override NSObject.hash and not Hashable.hashValue or Hashable.hash(into:) var result = hexEncodedPublicKey.hashValue if let signature = signature { result = result ^ signature.hashValue } return result } - override public var description: String { return hexEncodedPublicKey } + @objc override public var description: String { return hexEncodedPublicKey } } // MARK: Lifecycle - public init(between master: Device, and slave: Device) { + @objc public init(between master: Device, and slave: Device) { self.master = master self.slave = slave } // MARK: Coding - public init?(coder: NSCoder) { + @objc public init?(coder: NSCoder) { master = coder.decodeObject(forKey: "master") as! Device slave = coder.decodeObject(forKey: "slave") as! Device super.init() } - public func encode(with coder: NSCoder) { + @objc public func encode(with coder: NSCoder) { coder.encode(master, forKey: "master") coder.encode(slave, forKey: "slave") } // MARK: Equality - override public func isEqual(_ other: Any?) -> Bool { + @objc override public func isEqual(_ other: Any?) -> Bool { guard let other = other as? LokiDeviceLink else { return false } return master == other.master && slave == other.slave } // MARK: Hashing - override public var hash: Int { // Override NSObject.hash and not Hashable.hashValue or Hashable.hash(into:) + @objc override public var hash: Int { // Override NSObject.hash and not Hashable.hashValue or Hashable.hash(into:) return master.hash ^ slave.hash } // MARK: Description - override public var description: String { return "\(master) - \(slave)" } + @objc override public var description: String { return "\(master) - \(slave)" } } diff --git a/SignalServiceKit/src/Loki/API/Multi Device/LokiDeviceLinkingSession.swift b/SignalServiceKit/src/Loki/API/Multi Device/LokiDeviceLinkingSession.swift index 73f640d21..9b07e10d8 100644 --- a/SignalServiceKit/src/Loki/API/Multi Device/LokiDeviceLinkingSession.swift +++ b/SignalServiceKit/src/Loki/API/Multi Device/LokiDeviceLinkingSession.swift @@ -1,12 +1,13 @@ import PromiseKit +@objc (LKDeviceLinkingSession) final class LokiDeviceLinkingSession : NSObject { private let delegate: LokiDeviceLinkingSessionDelegate private var timer: Timer? - public var isListeningForLinkingRequests = false + @objc public var isListeningForLinkingRequests = false // MARK: Lifecycle - public init(delegate: LokiDeviceLinkingSessionDelegate) { + @objc public init(delegate: LokiDeviceLinkingSessionDelegate) { self.delegate = delegate } @@ -14,7 +15,7 @@ final class LokiDeviceLinkingSession : NSObject { private let listeningTimeout: TimeInterval = 60 // MARK: Public API - public func startListeningForLinkingRequests() { + @objc public func startListeningForLinkingRequests() { isListeningForLinkingRequests = true timer = Timer.scheduledTimer(withTimeInterval: listeningTimeout, repeats: false) { [weak self] timer in guard let self = self else { return } @@ -23,7 +24,7 @@ final class LokiDeviceLinkingSession : NSObject { } } - public func processLinkingRequest(from slaveHexEncodedPublicKey: String, with slaveSignature: Data) { + @objc public func processLinkingRequest(from slaveHexEncodedPublicKey: String, with slaveSignature: Data) { guard isListeningForLinkingRequests else { return } stopListeningForLinkingRequests() let master = LokiDeviceLink.Device(hexEncodedPublicKey: OWSIdentityManager.shared().identityKeyPair()!.hexEncodedPublicKey) @@ -33,11 +34,11 @@ final class LokiDeviceLinkingSession : NSObject { delegate.requestUserAuthorization(for: deviceLink) } - public func authorizeDeviceLink(_ deviceLink: LokiDeviceLink) { + @objc public func authorizeDeviceLink(_ deviceLink: LokiDeviceLink) { // TODO: Send a device link authorized message } - public func stopListeningForLinkingRequests() { + @objc public func stopListeningForLinkingRequests() { timer?.invalidate() timer = nil isListeningForLinkingRequests = false diff --git a/SignalServiceKit/src/Loki/API/Multi Device/LokiDeviceLinkingSessionDelegate.swift b/SignalServiceKit/src/Loki/API/Multi Device/LokiDeviceLinkingSessionDelegate.swift index 23505a973..2c406b61e 100644 --- a/SignalServiceKit/src/Loki/API/Multi Device/LokiDeviceLinkingSessionDelegate.swift +++ b/SignalServiceKit/src/Loki/API/Multi Device/LokiDeviceLinkingSessionDelegate.swift @@ -1,6 +1,7 @@ +@objc(LKDeviceLinkingSessionDelegate) public protocol LokiDeviceLinkingSessionDelegate { - func requestUserAuthorization(for deviceLink: LokiDeviceLink) - func handleDeviceLinkingSessionTimeout() + @objc func requestUserAuthorization(for deviceLink: LokiDeviceLink) + @objc func handleDeviceLinkingSessionTimeout() }