Implement device linking message receiving
This commit is contained in:
parent
8bdcbc6e40
commit
c05c12c7d2
|
@ -5,10 +5,6 @@ import NVActivityIndicatorView
|
|||
@objc(LKDeviceLinkingModal)
|
||||
final class DeviceLinkingModal : UIViewController, LokiDeviceLinkingSessionDelegate {
|
||||
|
||||
private lazy var deviceLinkingSession: LokiDeviceLinkingSession = {
|
||||
return LokiDeviceLinkingSession(delegate: self)
|
||||
}()
|
||||
|
||||
// MARK: Components
|
||||
private lazy var contentView: UIView = {
|
||||
let result = UIView()
|
||||
|
@ -55,7 +51,7 @@ final class DeviceLinkingModal : UIViewController, LokiDeviceLinkingSessionDeleg
|
|||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
setUpViewHierarchy()
|
||||
deviceLinkingSession.startListeningForLinkingRequests()
|
||||
LokiDeviceLinkingSession.startListeningForLinkingRequests(with: self)
|
||||
}
|
||||
|
||||
private func setUpViewHierarchy() {
|
||||
|
@ -109,7 +105,7 @@ final class DeviceLinkingModal : UIViewController, LokiDeviceLinkingSessionDeleg
|
|||
}
|
||||
|
||||
@objc private func cancel() {
|
||||
deviceLinkingSession.stopListeningForLinkingRequests()
|
||||
LokiDeviceLinkingSession.current?.stopListeningForLinkingRequests()
|
||||
dismiss(animated: true, completion: nil)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,13 +6,18 @@ public final class LokiDeviceLinkingSession : NSObject {
|
|||
@objc public var isListeningForLinkingRequests = false
|
||||
|
||||
// MARK: Lifecycle
|
||||
@objc public init(delegate: LokiDeviceLinkingSessionDelegate) {
|
||||
@objc public static var current: LokiDeviceLinkingSession?
|
||||
|
||||
private init(delegate: LokiDeviceLinkingSessionDelegate) {
|
||||
self.delegate = delegate
|
||||
}
|
||||
|
||||
// MARK: Public API
|
||||
@objc public func startListeningForLinkingRequests() {
|
||||
isListeningForLinkingRequests = true
|
||||
public static func startListeningForLinkingRequests(with delegate: LokiDeviceLinkingSessionDelegate) -> LokiDeviceLinkingSession {
|
||||
let session = LokiDeviceLinkingSession(delegate: delegate)
|
||||
session.isListeningForLinkingRequests = true
|
||||
LokiDeviceLinkingSession.current = session
|
||||
return session
|
||||
}
|
||||
|
||||
@objc public func processLinkingRequest(from slaveHexEncodedPublicKey: String, with slaveSignature: Data) {
|
||||
|
@ -25,11 +30,12 @@ public final class LokiDeviceLinkingSession : NSObject {
|
|||
delegate.requestUserAuthorization(for: deviceLink)
|
||||
}
|
||||
|
||||
@objc public func stopListeningForLinkingRequests() {
|
||||
public func stopListeningForLinkingRequests() {
|
||||
LokiDeviceLinkingSession.current = nil
|
||||
isListeningForLinkingRequests = false
|
||||
}
|
||||
|
||||
@objc public func authorizeDeviceLink(_ deviceLink: LokiDeviceLink) {
|
||||
public func authorizeDeviceLink(_ deviceLink: LokiDeviceLink) {
|
||||
// TODO: Send a device link authorized message
|
||||
}
|
||||
|
||||
|
|
|
@ -417,7 +417,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
// Loki: Handle friend request acceptance if needed
|
||||
// TODO: We'll need to fix this up if we ever start using sync messages
|
||||
[self handleFriendRequestAcceptanceIfNeededWithEnvelope:envelope transaction:transaction];
|
||||
|
||||
|
||||
if (envelope.content != nil) {
|
||||
NSError *error;
|
||||
SSKProtoContent *_Nullable contentProto = [SSKProtoContent parseData:plaintextData error:&error];
|
||||
|
@ -427,17 +427,27 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
}
|
||||
OWSLogInfo(@"handling content: <Content: %@>", [self descriptionForContent:contentProto]);
|
||||
|
||||
// Loki: Handle device linking message
|
||||
if (contentProto.lokiDeviceLinkingMessage != nil) {
|
||||
OWSLogInfo(@"[Loki] Received a device linking request from: %@", envelope.source);
|
||||
NSData *signature = [contentProto.lokiDeviceLinkingMessage.slaveSignature];
|
||||
if (signature == nil) {
|
||||
OWSFailDebug(@"Received a device linking request without an attached slave signature.");
|
||||
}
|
||||
[LKDeviceLinkingSession.current processLinkingRequestFrom:envelope.source with:signature];
|
||||
}
|
||||
|
||||
// Loki: Handle pre key bundle message
|
||||
if (contentProto.prekeyBundleMessage) {
|
||||
OWSLogInfo(@"Received a pre key bundle message from: %@.", envelope.source);
|
||||
OWSLogInfo(@"[Loki] Received a pre key bundle message from: %@.", envelope.source);
|
||||
PreKeyBundle *_Nullable bundle = [contentProto.prekeyBundleMessage createPreKeyBundleWithTransaction:transaction];
|
||||
if (!bundle) {
|
||||
OWSFailDebug(@"Failed to create PreKeyBundle from message.");
|
||||
OWSFailDebug(@"Failed to create a pre key bundle.");
|
||||
}
|
||||
[self.primaryStorage setPreKeyBundle:bundle forContact:envelope.source transaction:transaction];
|
||||
}
|
||||
|
||||
// Loki: Check if we got p2p address
|
||||
// Loki: Check if we got a P2P address
|
||||
if (contentProto.lokiAddressMessage) {
|
||||
NSString *address = contentProto.lokiAddressMessage.ptpAddress;
|
||||
uint32_t port = contentProto.lokiAddressMessage.ptpPort;
|
||||
|
@ -1572,6 +1582,10 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
}
|
||||
}
|
||||
|
||||
- (void)handleDeviceLinkingMessageIfNeeded:(TSIncomingMessage *)message transaction:(YapDatabaseReadWriteTransaction *)transaction {
|
||||
|
||||
}
|
||||
|
||||
- (void)finalizeIncomingMessage:(TSIncomingMessage *)incomingMessage
|
||||
thread:(TSThread *)thread
|
||||
envelope:(SSKProtoEnvelope *)envelope
|
||||
|
|
Loading…
Reference in New Issue