Put feature flags in one place
This commit is contained in:
parent
f7613e09bf
commit
e9df213bfe
|
@ -227,6 +227,7 @@
|
|||
B8783E9E23EB948D00404FB8 /* UILabel+Interaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8783E9D23EB948D00404FB8 /* UILabel+Interaction.swift */; };
|
||||
B879D449247E1BE300DB3608 /* PathVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B879D448247E1BE300DB3608 /* PathVC.swift */; };
|
||||
B87EF17126367CF800124B3C /* FileServerAPIV2.swift in Sources */ = {isa = PBXBuildFile; fileRef = B87EF17026367CF800124B3C /* FileServerAPIV2.swift */; };
|
||||
B87EF18126377A1D00124B3C /* Features.swift in Sources */ = {isa = PBXBuildFile; fileRef = B87EF18026377A1D00124B3C /* Features.swift */; };
|
||||
B8856CA8256F0F42001CE70E /* OWSBackupFragment.m in Sources */ = {isa = PBXBuildFile; fileRef = C33FDB07255A580700E217F9 /* OWSBackupFragment.m */; };
|
||||
B8856CB1256F0F47001CE70E /* OWSBackupFragment.h in Headers */ = {isa = PBXBuildFile; fileRef = C33FDAEA255A580500E217F9 /* OWSBackupFragment.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
B8856CEE256F1054001CE70E /* OWSAudioPlayer.m in Sources */ = {isa = PBXBuildFile; fileRef = C38EF2F7255B6DBC007E1867 /* OWSAudioPlayer.m */; };
|
||||
|
@ -1249,6 +1250,7 @@
|
|||
B879D448247E1BE300DB3608 /* PathVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PathVC.swift; sourceTree = "<group>"; };
|
||||
B879D44A247E1D9200DB3608 /* PathStatusView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PathStatusView.swift; sourceTree = "<group>"; };
|
||||
B87EF17026367CF800124B3C /* FileServerAPIV2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileServerAPIV2.swift; sourceTree = "<group>"; };
|
||||
B87EF18026377A1D00124B3C /* Features.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Features.swift; sourceTree = "<group>"; };
|
||||
B8856D5F256F129B001CE70E /* OWSAlerts.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OWSAlerts.swift; sourceTree = "<group>"; };
|
||||
B885D5F52334A32100EE0D8E /* UIView+Constraints.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Constraints.swift"; sourceTree = "<group>"; };
|
||||
B886B4A62398B23E00211ABE /* QRCodeVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QRCodeVC.swift; sourceTree = "<group>"; };
|
||||
|
@ -2354,6 +2356,7 @@
|
|||
B8F5F58225EC94A6003BF8D4 /* Collection+Subscripting.swift */,
|
||||
B8AE75A325A6C6A6001A84D2 /* Data+Trimming.swift */,
|
||||
C3C2A5D52553860A00C340D1 /* Dictionary+Description.swift */,
|
||||
B87EF18026377A1D00124B3C /* Features.swift */,
|
||||
B8BC00BF257D90E30032E807 /* General.swift */,
|
||||
C3C2A5CE2553860700C340D1 /* Logging.swift */,
|
||||
C33FDAFD255A580600E217F9 /* LRUCache.swift */,
|
||||
|
@ -4775,6 +4778,7 @@
|
|||
C3BBE0A92554D4DE0050F1E3 /* HTTP.swift in Sources */,
|
||||
B8856D23256F116B001CE70E /* Weak.swift in Sources */,
|
||||
C32C5A48256DB8F0003C73A2 /* BuildConfiguration.swift in Sources */,
|
||||
B87EF18126377A1D00124B3C /* Features.swift in Sources */,
|
||||
C300A60D2554B31900555489 /* Logging.swift in Sources */,
|
||||
B8FF8EA625C11FEF004D1F22 /* IPv4.swift in Sources */,
|
||||
C3D9E35525675EE10040E4F3 /* MIMETypeUtil.m in Sources */,
|
||||
|
|
|
@ -154,7 +154,7 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv
|
|||
let _ = IP2Country.shared.populateCacheIfNeeded()
|
||||
}
|
||||
// Get default open group rooms if needed
|
||||
if OpenGroupManagerV2.useV2OpenGroups {
|
||||
if Features.useV2OpenGroups {
|
||||
OpenGroupAPIV2.getDefaultRoomsIfNeeded()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -400,7 +400,7 @@ static NSTimeInterval launchStartedAt;
|
|||
NSUserDefaults *userDefaults = NSUserDefaults.standardUserDefaults;
|
||||
NSDate *now = [NSDate new];
|
||||
NSDate *lastProfilePictureUpload = (NSDate *)[userDefaults objectForKey:@"lastProfilePictureUpload"];
|
||||
if (lastProfilePictureUpload != nil && [now timeIntervalSinceDate:lastProfilePictureUpload] > 4 * 24 * 60 * 60) {
|
||||
if (lastProfilePictureUpload != nil && [now timeIntervalSinceDate:lastProfilePictureUpload] > 14 * 24 * 60 * 60) {
|
||||
OWSProfileManager *profileManager = OWSProfileManager.sharedManager;
|
||||
NSString *name = [[LKStorage.shared getUser] name];
|
||||
UIImage *profilePicture = [profileManager profileAvatarForRecipientId:userPublicKey];
|
||||
|
@ -411,7 +411,7 @@ static NSTimeInterval launchStartedAt;
|
|||
} requiresSync:YES];
|
||||
}
|
||||
|
||||
if (CurrentAppContext().isMainApp && SNOpenGroupManagerV2.useV2OpenGroups) {
|
||||
if (CurrentAppContext().isMainApp && SNFeatures.useV2OpenGroups) {
|
||||
[SNOpenGroupAPIV2 getDefaultRoomsIfNeeded];
|
||||
}
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@ final class JoinOpenGroupVC : BaseVC, UIPageViewControllerDataSource, UIPageView
|
|||
// A V2 open group URL will look like: <optional scheme> + <host> + <optional port> + <room> + <public key>
|
||||
// The host doesn't parse if no explicit scheme is provided
|
||||
if let url = URL(string: string), let host = url.host ?? given(string.split(separator: "/").first, { String($0) }) {
|
||||
if let (room, server, publicKey) = OpenGroupManagerV2.parseV2OpenGroup(from: string), OpenGroupManagerV2.useV2OpenGroups {
|
||||
if let (room, server, publicKey) = OpenGroupManagerV2.parseV2OpenGroup(from: string), Features.useV2OpenGroups {
|
||||
joinV2OpenGroup(room: room, server: server, publicKey: publicKey)
|
||||
} else {
|
||||
// Inputs that should work:
|
||||
|
@ -243,7 +243,7 @@ private final class EnterURLVC : UIViewController, UIGestureRecognizerDelegate,
|
|||
nextButtonContainer.pin(.bottom, to: .bottom, of: nextButton)
|
||||
// Stack view
|
||||
let stackView: UIStackView
|
||||
if OpenGroupManagerV2.useV2OpenGroups {
|
||||
if Features.useV2OpenGroups {
|
||||
stackView = UIStackView(arrangedSubviews: [ urlTextField, UIView.spacer(withHeight: Values.mediumSpacing), suggestionGridTitleLabel,
|
||||
UIView.spacer(withHeight: Values.mediumSpacing), suggestionGrid, UIView.vStretchingSpacer(), nextButtonContainer ])
|
||||
} else {
|
||||
|
|
|
@ -6,7 +6,6 @@ public final class FileServerAPIV2 : NSObject {
|
|||
|
||||
@objc public static let server = "http://88.99.175.227"
|
||||
public static let serverPublicKey = "7cb31905b55cd5580c686911debf672577b3fb0bff81df4ce2d5c4cb3a7aaa69"
|
||||
@objc public static let useV2FileServer = false
|
||||
|
||||
private override init() { }
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ public final class AttachmentUploadJob : NSObject, Job, NSCoding { // NSObject/N
|
|||
let storage = SNMessagingKitConfiguration.shared.storage
|
||||
if let v2OpenGroup = storage.getV2OpenGroup(for: threadID) {
|
||||
AttachmentUploadJob.upload(stream, using: { data in return OpenGroupAPIV2.upload(data, to: v2OpenGroup.room, on: v2OpenGroup.server) }, encrypt: false, onSuccess: handleSuccess, onFailure: handleFailure)
|
||||
} else if FileServerAPIV2.useV2FileServer && storage.getOpenGroup(for: threadID) == nil {
|
||||
} else if Features.useV2FileServer && storage.getOpenGroup(for: threadID) == nil {
|
||||
AttachmentUploadJob.upload(stream, using: FileServerAPIV2.upload, encrypt: true, onSuccess: handleSuccess, onFailure: handleFailure)
|
||||
} else { // Legacy
|
||||
let openGroup = storage.getOpenGroup(for: threadID)
|
||||
|
|
|
@ -4,8 +4,6 @@ import PromiseKit
|
|||
public final class OpenGroupManagerV2 : NSObject {
|
||||
private var pollers: [String:OpenGroupPollerV2] = [:] // One for each server
|
||||
private var isPolling = false
|
||||
|
||||
@objc public static var useV2OpenGroups = true
|
||||
|
||||
// MARK: Initialization
|
||||
@objc public static let shared = OpenGroupManagerV2()
|
||||
|
|
|
@ -19,14 +19,10 @@ public final class SnodeAPI : NSObject {
|
|||
// MARK: Settings
|
||||
private static let maxRetryCount: UInt = 8
|
||||
private static let minSwarmSnodeCount = 3
|
||||
private static let seedNodePool: Set<String> = useTestnet ? [ "http://public.loki.foundation:38157" ] : [ "https://storage.seed1.loki.network:4433", "https://storage.seed3.loki.network:4433", "https://public.loki.foundation:4433" ]
|
||||
private static let seedNodePool: Set<String> = Features.useTestnet ? [ "http://public.loki.foundation:38157" ] : [ "https://storage.seed1.loki.network:4433", "https://storage.seed3.loki.network:4433", "https://public.loki.foundation:4433" ]
|
||||
private static let snodeFailureThreshold = 3
|
||||
private static let targetSwarmSnodeCount = 2
|
||||
private static let minSnodePoolCount = 12
|
||||
|
||||
/// - Note: Changing this on the fly is not recommended.
|
||||
internal static var useOnionRequests = true
|
||||
internal static let useTestnet = false
|
||||
|
||||
// MARK: Error
|
||||
public enum Error : LocalizedError {
|
||||
|
@ -123,7 +119,7 @@ public final class SnodeAPI : NSObject {
|
|||
|
||||
// MARK: Internal API
|
||||
internal static func invoke(_ method: Snode.Method, on snode: Snode, associatedWith publicKey: String? = nil, parameters: JSON) -> RawResponsePromise {
|
||||
if useOnionRequests {
|
||||
if Features.useOnionRequests {
|
||||
return OnionRequestAPI.sendOnionRequest(to: snode, invoking: method, with: parameters, associatedWith: publicKey).map2 { $0 as Any }
|
||||
} else {
|
||||
let url = "\(snode.address):\(snode.port)/storage_rpc/v1"
|
||||
|
@ -349,7 +345,7 @@ public final class SnodeAPI : NSObject {
|
|||
return Promise<Set<Snode>> { $0.fulfill(cachedSwarm) }
|
||||
} else {
|
||||
SNLog("Getting swarm for: \((publicKey == SNSnodeKitConfiguration.shared.storage.getUserPublicKey()) ? "self" : publicKey).")
|
||||
let parameters: [String:Any] = [ "pubKey" : useTestnet ? publicKey.removing05PrefixIfNeeded() : publicKey ]
|
||||
let parameters: [String:Any] = [ "pubKey" : Features.useTestnet ? publicKey.removing05PrefixIfNeeded() : publicKey ]
|
||||
return getRandomSnode().then2 { snode in
|
||||
attempt(maxRetryCount: 4, recoveringOn: Threading.workQueue) {
|
||||
invoke(.getSwarm, on: snode, associatedWith: publicKey, parameters: parameters)
|
||||
|
@ -370,7 +366,7 @@ public final class SnodeAPI : NSObject {
|
|||
storage.pruneLastMessageHashInfoIfExpired(for: snode, associatedWith: publicKey, using: transaction)
|
||||
}
|
||||
let lastHash = storage.getLastMessageHash(for: snode, associatedWith: publicKey) ?? ""
|
||||
let parameters = [ "pubKey" : useTestnet ? publicKey.removing05PrefixIfNeeded() : publicKey, "lastHash" : lastHash ]
|
||||
let parameters = [ "pubKey" : Features.useTestnet ? publicKey.removing05PrefixIfNeeded() : publicKey, "lastHash" : lastHash ]
|
||||
invoke(.getMessages, on: snode, associatedWith: publicKey, parameters: parameters).done2 { seal.fulfill($0) }.catch2 { seal.reject($0) }
|
||||
}
|
||||
return promise
|
||||
|
@ -386,7 +382,7 @@ public final class SnodeAPI : NSObject {
|
|||
storage.pruneLastMessageHashInfoIfExpired(for: targetSnode, associatedWith: publicKey, using: transaction)
|
||||
}
|
||||
let lastHash = storage.getLastMessageHash(for: targetSnode, associatedWith: publicKey) ?? ""
|
||||
let parameters = [ "pubKey" : useTestnet ? publicKey.removing05PrefixIfNeeded() : publicKey, "lastHash" : lastHash ]
|
||||
let parameters = [ "pubKey" : Features.useTestnet ? publicKey.removing05PrefixIfNeeded() : publicKey, "lastHash" : lastHash ]
|
||||
return invoke(.getMessages, on: targetSnode, associatedWith: publicKey, parameters: parameters).map2 { rawResponse in
|
||||
parseRawMessagesResponse(rawResponse, from: targetSnode, associatedWith: publicKey)
|
||||
}
|
||||
|
@ -398,7 +394,7 @@ public final class SnodeAPI : NSObject {
|
|||
|
||||
public static func sendMessage(_ message: SnodeMessage) -> Promise<Set<RawResponsePromise>> {
|
||||
let (promise, seal) = Promise<Set<RawResponsePromise>>.pending()
|
||||
let publicKey = useTestnet ? message.recipient.removing05PrefixIfNeeded() : message.recipient
|
||||
let publicKey = Features.useTestnet ? message.recipient.removing05PrefixIfNeeded() : message.recipient
|
||||
Threading.workQueue.async {
|
||||
getTargetSnodes(for: publicKey).map2 { targetSnodes in
|
||||
let parameters = message.toJSON()
|
||||
|
|
|
@ -44,7 +44,7 @@ public final class SnodeMessage : NSObject, NSCoding { // NSObject/NSCoding conf
|
|||
// MARK: JSON Conversion
|
||||
public func toJSON() -> JSON {
|
||||
return [
|
||||
"pubKey" : SnodeAPI.useTestnet ? recipient.removing05PrefixIfNeeded() : recipient,
|
||||
"pubKey" : Features.useTestnet ? recipient.removing05PrefixIfNeeded() : recipient,
|
||||
"data" : data.description,
|
||||
"ttl" : String(ttl),
|
||||
"timestamp" : String(timestamp),
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
@objc(SNFeatures)
|
||||
public final class Features : NSObject {
|
||||
public static let useOnionRequests = true
|
||||
public static let useTestnet = false
|
||||
@objc public static let useV2OpenGroups = true
|
||||
@objc public static let useV2FileServer = false
|
||||
}
|
|
@ -47,7 +47,7 @@ extension MessageSender {
|
|||
let (promise, seal) = Promise<Void>.pending()
|
||||
AttachmentUploadJob.upload(stream, using: { data in return OpenGroupAPIV2.upload(data, to: v2OpenGroup.room, on: v2OpenGroup.server) }, encrypt: false, onSuccess: { seal.fulfill(()) }, onFailure: { seal.reject($0) })
|
||||
return promise
|
||||
} else if FileServerAPIV2.useV2FileServer && storage.getOpenGroup(for: thread.uniqueId!) == nil {
|
||||
} else if Features.useV2FileServer && storage.getOpenGroup(for: thread.uniqueId!) == nil {
|
||||
let (promise, seal) = Promise<Void>.pending()
|
||||
AttachmentUploadJob.upload(stream, using: FileServerAPIV2.upload, encrypt: true, onSuccess: { seal.fulfill(()) }, onFailure: { seal.reject($0) })
|
||||
return promise
|
||||
|
|
|
@ -363,7 +363,7 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
|
|||
OWSAssertDebug(encryptedAvatarData.length > 0);
|
||||
|
||||
AnyPromise *promise;
|
||||
if (SNFileServerAPIV2.useV2FileServer) {
|
||||
if (SNFeatures.useV2FileServer) {
|
||||
promise = [SNFileServerAPIV2 upload:encryptedAvatarData];
|
||||
} else {
|
||||
promise = [SNFileServerAPI uploadProfilePicture:encryptedAvatarData];
|
||||
|
|
Loading…
Reference in New Issue