mirror of https://github.com/oxen-io/session-ios
Rework account attributes; persist manual message fetch; add "unrestricted UD" setting.
parent
12c8eaf060
commit
1d40cbfb41
@ -0,0 +1,44 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
class OWS111UDAttributesMigration: OWSDatabaseMigration {
|
||||||
|
|
||||||
|
// MARK: - Singletons
|
||||||
|
|
||||||
|
private var networkManager: TSNetworkManager {
|
||||||
|
return SSKEnvironment.shared.networkManager
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: -
|
||||||
|
|
||||||
|
// increment a similar constant for each migration.
|
||||||
|
@objc
|
||||||
|
class func migrationId() -> String {
|
||||||
|
return "111"
|
||||||
|
}
|
||||||
|
|
||||||
|
override public func runUp(completion: @escaping OWSDatabaseMigrationCompletion) {
|
||||||
|
Logger.debug("")
|
||||||
|
BenchAsync(title: "UD Attributes Migration") { completeBenchmark in
|
||||||
|
self.doMigration {
|
||||||
|
completeBenchmark()
|
||||||
|
completion()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func doMigration(completion: @escaping OWSDatabaseMigrationCompletion) {
|
||||||
|
let request = OWSRequestFactory.updateAttributesRequest()
|
||||||
|
self.networkManager.makePromise(request: request).then(execute: { (_, _) in
|
||||||
|
self.dbReadWriteConnection().readWrite { transaction in
|
||||||
|
self.save(with: transaction)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.always {
|
||||||
|
completion()
|
||||||
|
}.retainUntilComplete()
|
||||||
|
}
|
||||||
|
}
|
@ -1,18 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
|
||||||
|
|
||||||
@interface TSAttributes : NSObject
|
|
||||||
|
|
||||||
+ (NSDictionary *)attributesFromStorageWithManualMessageFetching:(BOOL)isEnabled pin:(nullable NSString *)pin;
|
|
||||||
|
|
||||||
+ (NSDictionary *)attributesWithSignalingKey:(NSString *)signalingKey
|
|
||||||
serverAuthToken:(NSString *)authToken
|
|
||||||
manualMessageFetching:(BOOL)isEnabled
|
|
||||||
pin:(nullable NSString *)pin;
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
|
@ -1,45 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import "TSAttributes.h"
|
|
||||||
#import "TSAccountManager.h"
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
|
||||||
|
|
||||||
@implementation TSAttributes
|
|
||||||
|
|
||||||
+ (NSDictionary *)attributesFromStorageWithManualMessageFetching:(BOOL)isEnabled pin:(nullable NSString *)pin
|
|
||||||
{
|
|
||||||
return [self attributesWithSignalingKey:TSAccountManager.signalingKey
|
|
||||||
serverAuthToken:TSAccountManager.serverAuthToken
|
|
||||||
manualMessageFetching:isEnabled
|
|
||||||
pin:pin];
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (NSDictionary *)attributesWithSignalingKey:(NSString *)signalingKey
|
|
||||||
serverAuthToken:(NSString *)authToken
|
|
||||||
manualMessageFetching:(BOOL)isEnabled
|
|
||||||
pin:(nullable NSString *)pin
|
|
||||||
{
|
|
||||||
OWSAssertDebug(signalingKey.length > 0);
|
|
||||||
OWSAssertDebug(authToken.length > 0);
|
|
||||||
|
|
||||||
NSMutableDictionary *result = [@{
|
|
||||||
@"signalingKey" : signalingKey,
|
|
||||||
@"AuthKey" : authToken,
|
|
||||||
@"voice" : @(YES), // all Signal-iOS clients support voice
|
|
||||||
@"video" : @(YES), // all Signal-iOS clients support WebRTC-based voice and video calls.
|
|
||||||
@"fetchesMessages" :
|
|
||||||
@(isEnabled), // devices that don't support push must tell the server they fetch messages manually
|
|
||||||
@"registrationId" : [NSString stringWithFormat:@"%i", [TSAccountManager getOrGenerateRegistrationId]]
|
|
||||||
} mutableCopy];
|
|
||||||
if (pin.length > 0) {
|
|
||||||
result[@"pin"] = pin;
|
|
||||||
}
|
|
||||||
return [result copy];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
|
@ -1,23 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import "TSRequest.h"
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
|
||||||
|
|
||||||
@interface TSVerifyCodeRequest : TSRequest
|
|
||||||
|
|
||||||
@property (nonatomic, readonly) NSString *numberToValidate;
|
|
||||||
|
|
||||||
- (instancetype)init NS_UNAVAILABLE;
|
|
||||||
|
|
||||||
- (TSRequest *)initWithVerificationCode:(NSString *)verificationCode
|
|
||||||
forNumber:(NSString *)phoneNumber
|
|
||||||
pin:(nullable NSString *)pin
|
|
||||||
signalingKey:(NSString *)signalingKey
|
|
||||||
authKey:(NSString *)authKey;
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
|
@ -1,38 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import "TSVerifyCodeRequest.h"
|
|
||||||
#import "TSAccountManager.h"
|
|
||||||
#import "TSAttributes.h"
|
|
||||||
#import "TSConstants.h"
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
|
||||||
|
|
||||||
@implementation TSVerifyCodeRequest
|
|
||||||
|
|
||||||
- (TSRequest *)initWithVerificationCode:(NSString *)verificationCode
|
|
||||||
forNumber:(NSString *)phoneNumber
|
|
||||||
pin:(nullable NSString *)pin
|
|
||||||
signalingKey:(NSString *)signalingKey
|
|
||||||
authKey:(NSString *)authKey
|
|
||||||
{
|
|
||||||
OWSAssertDebug(verificationCode.length > 0);
|
|
||||||
OWSAssertDebug(phoneNumber.length > 0);
|
|
||||||
OWSAssertDebug(signalingKey.length > 0);
|
|
||||||
OWSAssertDebug(authKey.length > 0);
|
|
||||||
|
|
||||||
NSURL *url =
|
|
||||||
[NSURL URLWithString:[NSString stringWithFormat:@"%@/code/%@", textSecureAccountsAPI, verificationCode]];
|
|
||||||
NSDictionary *parameters =
|
|
||||||
[TSAttributes attributesWithSignalingKey:signalingKey serverAuthToken:authKey manualMessageFetching:NO pin:pin];
|
|
||||||
self = [super initWithURL:url method:@"PUT" parameters:parameters];
|
|
||||||
|
|
||||||
_numberToValidate = phoneNumber;
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
|
@ -1,45 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import "TSAttributes.h"
|
|
||||||
#import "SSKBaseTestObjC.h"
|
|
||||||
#import "TSAccountManager.h"
|
|
||||||
#import <XCTest/XCTest.h>
|
|
||||||
|
|
||||||
@interface TSAttributesTest : SSKBaseTestObjC
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation TSAttributesTest
|
|
||||||
|
|
||||||
- (void)setUp {
|
|
||||||
[super setUp];
|
|
||||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)tearDown {
|
|
||||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
|
||||||
[super tearDown];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)testAttributesWithSignalingKey {
|
|
||||||
|
|
||||||
NSString *registrationId = [NSString stringWithFormat:@"%i", [TSAccountManager getOrGenerateRegistrationId]];
|
|
||||||
NSDictionary *expected = @{
|
|
||||||
@"AuthKey" : @"fake-server-auth-token",
|
|
||||||
@"registrationId" : registrationId,
|
|
||||||
@"signalingKey" : @"fake-signaling-key",
|
|
||||||
@"video" : @1,
|
|
||||||
@"voice" : @1
|
|
||||||
};
|
|
||||||
|
|
||||||
NSDictionary *actual = [TSAttributes attributesWithSignalingKey:@"fake-signaling-key"
|
|
||||||
serverAuthToken:@"fake-server-auth-token"
|
|
||||||
manualMessageFetching:NO
|
|
||||||
pin:nil];
|
|
||||||
|
|
||||||
XCTAssertEqualObjects(expected, actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
Loading…
Reference in New Issue