Fix Swift/Obj-C interop

pull/182/head
nielsandriesse 5 years ago
parent 6fca0779e5
commit 2190c98ba1

@ -13,7 +13,7 @@ class FriendRequestProtocolTests : XCTestCase {
override func setUp() { override func setUp() {
super.setUp() super.setUp()
LokiTestUtilities.setupMockEnvironment() LokiTestUtilities.setUpMockEnvironment()
} }
// MARK: - Helpers // MARK: - Helpers

@ -261,8 +261,9 @@ public final class MultiDeviceProtocol : NSObject {
} }
} }
// MARK: - General
@objc public static func isSlaveThread(_ thread: TSThread) -> Bool { @objc public static func isSlaveThread(_ thread: TSThread) -> Bool {
guard let thread = thread as? TSContactThread else { return false; } guard let thread = thread as? TSContactThread else { return false }
var isSlaveThread = false var isSlaveThread = false
Storage.read { transaction in Storage.read { transaction in
isSlaveThread = storage.getMasterHexEncodedPublicKey(for: thread.contactIdentifier(), in: transaction) != nil isSlaveThread = storage.getMasterHexEncodedPublicKey(for: thread.contactIdentifier(), in: transaction) != nil

@ -9,7 +9,7 @@ class SyncMessagesProtocolTests : XCTestCase {
override func setUp() { override func setUp() {
super.setUp() super.setUp()
LokiTestUtilities.setupMockEnvironment() LokiTestUtilities.setUpMockEnvironment()
} }
func testContactSyncMessageHandling() { func testContactSyncMessageHandling() {

@ -2,14 +2,14 @@ import Foundation
import SignalServiceKit import SignalServiceKit
import Curve25519Kit import Curve25519Kit
@objc(LKTestUtilities) enum LokiTestUtilities {
class LokiTestUtilities : NSObject {
@objc public static func setupMockEnvironment() { public static func setUpMockEnvironment() {
// Activate the mock Signal environment
ClearCurrentAppContextForTests() ClearCurrentAppContextForTests()
SetCurrentAppContext(TestAppContext()) SetCurrentAppContext(TestAppContext())
MockSSKEnvironment.activate() MockSSKEnvironment.activate()
// Register a mock user
let identityManager = OWSIdentityManager.shared() let identityManager = OWSIdentityManager.shared()
let seed = Randomness.generateRandomBytes(16)! let seed = Randomness.generateRandomBytes(16)!
let keyPair = Curve25519.generateKeyPair(fromSeed: seed + seed) let keyPair = Curve25519.generateKeyPair(fromSeed: seed + seed)
@ -19,29 +19,25 @@ class LokiTestUtilities : NSObject {
TSAccountManager.sharedInstance().didRegister() TSAccountManager.sharedInstance().didRegister()
} }
@objc public static func generateKeyPair() -> ECKeyPair { public static func generateKeyPair() -> ECKeyPair {
return Curve25519.generateKeyPair() return Curve25519.generateKeyPair()
} }
@objc public static func generateHexEncodedPublicKey() -> String { public static func generateHexEncodedPublicKey() -> String {
return generateKeyPair().hexEncodedPublicKey return generateKeyPair().hexEncodedPublicKey
} }
@objc(getDeviceForHexEncodedPublicKey:)
public static func getDevice(for hexEncodedPublicKey: String) -> DeviceLink.Device? { public static func getDevice(for hexEncodedPublicKey: String) -> DeviceLink.Device? {
guard let signature = Data.getSecureRandomData(ofSize: 64) else { return nil } guard let signature = Data.getSecureRandomData(ofSize: 64) else { return nil }
return DeviceLink.Device(hexEncodedPublicKey: hexEncodedPublicKey, signature: signature) return DeviceLink.Device(hexEncodedPublicKey: hexEncodedPublicKey, signature: signature)
} }
@objc(createContactThreadForHexEncodedPublicKey:)
public static func createContactThread(for hexEncodedPublicKey: String) -> TSContactThread { public static func createContactThread(for hexEncodedPublicKey: String) -> TSContactThread {
return TSContactThread.getOrCreateThread(contactId: hexEncodedPublicKey) return TSContactThread.getOrCreateThread(contactId: hexEncodedPublicKey)
} }
@objc(createGroupThreadWithGroupType:)
public static func createGroupThread(groupType: GroupType) -> TSGroupThread? { public static func createGroupThread(groupType: GroupType) -> TSGroupThread? {
let hexEncodedGroupID = Randomness.generateRandomBytes(kGroupIdLength)!.toHexString() let hexEncodedGroupID = Randomness.generateRandomBytes(kGroupIdLength)!.toHexString()
let groupID: Data let groupID: Data
switch groupType { switch groupType {
case .closedGroup: groupID = LKGroupUtilities.getEncodedClosedGroupIDAsData(hexEncodedGroupID) case .closedGroup: groupID = LKGroupUtilities.getEncodedClosedGroupIDAsData(hexEncodedGroupID)
@ -49,7 +45,6 @@ class LokiTestUtilities : NSObject {
case .rssFeed: groupID = LKGroupUtilities.getEncodedRSSFeedIDAsData(hexEncodedGroupID) case .rssFeed: groupID = LKGroupUtilities.getEncodedRSSFeedIDAsData(hexEncodedGroupID)
default: return nil default: return nil
} }
return TSGroupThread.getOrCreateThread(withGroupId: groupID, groupType: groupType) return TSGroupThread.getOrCreateThread(withGroupId: groupID, groupType: groupType)
} }
} }
Loading…
Cancel
Save