Elaborate request factory.

This commit is contained in:
Matthew Chen 2018-03-01 22:29:59 -05:00
parent c17a819366
commit 004479a2ce
18 changed files with 59 additions and 213 deletions

View File

@ -25,7 +25,6 @@
#import <SignalServiceKit/TSAccountManager.h>
#import <SignalServiceKit/TSGroupThread.h>
#import <SignalServiceKit/TSNetworkManager.h>
#import <SignalServiceKit/TSProfileAvatarUploadFormRequest.h>
#import <SignalServiceKit/TSStorageManager.h>
#import <SignalServiceKit/TSThread.h>
#import <SignalServiceKit/TSYapDatabaseObject.h>
@ -364,7 +363,7 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// See: https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-UsingHTTPPOST.html
TSProfileAvatarUploadFormRequest *formRequest = [TSProfileAvatarUploadFormRequest new];
TSRequest *formRequest = [OWSRequestFactory profileAvatarUploadFormRequest];
// TODO: Since this form request causes the server to reset my avatar URL, if the update fails
// at some point from here on out, we want the user to understand they probably no longer have

View File

@ -7,6 +7,7 @@
#import "NSDate+OWS.h"
#import "NSURLSessionDataTask+StatusCode.h"
#import "OWSIdentityManager.h"
#import "OWSRequestFactory.h"
#import "TSNetworkManager.h"
#import "TSRegisterSignedPrekeyRequest.h"
#import "TSStorageHeaders.h"
@ -236,7 +237,7 @@ static const NSUInteger kMaxPrekeyUpdateFailureCount = 5;
// one-time keys in this case.
//
// We do not need a "one-time only" mode.
TSAvailablePreKeysCountRequest *preKeyCountRequest = [[TSAvailablePreKeysCountRequest alloc] init];
TSRequest *preKeyCountRequest = [OWSRequestFactory availablePreKeysCountRequest];
[[TSNetworkManager sharedManager] makeRequest:preKeyCountRequest
success:^(NSURLSessionDataTask *task, NSDictionary *responseObject) {
NSString *preKeyCountKey = @"count";
@ -295,7 +296,7 @@ static const NSUInteger kMaxPrekeyUpdateFailureCount = 5;
// If we didn't update the prekeys, our local "current signed key" state should
// agree with the service's "current signed key" state. Let's verify that,
// since it's closely related to the issues we saw with the 2.7.0.10 release.
TSRequest *currentSignedPreKey = [[TSCurrentSignedPreKeyRequest alloc] init];
TSRequest *currentSignedPreKey = [OWSRequestFactory currentSignedPreKeyRequest];
[[TSNetworkManager sharedManager] makeRequest:currentSignedPreKey
success:^(NSURLSessionDataTask *task, NSDictionary *responseObject) {
NSString *keyIdDictKey = @"keyId";

View File

@ -1,13 +1,13 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "ContactsUpdater.h"
#import "Contact.h"
#import "Cryptography.h"
#import "OWSError.h"
#import "OWSRequestFactory.h"
#import "PhoneNumber.h"
#import "TSContactsIntersectionRequest.h"
#import "TSNetworkManager.h"
#import "TSStorageManager.h"
#import <YapDatabase/YapDatabase.h>
@ -163,7 +163,7 @@ NS_ASSUME_NONNULL_BEGIN
}
NSArray *hashes = [phoneNumbersByHashes allKeys];
TSRequest *request = [[TSContactsIntersectionRequest alloc] initWithHashesArray:hashes];
TSRequest *request = [OWSRequestFactory contactsIntersectionRequestWithHashesArray:hashes];
[[TSNetworkManager sharedManager] makeRequest:request
success:^(NSURLSessionDataTask *tsTask, id responseDict) {
NSMutableDictionary *attributesForIdentifier = [NSMutableDictionary dictionary];

View File

@ -16,6 +16,7 @@
#import "OWSMessageServiceParams.h"
#import "OWSOutgoingSentMessageTranscript.h"
#import "OWSOutgoingSyncMessage.h"
#import "OWSRequestFactory.h"
#import "OWSUploadingService.h"
#import "PreKeyBundle+jsonDict.h"
#import "SignalRecipient.h"
@ -1339,7 +1340,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
// are called _off_ the main thread. Otherwise we'll deadlock if the main
// thread is blocked on opening a transaction.
TSRequest *request =
[[TSRecipientPrekeyRequest alloc] initWithRecipient:identifier deviceId:[deviceNumber stringValue]];
[OWSRequestFactory recipientPrekeyRequestWithRecipient:identifier deviceId:[deviceNumber stringValue]];
[self.networkManager makeRequest:request
completionQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
success:^(NSURLSessionDataTask *task, id responseObject) {

View File

@ -35,6 +35,16 @@ NS_ASSUME_NONNULL_BEGIN
+ (TSRequest *)attachmentRequestWithAttachmentId:(UInt64)attachmentId relay:(nullable NSString *)relay;
+ (TSRequest *)availablePreKeysCountRequest;
+ (TSRequest *)contactsIntersectionRequestWithHashesArray:(NSArray *)hashes;
+ (TSRequest *)currentSignedPreKeyRequest;
+ (TSRequest *)profileAvatarUploadFormRequest;
+ (TSRequest *)recipientPrekeyRequestWithRecipient:(NSString *)recipientNumber deviceId:(NSString *)deviceId;
@end
NS_ASSUME_NONNULL_END

View File

@ -112,6 +112,45 @@ NS_ASSUME_NONNULL_BEGIN
return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"GET" parameters:@{}];
}
+ (TSRequest *)availablePreKeysCountRequest
{
NSString *path = [NSString stringWithFormat:@"%@", textSecureKeysAPI];
return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"GET" parameters:@{}];
}
+ (TSRequest *)contactsIntersectionRequestWithHashesArray:(NSArray *)hashes
{
OWSAssert(hashes.count > 0);
NSString *path = [NSString stringWithFormat:@"%@/%@", textSecureDirectoryAPI, @"tokens"];
return [TSRequest requestWithUrl:[NSURL URLWithString:path]
method:@"PUT"
parameters:@{
@"contacts" : hashes,
}];
}
+ (TSRequest *)currentSignedPreKeyRequest
{
NSString *path = textSecureSignedKeysAPI;
return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"GET" parameters:@{}];
}
+ (TSRequest *)profileAvatarUploadFormRequest
{
NSString *path = textSecureProfileAvatarFormAPI;
return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"GET" parameters:@{}];
}
+ (TSRequest *)recipientPrekeyRequestWithRecipient:(NSString *)recipientNumber deviceId:(NSString *)deviceId
{
OWSAssert(recipientNumber.length > 0);
OWSAssert(deviceId.length > 0);
NSString *path = [NSString stringWithFormat:@"%@/%@/%@", textSecureKeysAPI, recipientNumber, deviceId];
return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"GET" parameters:@{}];
}
@end
NS_ASSUME_NONNULL_END

View File

@ -1,13 +0,0 @@
//
// TSAvailablePreKeysCountRequest.h
// Signal
//
// Created by Frederic Jacobs on 27/01/15.
// Copyright (c) 2015 Open Whisper Systems. All rights reserved.
//
#import "TSRequest.h"
@interface TSAvailablePreKeysCountRequest : TSRequest
@end

View File

@ -1,27 +0,0 @@
//
// TSAvailablePreKeysCountRequest.m
// Signal
//
// Created by Frederic Jacobs on 27/01/15.
// Copyright (c) 2015 Open Whisper Systems. All rights reserved.
//
#import "TSAvailablePreKeysCountRequest.h"
#import "TSConstants.h"
@implementation TSAvailablePreKeysCountRequest
- (instancetype)init {
NSString *path = [NSString stringWithFormat:@"%@", textSecureKeysAPI];
self = [super initWithURL:[NSURL URLWithString:path]];
if (self) {
[self setHTTPMethod:@"GET"];
}
return self;
}
@end

View File

@ -1,15 +0,0 @@
//
// TSContactsIntersection.h
// TextSecureiOS
//
// Created by Frederic Jacobs on 10/12/13.
// Copyright (c) 2013 Open Whisper Systems. All rights reserved.
//
#import "TSRequest.h"
@interface TSContactsIntersectionRequest : TSRequest
- (id)initWithHashesArray:(NSArray *)hashes;
@end

View File

@ -1,27 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSContactsIntersectionRequest.h"
#import "TSConstants.h"
@implementation TSContactsIntersectionRequest
- (id)initWithHashesArray:(NSArray *)hashes {
self = [self
initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", textSecureDirectoryAPI, @"tokens"]]];
if (!self) {
return nil;
}
self.HTTPMethod = @"PUT";
self.parameters = @{
@"contacts" : hashes,
};
return self;
}
@end

View File

@ -1,13 +0,0 @@
//
// TSCurrentSignedPreKeyRequest.h
// Signal
//
// Created by Frederic Jacobs on 27/01/15.
// Copyright (c) 2015 Open Whisper Systems. All rights reserved.
//
#import "TSRequest.h"
@interface TSCurrentSignedPreKeyRequest : TSRequest
@end

View File

@ -1,22 +0,0 @@
//
// TSCurrentSignedPreKeyRequest.m
// Signal
//
// Created by Frederic Jacobs on 27/01/15.
// Copyright (c) 2015 Open Whisper Systems. All rights reserved.
//
#import "TSConstants.h"
#import "TSCurrentSignedPreKeyRequest.h"
@implementation TSCurrentSignedPreKeyRequest
- (instancetype)init {
self = [super initWithURL:[NSURL URLWithString:textSecureSignedKeysAPI]];
self.HTTPMethod = @"GET";
return self;
}
@end

View File

@ -1,15 +0,0 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "TSRequest.h"
NS_ASSUME_NONNULL_BEGIN
@interface TSProfileAvatarUploadFormRequest : TSRequest
- (instancetype)init;
@end
NS_ASSUME_NONNULL_END

View File

@ -1,23 +0,0 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "TSProfileAvatarUploadFormRequest.h"
#import "TSConstants.h"
NS_ASSUME_NONNULL_BEGIN
@implementation TSProfileAvatarUploadFormRequest
- (instancetype)init
{
self = [super initWithURL:[NSURL URLWithString:textSecureProfileAvatarFormAPI]];
self.HTTPMethod = @"GET";
return self;
}
@end
NS_ASSUME_NONNULL_END

View File

@ -1,15 +0,0 @@
//
// TSGetRecipientPrekey.h
// TextSecureiOS
//
// Created by Christine Corbett Moran on 11/30/13.
// Copyright (c) 2013 Open Whisper Systems. All rights reserved.
//
#import "TSRequest.h"
@class TSContact;
@interface TSRecipientPrekeyRequest : TSRequest
- (TSRequest *)initWithRecipient:(NSString *)recipientNumber deviceId:(NSString *)deviceId;
@end

View File

@ -1,26 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSRecipientPrekeyRequest.h"
#import "TSConstants.h"
@implementation TSRecipientPrekeyRequest
- (TSRequest *)initWithRecipient:(NSString *)recipientNumber deviceId:(NSString *)deviceId {
self = [super
initWithURL:[NSURL
URLWithString:[NSString
stringWithFormat:@"%@/%@/%@", textSecureKeysAPI, recipientNumber, deviceId]]];
if (!self) {
return nil;
}
self.HTTPMethod = @"GET";
self.parameters = nil;
return self;
}
@end

View File

@ -6,10 +6,6 @@
* TSNetworkManager imports all TSRequests to prevent massive imports
in classes that call TSNetworkManager
*/
#import "TSAvailablePreKeysCountRequest.h"
#import "TSContactsIntersectionRequest.h"
#import "TSCurrentSignedPreKeyRequest.h"
#import "TSRecipientPrekeyRequest.h"
#import "TSRegisterForPushRequest.h"
#import "TSRegisterPrekeysRequest.h"
#import "TSRequestVerificationCodeRequest.h"
@ -41,10 +37,7 @@ typedef void (^TSNetworkManagerFailure)(NSURLSessionDataTask *task, NSError *err
- (void)makeRequest:(TSRequest *)request
completionQueue:(dispatch_queue_t)completionQueue
success:(TSNetworkManagerSuccess)success
failure:(TSNetworkManagerFailure)failure NS_SWIFT_NAME(makeRequest(_:shouldCompleteOnMainQueue
:success
:failure
:));
failure:(TSNetworkManagerFailure)failure NS_SWIFT_NAME(makeRequest(_:shouldCompleteOnMainQueue:success:failure:));
@end

View File

@ -7,7 +7,6 @@
#import "NSURLSessionDataTask+StatusCode.h"
#import "OWSSignalService.h"
#import "TSAccountManager.h"
#import "TSRecipientPrekeyRequest.h"
#import "TSSubmitMessageRequest.h"
#import "TSVerifyCodeRequest.h"
#import <AFNetworking/AFNetworking.h>