CR: rename classes, no functional changes

pull/1/head
Michael Kirk 7 years ago
parent 9f35b93647
commit cb55ba57f5

@ -1 +1 @@
Subproject commit 986d4fdcea0e72cfaab54b08918234a61c9824fd Subproject commit 31f649e593f0d868b514b7aec865f31e7027c364

@ -8,26 +8,27 @@ import PromiseKit
// TODO define actual type, and validate length // TODO define actual type, and validate length
public typealias IdentityKey = Data public typealias IdentityKey = Data
@objc(SSKAccountManager) /// based on libsignal-service-java's AccountManager class
public class AccountManager: NSObject { @objc(SSKAccountServiceClient)
public class AccountServiceClient: NSObject {
static var shared = AccountManager() static var shared = AccountServiceClient()
private let serviceSocket: ServiceSocket private let serviceClient: SignalServiceClient
override init() { override init() {
self.serviceSocket = ServiceRestSocket() self.serviceClient = SignalServiceRestClient()
} }
public func getPreKeysCount() -> Promise<Int> { public func getPreKeysCount() -> Promise<Int> {
return serviceSocket.getAvailablePreKeys() return serviceClient.getAvailablePreKeys()
} }
public func setPreKeys(identityKey: IdentityKey, signedPreKeyRecord: SignedPreKeyRecord, preKeyRecords: [PreKeyRecord]) -> Promise<Void> { public func setPreKeys(identityKey: IdentityKey, signedPreKeyRecord: SignedPreKeyRecord, preKeyRecords: [PreKeyRecord]) -> Promise<Void> {
return serviceSocket.registerPreKeys(identityKey: identityKey, signedPreKeyRecord: signedPreKeyRecord, preKeyRecords: preKeyRecords) return serviceClient.registerPreKeys(identityKey: identityKey, signedPreKeyRecord: signedPreKeyRecord, preKeyRecords: preKeyRecords)
} }
public func setSignedPreKey(_ signedPreKey: SignedPreKeyRecord) -> Promise<Void> { public func setSignedPreKey(_ signedPreKey: SignedPreKeyRecord) -> Promise<Void> {
return serviceSocket.setCurrentSignedPreKey(signedPreKey) return serviceClient.setCurrentSignedPreKey(signedPreKey)
} }
} }

@ -7,9 +7,11 @@ import PromiseKit
@objc(SSKCreatePreKeysOperation) @objc(SSKCreatePreKeysOperation)
public class CreatePreKeysOperation: OWSOperation { public class CreatePreKeysOperation: OWSOperation {
private var accountManager: AccountManager {
return AccountManager.shared private var accountServiceClient: AccountServiceClient {
return AccountServiceClient.shared
} }
private var primaryStorage: OWSPrimaryStorage { private var primaryStorage: OWSPrimaryStorage {
return OWSPrimaryStorage.shared() return OWSPrimaryStorage.shared()
} }
@ -32,7 +34,7 @@ public class CreatePreKeysOperation: OWSOperation {
self.primaryStorage.storeSignedPreKey(signedPreKeyRecord.id, signedPreKeyRecord: signedPreKeyRecord) self.primaryStorage.storeSignedPreKey(signedPreKeyRecord.id, signedPreKeyRecord: signedPreKeyRecord)
self.primaryStorage.storePreKeyRecords(preKeyRecords) self.primaryStorage.storePreKeyRecords(preKeyRecords)
return self.accountManager.setPreKeys(identityKey: identityKey, signedPreKeyRecord: signedPreKeyRecord, preKeyRecords: preKeyRecords) return self.accountServiceClient.setPreKeys(identityKey: identityKey, signedPreKeyRecord: signedPreKeyRecord, preKeyRecords: preKeyRecords)
}.then { () -> Void in }.then { () -> Void in
signedPreKeyRecord.markAsAcceptedByService() signedPreKeyRecord.markAsAcceptedByService()
self.primaryStorage.setCurrentSignedPrekeyId(signedPreKeyRecord.id) self.primaryStorage.setCurrentSignedPrekeyId(signedPreKeyRecord.id)

@ -16,8 +16,8 @@ public class RefreshPreKeysOperation: OWSOperation {
return TSAccountManager.sharedInstance() return TSAccountManager.sharedInstance()
} }
private var accountManager: AccountManager { private var accountServiceClient: AccountServiceClient {
return AccountManager.shared return AccountServiceClient.shared
} }
private var primaryStorage: OWSPrimaryStorage { private var primaryStorage: OWSPrimaryStorage {
@ -37,7 +37,7 @@ public class RefreshPreKeysOperation: OWSOperation {
} }
firstly { firstly {
self.accountManager.getPreKeysCount() self.accountServiceClient.getPreKeysCount()
}.then(on: DispatchQueue.global()) { preKeysCount -> Promise<Void> in }.then(on: DispatchQueue.global()) { preKeysCount -> Promise<Void> in
Logger.debug("preKeysCount: \(preKeysCount)") Logger.debug("preKeysCount: \(preKeysCount)")
guard preKeysCount < kEphemeralPreKeysMinimumCount || self.primaryStorage.currentSignedPrekeyId() == nil else { guard preKeysCount < kEphemeralPreKeysMinimumCount || self.primaryStorage.currentSignedPrekeyId() == nil else {
@ -52,7 +52,7 @@ public class RefreshPreKeysOperation: OWSOperation {
self.primaryStorage.storeSignedPreKey(signedPreKeyRecord.id, signedPreKeyRecord: signedPreKeyRecord) self.primaryStorage.storeSignedPreKey(signedPreKeyRecord.id, signedPreKeyRecord: signedPreKeyRecord)
self.primaryStorage.storePreKeyRecords(preKeyRecords) self.primaryStorage.storePreKeyRecords(preKeyRecords)
return self.accountManager.setPreKeys(identityKey: identityKey, signedPreKeyRecord: signedPreKeyRecord, preKeyRecords: preKeyRecords).then { () -> Void in return self.accountServiceClient.setPreKeys(identityKey: identityKey, signedPreKeyRecord: signedPreKeyRecord, preKeyRecords: preKeyRecords).then { () -> Void in
signedPreKeyRecord.markAsAcceptedByService() signedPreKeyRecord.markAsAcceptedByService()
self.primaryStorage.setCurrentSignedPrekeyId(signedPreKeyRecord.id) self.primaryStorage.setCurrentSignedPrekeyId(signedPreKeyRecord.id)

@ -11,8 +11,8 @@ public class RotateSignedPreKeyOperation: OWSOperation {
return TSAccountManager.sharedInstance() return TSAccountManager.sharedInstance()
} }
private var accountManager: AccountManager { private var accountServiceClient: AccountServiceClient {
return AccountManager.shared return AccountServiceClient.shared
} }
private var primaryStorage: OWSPrimaryStorage { private var primaryStorage: OWSPrimaryStorage {
@ -31,7 +31,7 @@ public class RotateSignedPreKeyOperation: OWSOperation {
firstly { firstly {
self.primaryStorage.storeSignedPreKey(signedPreKeyRecord.id, signedPreKeyRecord: signedPreKeyRecord) self.primaryStorage.storeSignedPreKey(signedPreKeyRecord.id, signedPreKeyRecord: signedPreKeyRecord)
return self.accountManager.setSignedPreKey(signedPreKeyRecord) return self.accountServiceClient.setSignedPreKey(signedPreKeyRecord)
}.then(on: DispatchQueue.global()) { () -> Void in }.then(on: DispatchQueue.global()) { () -> Void in
Logger.info("Successfully uploaded signed PreKey") Logger.info("Successfully uploaded signed PreKey")
signedPreKeyRecord.markAsAcceptedByService() signedPreKeyRecord.markAsAcceptedByService()

@ -5,13 +5,14 @@
import Foundation import Foundation
import PromiseKit import PromiseKit
protocol ServiceSocket { protocol SignalServiceClient {
func getAvailablePreKeys() -> Promise<Int> func getAvailablePreKeys() -> Promise<Int>
func registerPreKeys(identityKey: IdentityKey, signedPreKeyRecord: SignedPreKeyRecord, preKeyRecords: [PreKeyRecord]) -> Promise<Void> func registerPreKeys(identityKey: IdentityKey, signedPreKeyRecord: SignedPreKeyRecord, preKeyRecords: [PreKeyRecord]) -> Promise<Void>
func setCurrentSignedPreKey(_ signedPreKey: SignedPreKeyRecord) -> Promise<Void> func setCurrentSignedPreKey(_ signedPreKey: SignedPreKeyRecord) -> Promise<Void>
} }
class ServiceRestSocket: ServiceSocket { /// Based on libsignal-service-java's PushServiceSocket class
class SignalServiceRestClient: SignalServiceClient {
var networkManager: TSNetworkManager { var networkManager: TSNetworkManager {
return TSNetworkManager.shared() return TSNetworkManager.shared()
Loading…
Cancel
Save