Whitelist sender key requests for websocket.
This commit is contained in:
parent
01aa5ba8ba
commit
976fbace2e
@ -211,6 +211,7 @@ class StubbableNetworkManager: NetworkManager {
|
||||
}
|
||||
|
||||
public override func makePromise(request: TSRequest,
|
||||
websocketSupportsRequest: Bool = false,
|
||||
remainingRetryCount: Int = 0) -> Promise<HTTPResponse> {
|
||||
Logger.info("Ignoring request: \(request)")
|
||||
|
||||
|
||||
@ -586,7 +586,14 @@ extension MessageSender {
|
||||
timestamp: timestamp,
|
||||
isOnline: isOnline)
|
||||
|
||||
return networkManager.makePromise(request: request)
|
||||
// If we can use the websocket, try that and fail over to REST.
|
||||
// If not, go straight to REST.
|
||||
let remainingRetryCount: Int = (OWSWebSocket.canAppUseSocketsToMakeRequests
|
||||
? 1
|
||||
: 0)
|
||||
return networkManager.makePromise(request: request,
|
||||
websocketSupportsRequest: true,
|
||||
remainingRetryCount: remainingRetryCount)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -18,11 +18,17 @@ public class NetworkManager: NSObject {
|
||||
|
||||
// This method can be called from any thread.
|
||||
public func makePromise(request: TSRequest,
|
||||
websocketSupportsRequest: Bool = false,
|
||||
remainingRetryCount: Int = 0) -> Promise<HTTPResponse> {
|
||||
firstly {
|
||||
FeatureFlags.deprecateREST
|
||||
? websocketRequestPromise(request: request)
|
||||
: restRequestPromise(request: request)
|
||||
firstly { () -> Promise<HTTPResponse> in
|
||||
// Fail over to REST if websocket attempt fails.
|
||||
if remainingRetryCount > 0,
|
||||
OWSWebSocket.canAppUseSocketsToMakeRequests,
|
||||
websocketSupportsRequest {
|
||||
return websocketRequestPromise(request: request)
|
||||
} else {
|
||||
return restRequestPromise(request: request)
|
||||
}
|
||||
}.recover(on: .global()) { error -> Promise<HTTPResponse> in
|
||||
if error.isRetryable,
|
||||
remainingRetryCount > 0 {
|
||||
@ -67,7 +73,9 @@ public class NetworkManager: NSObject {
|
||||
@objc
|
||||
public class OWSFakeNetworkManager: NetworkManager {
|
||||
|
||||
public override func makePromise(request: TSRequest, remainingRetryCount: Int = 0) -> Promise<HTTPResponse> {
|
||||
public override func makePromise(request: TSRequest,
|
||||
websocketSupportsRequest: Bool = false,
|
||||
remainingRetryCount: Int = 0) -> Promise<HTTPResponse> {
|
||||
Logger.info("Ignoring request: \(request)")
|
||||
// Never resolve.
|
||||
let (promise, _) = Promise<HTTPResponse>.pending()
|
||||
|
||||
@ -638,6 +638,20 @@ public class OWSWebSocket: NSObject {
|
||||
|
||||
// MARK: - Socket LifeCycle
|
||||
|
||||
public static var canAppUseSocketsToMakeRequests: Bool {
|
||||
if signalService.isCensorshipCircumventionActive {
|
||||
return false
|
||||
} else if CurrentAppContext().isMainApp {
|
||||
return true
|
||||
} else if FeatureFlags.deprecateREST {
|
||||
// When we deprecated REST, we _do_ want to open
|
||||
// both websockets in the app extensions.
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// This method is thread-safe.
|
||||
public var shouldSocketBeOpen: Bool {
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user