Sketch out profile manager.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 7b2bab2abc
commit 63e20cd8bb

@ -5,7 +5,6 @@
#import "DebugUIMessages.h"
#import "Environment.h"
#import "OWSTableViewController.h"
#import "SecurityUtils.h"
#import "Signal-Swift.h"
#import "ThreadUtil.h"
#import <AFNetworking/AFNetworking.h>
@ -13,6 +12,7 @@
#import <SignalServiceKit/OWSDisappearingConfigurationUpdateInfoMessage.h>
#import <SignalServiceKit/OWSDisappearingMessagesConfiguration.h>
#import <SignalServiceKit/OWSVerificationStateChangeMessage.h>
#import <SignalServiceKit/SecurityUtils.h>
#import <SignalServiceKit/TSCall.h>
#import <SignalServiceKit/TSInvalidIdentityKeyReceivingErrorMessage.h>
#import <SignalServiceKit/TSStorageManager+SessionStore.h>

@ -6,7 +6,6 @@
#import "Environment.h"
#import "OWSCountryMetadata.h"
#import "OWSTableViewController.h"
#import "SecurityUtils.h"
#import "Signal-Swift.h"
#import "ThreadUtil.h"
#import <AFNetworking/AFNetworking.h>
@ -14,6 +13,7 @@
#import <SignalServiceKit/OWSDisappearingConfigurationUpdateInfoMessage.h>
#import <SignalServiceKit/OWSDisappearingMessagesConfiguration.h>
#import <SignalServiceKit/OWSVerificationStateChangeMessage.h>
#import <SignalServiceKit/SecurityUtils.h>
#import <SignalServiceKit/TSCall.h>
#import <SignalServiceKit/TSInvalidIdentityKeyReceivingErrorMessage.h>
#import <SignalServiceKit/TSStorageManager+SessionStore.h>

@ -11,7 +11,6 @@
#import "GroupViewHelper.h"
#import "OWSContactsManager.h"
#import "OWSTableViewController.h"
#import "SecurityUtils.h"
#import "Signal-Swift.h"
#import "SignalKeyingStorage.h"
#import "TSOutgoingMessage.h"
@ -20,6 +19,7 @@
#import "UIViewController+OWS.h"
#import <SignalServiceKit/NSDate+millisecondTimeStamp.h>
#import <SignalServiceKit/OWSMessageSender.h>
#import <SignalServiceKit/SecurityUtils.h>
#import <SignalServiceKit/SignalAccount.h>
#import <SignalServiceKit/TSGroupModel.h>
#import <SignalServiceKit/TSGroupThread.h>

@ -11,7 +11,6 @@
#import "GroupViewHelper.h"
#import "OWSContactsManager.h"
#import "OWSTableViewController.h"
#import "SecurityUtils.h"
#import "Signal-Swift.h"
#import "SignalKeyingStorage.h"
#import "TSOutgoingMessage.h"
@ -21,6 +20,7 @@
#import "ViewControllerUtils.h"
#import <SignalServiceKit/NSDate+millisecondTimeStamp.h>
#import <SignalServiceKit/OWSMessageSender.h>
#import <SignalServiceKit/SecurityUtils.h>
#import <SignalServiceKit/SignalAccount.h>
#import <SignalServiceKit/TSGroupModel.h>
#import <SignalServiceKit/TSGroupThread.h>

@ -4,9 +4,6 @@
NS_ASSUME_NONNULL_BEGIN
@class TSStorageManager;
@class OWSMessageSender;
extern NSString *const kNSNotificationName_BlockedPhoneNumbersDidChange;
// This class can be safely accessed and used from any thread.

@ -5,14 +5,16 @@
NS_ASSUME_NONNULL_BEGIN
@class ContactsUpdater;
@class OWSBlockingManager;
@class OWSProfilesManager;
@class OWSUploadingService;
@class SignalRecipient;
@class OWSBlockingManager;
@class TSInvalidIdentityKeySendingErrorMessage;
@class TSNetworkManager;
@class TSOutgoingMessage;
@class TSStorageManager;
@class TSThread;
@protocol ContactsManagerProtocol;
/**
@ -57,6 +59,8 @@ NS_SWIFT_NAME(MessageSender)
- (void)setBlockingManager:(OWSBlockingManager *)blockingManager;
- (void)setProfilesManager:(OWSProfilesManager *)profilesManager;
/**
* Send and resend text messages or resend messages with existing attachments.
* If you haven't yet created the attachment, see the `sendAttachmentData:` variants.

@ -14,6 +14,7 @@
#import "OWSMessageServiceParams.h"
#import "OWSOutgoingSentMessageTranscript.h"
#import "OWSOutgoingSyncMessage.h"
#import "OWSProfilesManager.h"
#import "OWSUploadingService.h"
#import "PreKeyBundle+jsonDict.h"
#import "SignalRecipient.h"
@ -356,6 +357,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
@property (nonatomic, readonly) TSNetworkManager *networkManager;
@property (nonatomic, readonly) TSStorageManager *storageManager;
@property (nonatomic, readonly) OWSBlockingManager *blockingManager;
@property (nonatomic, readonly) OWSProfilesManager *profilesManager;
@property (nonatomic, readonly) OWSUploadingService *uploadingService;
@property (nonatomic, readonly) YapDatabaseConnection *dbConnection;
@property (nonatomic, readonly) id<ContactsManagerProtocol> contactsManager;
@ -398,6 +400,14 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
_blockingManager = blockingManager;
}
- (void)setProfilesManager:(OWSProfilesManager *)profilesManager
{
OWSAssert(profilesManager);
OWSAssert(!_profilesManager);
_profilesManager = profilesManager;
}
- (NSOperationQueue *)sendingQueueForMessage:(TSOutgoingMessage *)message
{
OWSAssert(message);

@ -0,0 +1,16 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
NS_ASSUME_NONNULL_BEGIN
// This class can be safely accessed and used from any thread.
@interface OWSProfilesManager : NSObject
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)sharedManager;
@end
NS_ASSUME_NONNULL_END

@ -0,0 +1,144 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "OWSProfilesManager.h"
#import "OWSMessageSender.h"
#import "SecurityUtils.h"
#import "TSStorageManager.h"
#import "TextSecureKitEnv.h"
NS_ASSUME_NONNULL_BEGIN
NSString *const kOWSProfilesManager_Collection = @"kOWSProfilesManager_Collection";
// This key is used to persist the local user's profile key.
NSString *const kOWSProfilesManager_LocalProfileKey = @"kOWSProfilesManager_LocalProfileKey";
// TODO:
static const NSInteger kProfileKeyLength = 16;
@interface OWSProfilesManager ()
@property (nonatomic, readonly) TSStorageManager *storageManager;
@property (nonatomic, readonly) OWSMessageSender *messageSender;
@property (nonatomic, readonly, nullable) NSData *localProfileKey;
@end
#pragma mark -
@implementation OWSProfilesManager
@synthesize localProfileKey = _localProfileKey;
+ (instancetype)sharedManager
{
static OWSProfilesManager *sharedMyManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedMyManager = [[self alloc] initDefault];
});
return sharedMyManager;
}
- (instancetype)initDefault
{
TSStorageManager *storageManager = [TSStorageManager sharedManager];
OWSMessageSender *messageSender = [TextSecureKitEnv sharedEnv].messageSender;
return [self initWithStorageManager:storageManager messageSender:messageSender];
}
- (instancetype)initWithStorageManager:(TSStorageManager *)storageManager
messageSender:(OWSMessageSender *)messageSender
{
self = [super init];
if (!self) {
return self;
}
OWSAssert(storageManager);
OWSAssert(messageSender);
_storageManager = storageManager;
_messageSender = messageSender;
OWSSingletonAssert();
// Register this manager with the message sender.
// This is a circular dependency.
[messageSender setProfilesManager:self];
// Try to load.
_localProfileKey = [self.storageManager objectForKey:kOWSProfilesManager_LocalProfileKey
inCollection:kOWSProfilesManager_Collection];
if (!_localProfileKey) {
// Generate
_localProfileKey = [OWSProfilesManager generateLocalProfileKey];
// Persist
[self.storageManager setObject:_localProfileKey
forKey:kOWSProfilesManager_LocalProfileKey
inCollection:kOWSProfilesManager_Collection];
}
OWSAssert(_localProfileKey.length == kProfileKeyLength);
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)observeNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification
object:nil];
}
#pragma mark - Local Profile Key
+ (NSData *)generateLocalProfileKey
{
// TODO:
OWSFail(@"Profile key generation is not yet implemented.");
return [SecurityUtils generateRandomBytes:kProfileKeyLength];
}
- (nullable NSData *)localProfileKey
{
OWSAssert(_localProfileKey.length == kProfileKeyLength);
return _localProfileKey;
}
#pragma mark - Notifications
- (void)applicationDidBecomeActive:(NSNotification *)notification
{
OWSAssert([NSThread isMainThread]);
@synchronized(self)
{
// TODO: Sync if necessary.
}
}
#pragma mark - Logging
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
- (NSString *)tag
{
return self.class.tag;
}
@end
NS_ASSUME_NONNULL_END
Loading…
Cancel
Save