Fix inconsistent file prefixes

This commit is contained in:
Niels Andriesse 2019-09-24 11:18:14 +10:00
parent b56d083e6a
commit f230ac7d42
8 changed files with 38 additions and 38 deletions

View File

@ -1,8 +1,8 @@
import NVActivityIndicatorView
@objc(LKDeviceLinkingModal)
final class DeviceLinkingModal : Modal, LokiDeviceLinkingSessionDelegate {
private var deviceLink: LokiDeviceLink?
final class DeviceLinkingModal : Modal, DeviceLinkingSessionDelegate {
private var deviceLink: DeviceLink?
// MARK: Components
private lazy var topSpacer = UIView.spacer(withHeight: 8)
@ -51,7 +51,7 @@ final class DeviceLinkingModal : Modal, LokiDeviceLinkingSessionDelegate {
// MARK: Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
let _ = LokiDeviceLinkingSession.startListeningForLinkingRequests(with: self)
let _ = DeviceLinkingSession.startListeningForLinkingRequests(with: self)
}
override func populateContentView() {
@ -76,7 +76,7 @@ final class DeviceLinkingModal : Modal, LokiDeviceLinkingSessionDelegate {
}
// MARK: Device Linking
func requestUserAuthorization(for deviceLink: LokiDeviceLink) {
func requestUserAuthorization(for deviceLink: DeviceLink) {
self.deviceLink = deviceLink
self.topSpacer.isHidden = true
self.spinner.stopAnimating()
@ -89,7 +89,7 @@ final class DeviceLinkingModal : Modal, LokiDeviceLinkingSessionDelegate {
@objc private func authorizeDeviceLink() {
let deviceLink = self.deviceLink!
let session = LokiDeviceLinkingSession.current!
let session = DeviceLinkingSession.current!
session.authorizeDeviceLink(deviceLink)
session.stopListeningForLinkingRequests()
dismiss(animated: true, completion: nil)

View File

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

View File

@ -1,6 +1,6 @@
@objc(LKDeviceLink)
public final class LokiDeviceLink : NSObject, NSCoding {
public final class DeviceLink : NSObject, NSCoding {
@objc public let master: Device
@objc public let slave: Device
@ -61,7 +61,7 @@ public final class LokiDeviceLink : NSObject, NSCoding {
// MARK: Equality
@objc override public func isEqual(_ other: Any?) -> Bool {
guard let other = other as? LokiDeviceLink else { return false }
guard let other = other as? DeviceLink else { return false }
return master == other.master && slave == other.slave
}

View File

@ -2,46 +2,46 @@ import Curve25519Kit
import PromiseKit
@objc (LKDeviceLinkingSession)
public final class LokiDeviceLinkingSession : NSObject {
private let delegate: LokiDeviceLinkingSessionDelegate
public final class DeviceLinkingSession : NSObject {
private let delegate: DeviceLinkingSessionDelegate
@objc public var isListeningForLinkingRequests = false
// MARK: Lifecycle
@objc public static var current: LokiDeviceLinkingSession?
@objc public static var current: DeviceLinkingSession?
private init(delegate: LokiDeviceLinkingSessionDelegate) {
private init(delegate: DeviceLinkingSessionDelegate) {
self.delegate = delegate
}
// MARK: Public API
public static func startListeningForLinkingRequests(with delegate: LokiDeviceLinkingSessionDelegate) -> LokiDeviceLinkingSession {
let session = LokiDeviceLinkingSession(delegate: delegate)
public static func startListeningForLinkingRequests(with delegate: DeviceLinkingSessionDelegate) -> DeviceLinkingSession {
let session = DeviceLinkingSession(delegate: delegate)
session.isListeningForLinkingRequests = true
LokiDeviceLinkingSession.current = session
DeviceLinkingSession.current = session
return session
}
@objc public func processLinkingRequest(from slaveHexEncodedPublicKey: String, with slaveSignature: Data) {
guard isListeningForLinkingRequests else { return }
stopListeningForLinkingRequests()
let master = LokiDeviceLink.Device(hexEncodedPublicKey: OWSIdentityManager.shared().identityKeyPair()!.hexEncodedPublicKey)
let slave = LokiDeviceLink.Device(hexEncodedPublicKey: slaveHexEncodedPublicKey, signature: slaveSignature)
let deviceLink = LokiDeviceLink(between: master, and: slave)
let master = DeviceLink.Device(hexEncodedPublicKey: OWSIdentityManager.shared().identityKeyPair()!.hexEncodedPublicKey)
let slave = DeviceLink.Device(hexEncodedPublicKey: slaveHexEncodedPublicKey, signature: slaveSignature)
let deviceLink = DeviceLink(between: master, and: slave)
guard isValidLinkingRequest(deviceLink) else { return }
delegate.requestUserAuthorization(for: deviceLink)
}
public func stopListeningForLinkingRequests() {
LokiDeviceLinkingSession.current = nil
DeviceLinkingSession.current = nil
isListeningForLinkingRequests = false
}
public func authorizeDeviceLink(_ deviceLink: LokiDeviceLink) {
public func authorizeDeviceLink(_ deviceLink: DeviceLink) {
// TODO: Send a device link authorized message
}
// MARK: Private API
private func isValidLinkingRequest(_ deviceLink: LokiDeviceLink) -> Bool {
private func isValidLinkingRequest(_ deviceLink: DeviceLink) -> Bool {
// When requesting a device link, the slave device signs the master device's public key. When authorizing
// a device link, the master device signs the slave device's public key.
let slaveSignature = deviceLink.slave.signature!

View File

@ -0,0 +1,6 @@
@objc(LKDeviceLinkingSessionDelegate)
public protocol DeviceLinkingSessionDelegate {
@objc func requestUserAuthorization(for deviceLink: DeviceLink)
}

View File

@ -1,6 +0,0 @@
@objc(LKDeviceLinkingSessionDelegate)
public protocol LokiDeviceLinkingSessionDelegate {
@objc func requestUserAuthorization(for deviceLink: LokiDeviceLink)
}

View File

@ -14,7 +14,7 @@ public final class DeviceLinkIndex : NSObject {
setup.addColumn(slaveHexEncodedPublicKey, with: .text)
setup.addColumn(isAuthorized, with: .integer)
let handler = YapDatabaseSecondaryIndexHandler.withObjectBlock { _, map, _, _, object in
guard let deviceLink = object as? LokiDeviceLink else { return }
guard let deviceLink = object as? DeviceLink else { return }
map[masterHexEncodedPublicKey] = deviceLink.master.hexEncodedPublicKey
map[slaveHexEncodedPublicKey] = deviceLink.slave.hexEncodedPublicKey
map[isAuthorized] = deviceLink.isAuthorized
@ -28,14 +28,14 @@ public final class DeviceLinkIndex : NSObject {
storage.asyncRegister(indexDatabaseExtension, withName: name)
}
@objc public static func getDeviceLinks(for query: YapDatabaseQuery, in transaction: YapDatabaseReadTransaction) -> [LokiDeviceLink] {
@objc public static func getDeviceLinks(for query: YapDatabaseQuery, in transaction: YapDatabaseReadTransaction) -> [DeviceLink] {
guard let ext = transaction.ext(DeviceLinkIndex.name) as? YapDatabaseSecondaryIndexTransaction else {
print("[Loki] Couldn't get device link index database extension.")
return []
}
var result: [LokiDeviceLink] = []
var result: [DeviceLink] = []
ext.enumerateKeysAndObjects(matching: query) { _, _, object, _ in
guard let deviceLink = object as? LokiDeviceLink else { return }
guard let deviceLink = object as? DeviceLink else { return }
result.append(deviceLink)
}
return result

View File

@ -5,22 +5,22 @@ extension OWSPrimaryStorage {
return "LokiDeviceLinkCollection-\(primaryDevice)"
}
public func storeDeviceLink(_ deviceLink: LokiDeviceLink, in transaction: YapDatabaseReadWriteTransaction) {
public func storeDeviceLink(_ deviceLink: DeviceLink, in transaction: YapDatabaseReadWriteTransaction) {
let collection = getCollection(for: deviceLink.master.hexEncodedPublicKey)
transaction.setObject(deviceLink, forKey: deviceLink.slave.hexEncodedPublicKey, inCollection: collection)
}
public func getDeviceLinks(for masterHexEncodedPublicKey: String, in transaction: YapDatabaseReadTransaction) -> [LokiDeviceLink] {
public func getDeviceLinks(for masterHexEncodedPublicKey: String, in transaction: YapDatabaseReadTransaction) -> [DeviceLink] {
let collection = getCollection(for: masterHexEncodedPublicKey)
var result: [LokiDeviceLink] = []
var result: [DeviceLink] = []
transaction.enumerateRows(inCollection: collection) { _, object, _, _ in
guard let deviceLink = object as? LokiDeviceLink else { return }
guard let deviceLink = object as? DeviceLink else { return }
result.append(deviceLink)
}
return result
}
public func getDeviceLink(for slaveHexEncodedPublicKey: String, in transaction: YapDatabaseReadTransaction) -> LokiDeviceLink? {
public func getDeviceLink(for slaveHexEncodedPublicKey: String, in transaction: YapDatabaseReadTransaction) -> DeviceLink? {
let query = YapDatabaseQuery(string: "WHERE \(DeviceLinkIndex.slaveHexEncodedPublicKey) = ?", parameters: [ slaveHexEncodedPublicKey ])
let deviceLinks = DeviceLinkIndex.getDeviceLinks(for: query, in: transaction)
guard deviceLinks.count <= 1 else {