Rename TSStorageManager to OWSPrimaryStorage.

This commit is contained in:
Matthew Chen 2018-03-05 11:30:58 -03:00
parent 09d561823b
commit d6f4db1523
118 changed files with 794 additions and 783 deletions

2
Pods

@ -1 +1 @@
Subproject commit aae15b5fb1fc718f19b862390b61f540e45a36ee
Subproject commit 0be58b9a53eea267c9acb74abb24fdef3eed7b96

View File

@ -40,12 +40,12 @@
#import <SignalServiceKit/OWSMessageManager.h>
#import <SignalServiceKit/OWSMessageSender.h>
#import <SignalServiceKit/OWSOrphanedDataCleaner.h>
#import <SignalServiceKit/OWSPrimaryStorage+Calling.h>
#import <SignalServiceKit/OWSReadReceiptManager.h>
#import <SignalServiceKit/TSAccountManager.h>
#import <SignalServiceKit/TSDatabaseView.h>
#import <SignalServiceKit/TSPreKeyManager.h>
#import <SignalServiceKit/TSSocketManager.h>
#import <SignalServiceKit/TSStorageManager+Calling.h>
#import <SignalServiceKit/TextSecureKitEnv.h>
#import <YapDatabase/YapDatabaseCryptoUtils.h>
#import <sys/sysctl.h>
@ -120,7 +120,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
SetRandFunctionSeed();
// XXX - careful when moving this. It must happen before we initialize TSStorageManager.
// XXX - careful when moving this. It must happen before we initialize OWSPrimaryStorage.
[self verifyDBKeysAvailableBeforeBackgroundLaunch];
#if RELEASE
@ -223,7 +223,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
return;
}
if (![TSStorageManager isDatabasePasswordAccessible]) {
if (![OWSPrimaryStorage isDatabasePasswordAccessible]) {
DDLogInfo(
@"%@ exiting because we are in the background and the database password is not accessible.", self.logTag);
[DDLog flushLog];
@ -239,12 +239,12 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
// TODO: Remove this logging once we have high confidence
// in our migration logic.
NSArray<NSString *> *paths = @[
TSStorageManager.legacyDatabaseFilePath,
TSStorageManager.legacyDatabaseFilePath_SHM,
TSStorageManager.legacyDatabaseFilePath_WAL,
TSStorageManager.sharedDataDatabaseFilePath,
TSStorageManager.sharedDataDatabaseFilePath_SHM,
TSStorageManager.sharedDataDatabaseFilePath_WAL,
OWSPrimaryStorage.legacyDatabaseFilePath,
OWSPrimaryStorage.legacyDatabaseFilePath_SHM,
OWSPrimaryStorage.legacyDatabaseFilePath_WAL,
OWSPrimaryStorage.sharedDataDatabaseFilePath,
OWSPrimaryStorage.sharedDataDatabaseFilePath_SHM,
OWSPrimaryStorage.sharedDataDatabaseFilePath_WAL,
];
NSFileManager *fileManager = [NSFileManager defaultManager];
for (NSString *path in paths) {
@ -259,16 +259,16 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
OWSBackgroundTask *_Nullable backgroundTask = [OWSBackgroundTask backgroundTaskWithLabelStr:__PRETTY_FUNCTION__];
if ([NSFileManager.defaultManager fileExistsAtPath:TSStorageManager.legacyDatabaseFilePath]) {
if ([NSFileManager.defaultManager fileExistsAtPath:OWSPrimaryStorage.legacyDatabaseFilePath]) {
DDLogInfo(@"%@ Legacy Database file size: %@",
self.logTag,
[OWSFileSystem fileSizeOfPath:TSStorageManager.legacyDatabaseFilePath]);
[OWSFileSystem fileSizeOfPath:OWSPrimaryStorage.legacyDatabaseFilePath]);
DDLogInfo(@"%@ \t Legacy SHM file size: %@",
self.logTag,
[OWSFileSystem fileSizeOfPath:TSStorageManager.legacyDatabaseFilePath_SHM]);
[OWSFileSystem fileSizeOfPath:OWSPrimaryStorage.legacyDatabaseFilePath_SHM]);
DDLogInfo(@"%@ \t Legacy WAL file size: %@",
self.logTag,
[OWSFileSystem fileSizeOfPath:TSStorageManager.legacyDatabaseFilePath_WAL]);
[OWSFileSystem fileSizeOfPath:OWSPrimaryStorage.legacyDatabaseFilePath_WAL]);
}
NSError *_Nullable error = [self convertDatabaseIfNecessary];
@ -278,7 +278,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
}
if (!error) {
error = [TSStorageManager migrateToSharedData];
error = [OWSPrimaryStorage migrateToSharedData];
}
if (!error) {
error = [OWSProfileManager migrateToSharedData];
@ -342,7 +342,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
{
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
NSString *databaseFilePath = [TSStorageManager legacyDatabaseFilePath];
NSString *databaseFilePath = [OWSPrimaryStorage legacyDatabaseFilePath];
if (![[NSFileManager defaultManager] fileExistsAtPath:databaseFilePath]) {
DDLogVerbose(@"%@ no legacy database file found", self.logTag);
return nil;
@ -621,8 +621,9 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
// Mark all "attempting out" messages as "unsent", i.e. any messages that were not successfully
// sent before the app exited should be marked as failures.
[[[OWSFailedMessagesJob alloc] initWithStorageManager:[TSStorageManager sharedManager]] run];
[[[OWSFailedAttachmentDownloadsJob alloc] initWithStorageManager:[TSStorageManager sharedManager]] run];
[[[OWSFailedMessagesJob alloc] initWithPrimaryStorage:[OWSPrimaryStorage sharedManager]] run];
[[[OWSFailedAttachmentDownloadsJob alloc] initWithPrimaryStorage:[OWSPrimaryStorage sharedManager]]
run];
[AppStoreRating setupRatingLibrary];
});
@ -796,7 +797,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
[AppReadiness runNowOrWhenAppIsReady:^{
NSString *_Nullable phoneNumber = handle;
if ([handle hasPrefix:CallKitCallManager.kAnonymousCallHandlePrefix]) {
phoneNumber = [[TSStorageManager sharedManager] phoneNumberForCallKitId:handle];
phoneNumber = [[OWSPrimaryStorage sharedManager] phoneNumberForCallKitId:handle];
if (phoneNumber.length < 1) {
DDLogWarn(
@"%@ ignoring attempt to initiate video call to unknown anonymous signal user.", self.logTag);
@ -855,7 +856,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
[AppReadiness runNowOrWhenAppIsReady:^{
NSString *_Nullable phoneNumber = handle;
if ([handle hasPrefix:CallKitCallManager.kAnonymousCallHandlePrefix]) {
phoneNumber = [[TSStorageManager sharedManager] phoneNumberForCallKitId:handle];
phoneNumber = [[OWSPrimaryStorage sharedManager] phoneNumberForCallKitId:handle];
if (phoneNumber.length < 1) {
DDLogWarn(
@"%@ ignoring attempt to initiate audio call to unknown anonymous signal user.", self.logTag);
@ -1138,7 +1139,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
if ([TSAccountManager isRegistered]) {
DDLogInfo(@"localNumber: %@", [TSAccountManager localNumber]);
[[TSStorageManager sharedManager].newDatabaseConnection
[[OWSPrimaryStorage sharedManager].newDatabaseConnection
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
[ExperienceUpgradeFinder.sharedManager markAllAsSeenWithTransaction:transaction];
}];

View File

@ -13,23 +13,23 @@ class SessionResetJob: NSObject {
let recipientId: String
let thread: TSThread
let storageManager: TSStorageManager
let primaryStorage: OWSPrimaryStorage
let messageSender: MessageSender
required init(recipientId: String, thread: TSThread, messageSender: MessageSender, storageManager: TSStorageManager) {
required init(recipientId: String, thread: TSThread, messageSender: MessageSender, primaryStorage: OWSPrimaryStorage) {
self.thread = thread
self.recipientId = recipientId
self.messageSender = messageSender
self.storageManager = storageManager
self.primaryStorage = primaryStorage
}
func run() {
Logger.info("\(TAG) Local user reset session.")
let dbConnection = TSStorageManager.shared().newDatabaseConnection()
let dbConnection = OWSPrimaryStorage.shared().newDatabaseConnection()
dbConnection.asyncReadWrite { (transaction) in
Logger.info("\(self.TAG) deleting sessions for recipient: \(self.recipientId)")
self.storageManager.deleteAllSessions(forContact: self.recipientId, protocolContext: transaction)
self.primaryStorage.deleteAllSessions(forContact: self.recipientId, protocolContext: transaction)
DispatchQueue.main.async {
let endSessionMessage = EndSessionMessage(timestamp: NSDate.ows_millisecondTimeStamp(), in: self.thread)
@ -39,7 +39,7 @@ class SessionResetJob: NSObject {
// Archive the just-created session since the recipient should delete their corresponding
// session upon receiving and decrypting our EndSession message.
// Otherwise if we send another message before them, they wont have the session to decrypt it.
self.storageManager.archiveAllSessions(forContact: self.recipientId, protocolContext: transaction)
self.primaryStorage.archiveAllSessions(forContact: self.recipientId, protocolContext: transaction)
}
Logger.info("\(self.TAG) successfully sent EndSessionMessage.")
let message = TSInfoMessage(timestamp: NSDate.ows_millisecondTimeStamp(),
@ -56,7 +56,7 @@ class SessionResetJob: NSObject {
// Archive the just-created session since the recipient should delete their corresponding
// session upon receiving and decrypting our EndSession message.
// Otherwise if we send another message before them, they wont have the session to decrypt it.
self.storageManager.archiveAllSessions(forContact: self.recipientId, protocolContext: transaction)
self.primaryStorage.archiveAllSessions(forContact: self.recipientId, protocolContext: transaction)
}
Logger.error("\(self.TAG) failed to send EndSessionMessage with error: \(error.localizedDescription)")
})
@ -64,11 +64,11 @@ class SessionResetJob: NSObject {
}
}
class func run(contactThread: TSContactThread, messageSender: MessageSender, storageManager: TSStorageManager) {
class func run(contactThread: TSContactThread, messageSender: MessageSender, primaryStorage: OWSPrimaryStorage) {
let job = self.init(recipientId: contactThread.contactIdentifier(),
thread: contactThread,
messageSender: messageSender,
storageManager: storageManager)
primaryStorage: primaryStorage)
job.run()
}
}

View File

@ -94,6 +94,8 @@
#import <SignalServiceKit/OWSMessageReceiver.h>
#import <SignalServiceKit/OWSMessageSender.h>
#import <SignalServiceKit/OWSOutgoingCallMessage.h>
#import <SignalServiceKit/OWSPrimaryStorage+Calling.h>
#import <SignalServiceKit/OWSPrimaryStorage+SessionStore.h>
#import <SignalServiceKit/OWSProfileKeyMessage.h>
#import <SignalServiceKit/OWSRecipientIdentity.h>
#import <SignalServiceKit/OWSRequestFactory.h>
@ -116,8 +118,6 @@
#import <SignalServiceKit/TSOutgoingMessage.h>
#import <SignalServiceKit/TSPreKeyManager.h>
#import <SignalServiceKit/TSSocketManager.h>
#import <SignalServiceKit/TSStorageManager+Calling.h>
#import <SignalServiceKit/TSStorageManager+SessionStore.h>
#import <SignalServiceKit/TSThread.h>
#import <SignalServiceKit/Threading.h>
#import <WebRTC/RTCAudioSession.h>

View File

@ -8,8 +8,8 @@
#import <SignalMessaging/Environment.h>
#import <SignalMessaging/OWSPreferences.h>
#import <SignalMessaging/UIUtil.h>
#import <SignalServiceKit/OWSPrimaryStorage.h>
#import <SignalServiceKit/TSDatabaseView.h>
#import <SignalServiceKit/TSStorageManager.h>
@implementation AboutTableViewController
@ -71,11 +71,11 @@
#ifdef DEBUG
__block NSUInteger threadCount;
__block NSUInteger messageCount;
[TSStorageManager.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
[OWSPrimaryStorage.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
threadCount = [[transaction ext:TSThreadDatabaseViewExtensionName] numberOfItemsInAllGroups];
messageCount = [[transaction ext:TSMessageDatabaseViewExtensionName] numberOfItemsInAllGroups];
}];
unsigned long long databaseFileSize = [TSStorageManager.sharedManager databaseFileSize];
unsigned long long databaseFileSize = [OWSPrimaryStorage.sharedManager databaseFileSize];
OWSTableSection *debugSection = [OWSTableSection new];
debugSection.headerTitle = @"Debug";

View File

@ -196,7 +196,7 @@ typedef enum : NSUInteger {
@property (nonatomic, readonly) OWSContactsManager *contactsManager;
@property (nonatomic, readonly) ContactsUpdater *contactsUpdater;
@property (nonatomic, readonly) OWSMessageSender *messageSender;
@property (nonatomic, readonly) TSStorageManager *storageManager;
@property (nonatomic, readonly) OWSPrimaryStorage *primaryStorage;
@property (nonatomic, readonly) TSNetworkManager *networkManager;
@property (nonatomic, readonly) OutboundCallInitiator *outboundCallInitiator;
@property (nonatomic, readonly) OWSBlockingManager *blockingManager;
@ -269,7 +269,7 @@ typedef enum : NSUInteger {
_contactsUpdater = [Environment current].contactsUpdater;
_messageSender = [Environment current].messageSender;
_outboundCallInitiator = SignalApp.sharedApp.outboundCallInitiator;
_storageManager = [TSStorageManager sharedManager];
_primaryStorage = [OWSPrimaryStorage sharedManager];
_networkManager = [TSNetworkManager sharedManager];
_blockingManager = [OWSBlockingManager sharedManager];
_contactsViewHelper = [[ContactsViewHelper alloc] initWithDelegate:self];
@ -294,7 +294,7 @@ typedef enum : NSUInteger {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yapDatabaseModified:)
name:YapDatabaseModifiedNotification
object:TSStorageManager.sharedManager.dbNotificationObject];
object:OWSPrimaryStorage.sharedManager.dbNotificationObject];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yapDatabaseModifiedExternally:)
name:YapDatabaseModifiedExternallyNotification
@ -1664,9 +1664,9 @@ typedef enum : NSUInteger {
OWSAttachmentsProcessor *processor =
[[OWSAttachmentsProcessor alloc] initWithAttachmentPointer:attachmentPointer
networkManager:self.networkManager
storageManager:self.storageManager];
primaryStorage:self.primaryStorage];
[processor fetchAttachmentsForMessage:message
storageManager:self.storageManager
primaryStorage:self.primaryStorage
success:^(TSAttachmentStream *_Nonnull attachmentStream) {
DDLogInfo(
@"%@ Successfully redownloaded attachment in thread: %@", self.logTag, message.thread);
@ -1837,7 +1837,7 @@ typedef enum : NSUInteger {
TSContactThread *contactThread = (TSContactThread *)self.thread;
[OWSSessionResetJob runWithContactThread:contactThread
messageSender:self.messageSender
storageManager:self.storageManager];
primaryStorage:self.primaryStorage];
}];
[alertController addAction:resetSessionAction];
@ -2799,7 +2799,7 @@ typedef enum : NSUInteger {
{
NSAssert([NSThread isMainThread], @"Must access uiDatabaseConnection on main thread!");
if (!_uiDatabaseConnection) {
_uiDatabaseConnection = [self.storageManager newDatabaseConnection];
_uiDatabaseConnection = [self.primaryStorage newDatabaseConnection];
[_uiDatabaseConnection beginLongLivedReadTransaction];
}
return _uiDatabaseConnection;
@ -2808,7 +2808,7 @@ typedef enum : NSUInteger {
- (YapDatabaseConnection *)editingDatabaseConnection
{
if (!_editingDatabaseConnection) {
_editingDatabaseConnection = [self.storageManager newDatabaseConnection];
_editingDatabaseConnection = [self.primaryStorage newDatabaseConnection];
}
return _editingDatabaseConnection;
}

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "DebugUIDiskUsage.h"
@ -7,9 +7,9 @@
#import "Signal-Swift.h"
#import <SignalServiceKit/NSDate+OWS.h>
#import <SignalServiceKit/OWSOrphanedDataCleaner.h>
#import <SignalServiceKit/OWSPrimaryStorage.h>
#import <SignalServiceKit/TSDatabaseView.h>
#import <SignalServiceKit/TSInteraction.h>
#import <SignalServiceKit/TSStorageManager.h>
NS_ASSUME_NONNULL_BEGIN
@ -47,9 +47,8 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)saveAllAttachments
{
TSStorageManager *storageManager = [TSStorageManager sharedManager];
[storageManager.newDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
OWSPrimaryStorage *primaryStorage = [OWSPrimaryStorage sharedManager];
[primaryStorage.newDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
NSMutableArray<TSAttachmentStream *> *attachmentStreams = [NSMutableArray new];
[transaction enumerateKeysAndObjectsInCollection:TSAttachmentStream.collection
usingBlock:^(NSString *key, TSAttachment *attachment, BOOL *stop) {
@ -79,9 +78,8 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)deleteOldMessages:(NSTimeInterval)maxAgeSeconds
{
TSStorageManager *storageManager = [TSStorageManager sharedManager];
[storageManager.newDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
OWSPrimaryStorage *primaryStorage = [OWSPrimaryStorage sharedManager];
[primaryStorage.newDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
NSMutableArray<NSString *> *threadIds = [NSMutableArray new];
YapDatabaseViewTransaction *interactionsByThread = [transaction ext:TSMessageDatabaseViewExtensionName];
[interactionsByThread enumerateGroupsUsingBlock:^(NSString *group, BOOL *stop) {

View File

@ -13,6 +13,7 @@
#import <SignalServiceKit/OWSBatchMessageProcessor.h>
#import <SignalServiceKit/OWSDisappearingConfigurationUpdateInfoMessage.h>
#import <SignalServiceKit/OWSDisappearingMessagesConfiguration.h>
#import <SignalServiceKit/OWSPrimaryStorage+SessionStore.h>
#import <SignalServiceKit/OWSSyncGroupsRequestMessage.h>
#import <SignalServiceKit/OWSVerificationStateChangeMessage.h>
#import <SignalServiceKit/SecurityUtils.h>
@ -20,7 +21,6 @@
#import <SignalServiceKit/TSDatabaseView.h>
#import <SignalServiceKit/TSIncomingMessage.h>
#import <SignalServiceKit/TSInvalidIdentityKeyReceivingErrorMessage.h>
#import <SignalServiceKit/TSStorageManager+SessionStore.h>
#import <SignalServiceKit/TSThread.h>
NS_ASSUME_NONNULL_BEGIN
@ -753,8 +753,7 @@ NS_ASSUME_NONNULL_BEGIN
NSMutableArray<TSInteraction *> *result = [NSMutableArray new];
[TSStorageManager.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
if ([thread isKindOfClass:[TSContactThread class]]) {
TSContactThread *contactThread = (TSContactThread *)thread;
@ -883,7 +882,6 @@ NS_ASSUME_NONNULL_BEGIN
inThread:thread
failedMessageType:TSErrorMessageNonBlockingIdentityChange
recipientId:@"+19174054215"]];
}];
return result;
@ -894,7 +892,7 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(thread);
NSArray<TSInteraction *> *messages = [self unsavedSystemMessagesInThread:thread];
[TSStorageManager.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
for (TSInteraction *message in messages) {
[message saveWithTransaction:transaction];
}
@ -907,7 +905,7 @@ NS_ASSUME_NONNULL_BEGIN
NSArray<TSInteraction *> *messages = [self unsavedSystemMessagesInThread:thread];
TSInteraction *message = messages[(NSUInteger)arc4random_uniform((uint32_t)messages.count)];
[TSStorageManager.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[message saveWithTransaction:transaction];
}];
}
@ -968,7 +966,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)createFakeUnreadMessages:(int)counter thread:(TSThread *)thread
{
[TSStorageManager.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
for (int i = 0; i < counter; i++) {
NSString *randomText = [self randomText];
TSIncomingMessage *message = [[TSIncomingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
@ -1009,7 +1007,7 @@ NS_ASSUME_NONNULL_BEGIN
{
const NSUInteger kMaxBatchSize = 2500;
if (counter < kMaxBatchSize) {
[TSStorageManager.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[self sendFakeMessages:counter thread:thread isTextOnly:isTextOnly transaction:transaction];
}];
} else {
@ -1017,7 +1015,7 @@ NS_ASSUME_NONNULL_BEGIN
NSUInteger remainder = counter;
while (remainder > 0) {
NSUInteger batchSize = MIN(kMaxBatchSize, remainder);
[TSStorageManager.dbReadWriteConnection
[OWSPrimaryStorage.dbReadWriteConnection
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[self sendFakeMessages:batchSize thread:thread isTextOnly:isTextOnly transaction:transaction];
}];
@ -1121,7 +1119,7 @@ NS_ASSUME_NONNULL_BEGIN
return;
}
[TSStorageManager.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
TSOutgoingMessage *message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
inThread:thread
messageBody:nil
@ -1190,7 +1188,7 @@ NS_ASSUME_NONNULL_BEGIN
[[TSGroupModel alloc] initWithTitle:groupName memberIds:recipientIds image:nil groupId:groupId];
__block TSGroupThread *thread;
[TSStorageManager.dbReadWriteConnection
[OWSPrimaryStorage.dbReadWriteConnection
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
thread = [TSGroupThread getOrCreateThreadWithGroupModel:groupModel transaction:transaction];
}];
@ -1273,7 +1271,7 @@ NS_ASSUME_NONNULL_BEGIN
NSData *envelopeData = [envelopeBuilder build].data;
OWSAssert(envelopeData);
[TSStorageManager.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[[OWSBatchMessageProcessor sharedInstance] enqueueEnvelopeData:envelopeData
plaintextData:plaintextData
transaction:transaction];
@ -1338,7 +1336,7 @@ NS_ASSUME_NONNULL_BEGIN
[self resurrectNewOutgoingMessages2:messageCount thread:thread transaction:transaction];
},
];
[TSStorageManager.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
int actionCount = 1 + (int)arc4random_uniform(3);
for (int actionIdx = 0; actionIdx < actionCount; actionIdx++) {
ActionBlock actionBlock = actionBlocks[(NSUInteger)arc4random_uniform((uint32_t)actionBlocks.count)];
@ -1493,7 +1491,7 @@ NS_ASSUME_NONNULL_BEGIN
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
DDLogInfo(@"%@ resurrectNewOutgoingMessages1.2: %zd", self.logTag, count);
[TSStorageManager.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
for (TSOutgoingMessage *message in messages) {
[message removeWithTransaction:transaction];
}
@ -1533,18 +1531,19 @@ NS_ASSUME_NONNULL_BEGIN
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
DDLogInfo(@"%@ resurrectNewOutgoingMessages2.2: %zd", self.logTag, count);
[TSStorageManager.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
for (TSOutgoingMessage *message in messages) {
[message removeWithTransaction:transaction];
}
}];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
DDLogInfo(@"%@ resurrectNewOutgoingMessages2.3: %zd", self.logTag, count);
[TSStorageManager.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
for (TSOutgoingMessage *message in messages) {
[message saveWithTransaction:transaction];
}
}];
[OWSPrimaryStorage.dbReadWriteConnection
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
for (TSOutgoingMessage *message in messages) {
[message saveWithTransaction:transaction];
}
}];
});
});
}
@ -1573,7 +1572,7 @@ NS_ASSUME_NONNULL_BEGIN
[recipientIds removeObject:[TSAccountManager localNumber]];
NSString *recipientId = (recipientIds.count > 0 ? recipientIds.firstObject : @"+19174054215");
[TSStorageManager.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
for (NSNumber *timestamp in timestamps) {
NSString *randomText = [self randomText];
{
@ -1612,7 +1611,7 @@ NS_ASSUME_NONNULL_BEGIN
@"non-crashing string",
];
[TSStorageManager.sharedManager.dbReadWriteConnection
[OWSPrimaryStorage.sharedManager.dbReadWriteConnection
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
for (NSString *string in strings) {
// DO NOT log these strings with the debugger attached.
@ -1654,7 +1653,7 @@ NS_ASSUME_NONNULL_BEGIN
@"This is some normal text",
];
[TSStorageManager.sharedManager.dbReadWriteConnection
[OWSPrimaryStorage.sharedManager.dbReadWriteConnection
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
for (NSString *string in strings) {
DDLogInfo(@"%@ sending zalgo", self.logTag);

View File

@ -16,11 +16,11 @@
#import <SignalMessaging/UIImage+OWS.h>
#import <SignalServiceKit/OWSDisappearingConfigurationUpdateInfoMessage.h>
#import <SignalServiceKit/OWSDisappearingMessagesConfiguration.h>
#import <SignalServiceKit/OWSPrimaryStorage+SessionStore.h>
#import <SignalServiceKit/OWSVerificationStateChangeMessage.h>
#import <SignalServiceKit/SecurityUtils.h>
#import <SignalServiceKit/TSCall.h>
#import <SignalServiceKit/TSInvalidIdentityKeyReceivingErrorMessage.h>
#import <SignalServiceKit/TSStorageManager+SessionStore.h>
#import <SignalServiceKit/TSThread.h>
NS_ASSUME_NONNULL_BEGIN
@ -171,7 +171,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)clearHasDismissedOffers
{
[TSStorageManager.dbReadWriteConnection
[OWSPrimaryStorage.dbReadWriteConnection
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
NSMutableArray<TSContactThread *> *contactThreads = [NSMutableArray new];
[transaction
@ -199,10 +199,10 @@ NS_ASSUME_NONNULL_BEGIN
NSString *fileName = filePath.lastPathComponent;
__block BOOL success;
[TSStorageManager.sharedManager.newDatabaseConnection
[OWSPrimaryStorage.sharedManager.newDatabaseConnection
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
NSError *error;
success = [[NSFileManager defaultManager] copyItemAtPath:TSStorageManager.databaseFilePath
success = [[NSFileManager defaultManager] copyItemAtPath:OWSPrimaryStorage.databaseFilePath
toPath:filePath
error:&error];
if (!success || error) {
@ -220,7 +220,7 @@ NS_ASSUME_NONNULL_BEGIN
DataSource *_Nullable dataSource = [DataSourcePath dataSourceWithFilePath:filePath];
[dataSource setSourceFilename:fileName];
SignalAttachment *attachment = [SignalAttachment attachmentWithDataSource:dataSource dataUTI:utiType];
NSData *databasePassword = [TSStorageManager.sharedManager databasePassword];
NSData *databasePassword = [OWSPrimaryStorage.sharedManager databasePassword];
attachment.captionText = [databasePassword hexadecimalString];
if (!attachment || [attachment hasError]) {
OWSFail(@"%@ attachment[%@]: %@", self.logTag, [attachment sourceFilename], [attachment errorName]);
@ -234,7 +234,7 @@ NS_ASSUME_NONNULL_BEGIN
NSString *filePath = [OWSFileSystem temporaryFilePathWithFileExtension:@"sqlite"];
NSString *fileName = filePath.lastPathComponent;
NSError *error = [TSStorageManager.sharedManager.newDatabaseConnection backupToPath:filePath];
NSError *error = [OWSPrimaryStorage.sharedManager.newDatabaseConnection backupToPath:filePath];
if (error) {
OWSFail(@"%@ Could not copy database file: %@.", self.logTag, error);
return;

View File

@ -36,7 +36,7 @@ class DebugUINotifications: DebugUIPage {
}
var sectionItems = [
OWSTableItem(title:"Last Incoming Message") { [weak self] in
OWSTableItem(title: "Last Incoming Message") { [weak self] in
guard let strongSelf = self else {
return
}
@ -44,7 +44,7 @@ class DebugUINotifications: DebugUIPage {
Logger.info("\(strongSelf.logTag) scheduling notification for incoming message.")
strongSelf.delayedNotificationDispatch {
Logger.info("\(strongSelf.logTag) dispatching")
TSStorageManager.shared().newDatabaseConnection().read { (transaction) in
OWSPrimaryStorage.shared().newDatabaseConnection().read { (transaction) in
guard let viewTransaction = transaction.ext(TSMessageDatabaseViewExtensionName) as? YapDatabaseViewTransaction else {
owsFail("unable to build view transaction")
return
@ -68,7 +68,7 @@ class DebugUINotifications: DebugUIPage {
if let contactThread = thread as? TSContactThread {
sectionItems += [
OWSTableItem(title:"Call Missed") { [weak self] in
OWSTableItem(title: "Call Missed") { [weak self] in
guard let strongSelf = self else {
return
}
@ -77,7 +77,7 @@ class DebugUINotifications: DebugUIPage {
strongSelf.notificationsAdapter.presentMissedCall(call, callerName: thread.name())
}
},
OWSTableItem(title:"Call Rejected: New Safety Number") { [weak self] in
OWSTableItem(title: "Call Rejected: New Safety Number") { [weak self] in
guard let strongSelf = self else {
return
}
@ -86,7 +86,7 @@ class DebugUINotifications: DebugUIPage {
strongSelf.notificationsAdapter.presentMissedCallBecauseOfNewIdentity(call: call, callerName: thread.name())
}
},
OWSTableItem(title:"Call Rejected: No Longer Verified") { [weak self] in
OWSTableItem(title: "Call Rejected: No Longer Verified") { [weak self] in
guard let strongSelf = self else {
return
}

View File

@ -6,8 +6,8 @@
#import "OWSTableViewController.h"
#import "Signal-Swift.h"
#import <SignalServiceKit/OWSIdentityManager.h>
#import <SignalServiceKit/OWSPrimaryStorage+SessionStore.h>
#import <SignalServiceKit/TSContactThread.h>
#import <SignalServiceKit/TSStorageManager+SessionStore.h>
NS_ASSUME_NONNULL_BEGIN
@ -30,7 +30,7 @@ NS_ASSUME_NONNULL_BEGIN
}],
[OWSTableItem itemWithTitle:@"Log All Sessions"
actionBlock:^{
[[TSStorageManager sharedManager] printAllSessions];
[[OWSPrimaryStorage sharedManager] printAllSessions];
}],
[OWSTableItem itemWithTitle:@"Toggle Key Change"
actionBlock:^{
@ -51,18 +51,18 @@ NS_ASSUME_NONNULL_BEGIN
}],
[OWSTableItem itemWithTitle:@"Delete all sessions"
actionBlock:^{
[TSStorageManager.sharedManager.newDatabaseConnection
[OWSPrimaryStorage.sharedManager.newDatabaseConnection
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[[TSStorageManager sharedManager]
[[OWSPrimaryStorage sharedManager]
deleteAllSessionsForContact:thread.contactIdentifier
protocolContext:transaction];
}];
}],
[OWSTableItem itemWithTitle:@"Archive all sessions"
actionBlock:^{
[TSStorageManager.sharedManager.newDatabaseConnection
[OWSPrimaryStorage.sharedManager.newDatabaseConnection
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[[TSStorageManager sharedManager]
[[OWSPrimaryStorage sharedManager]
archiveAllSessionsForContact:thread.contactIdentifier
protocolContext:transaction];
}];
@ -71,7 +71,7 @@ NS_ASSUME_NONNULL_BEGIN
actionBlock:^{
[OWSSessionResetJob runWithContactThread:thread
messageSender:[Environment current].messageSender
storageManager:[TSStorageManager sharedManager]];
primaryStorage:[OWSPrimaryStorage sharedManager]];
}],
]];
}
@ -99,27 +99,27 @@ NS_ASSUME_NONNULL_BEGIN
#if DEBUG
+ (void)clearSessionAndIdentityStore
{
[TSStorageManager.sharedManager.newDatabaseConnection
[OWSPrimaryStorage.sharedManager.newDatabaseConnection
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[[TSStorageManager sharedManager] resetSessionStore:transaction];
[[OWSPrimaryStorage sharedManager] resetSessionStore:transaction];
[[OWSIdentityManager sharedManager] clearIdentityState:transaction];
}];
}
+ (void)snapshotSessionAndIdentityStore
{
[TSStorageManager.sharedManager.newDatabaseConnection
[OWSPrimaryStorage.sharedManager.newDatabaseConnection
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[[TSStorageManager sharedManager] snapshotSessionStore:transaction];
[[OWSPrimaryStorage sharedManager] snapshotSessionStore:transaction];
[[OWSIdentityManager sharedManager] snapshotIdentityState:transaction];
}];
}
+ (void)restoreSessionAndIdentityStore
{
[TSStorageManager.sharedManager.newDatabaseConnection
[OWSPrimaryStorage.sharedManager.newDatabaseConnection
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[[TSStorageManager sharedManager] restoreSessionStore:transaction];
[[OWSPrimaryStorage sharedManager] restoreSessionStore:transaction];
[[OWSIdentityManager sharedManager] restoreIdentityState:transaction];
}];
}

View File

@ -11,9 +11,9 @@
#import <SignalServiceKit/Cryptography.h>
#import <SignalServiceKit/NSDate+OWS.h>
#import <SignalServiceKit/OWSDynamicOutgoingMessage.h>
#import <SignalServiceKit/OWSPrimaryStorage.h>
#import <SignalServiceKit/SecurityUtils.h>
#import <SignalServiceKit/TSGroupThread.h>
#import <SignalServiceKit/TSStorageManager.h>
#import <SignalServiceKit/TSThread.h>
NS_ASSUME_NONNULL_BEGIN
@ -475,7 +475,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)hallucinateTwinGroup:(TSGroupThread *)groupThread
{
__block TSGroupThread *thread;
[TSStorageManager.dbReadWriteConnection
[OWSPrimaryStorage.dbReadWriteConnection
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
TSGroupModel *groupModel =
[[TSGroupModel alloc] initWithTitle:[groupThread.groupModel.groupName stringByAppendingString:@" Copy"]

View File

@ -14,6 +14,8 @@
#import <SignalServiceKit/OWSBlockingManager.h>
#import <SignalServiceKit/OWSDisappearingConfigurationUpdateInfoMessage.h>
#import <SignalServiceKit/OWSDisappearingMessagesConfiguration.h>
#import <SignalServiceKit/OWSPrimaryStorage+SessionStore.h>
#import <SignalServiceKit/OWSPrimaryStorage.h>
#import <SignalServiceKit/OWSReadReceiptManager.h>
#import <SignalServiceKit/OWSSyncConfigurationMessage.h>
#import <SignalServiceKit/OWSSyncContactsMessage.h>
@ -25,8 +27,6 @@
#import <SignalServiceKit/TSDatabaseView.h>
#import <SignalServiceKit/TSIncomingMessage.h>
#import <SignalServiceKit/TSInvalidIdentityKeyReceivingErrorMessage.h>
#import <SignalServiceKit/TSStorageManager+SessionStore.h>
#import <SignalServiceKit/TSStorageManager.h>
#import <SignalServiceKit/TSThread.h>
NS_ASSUME_NONNULL_BEGIN
@ -90,7 +90,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (YapDatabaseConnection *)dbConnection
{
return [TSStorageManager.sharedManager newDatabaseConnection];
return [OWSPrimaryStorage.sharedManager newDatabaseConnection];
}
+ (void)sendContactsSyncMessage

View File

@ -17,9 +17,9 @@
#import <SignalServiceKit/OWSFingerprint.h>
#import <SignalServiceKit/OWSFingerprintBuilder.h>
#import <SignalServiceKit/OWSIdentityManager.h>
#import <SignalServiceKit/OWSPrimaryStorage+SessionStore.h>
#import <SignalServiceKit/TSAccountManager.h>
#import <SignalServiceKit/TSInfoMessage.h>
#import <SignalServiceKit/TSStorageManager+SessionStore.h>
NS_ASSUME_NONNULL_BEGIN
@ -512,7 +512,7 @@ typedef void (^CustomLayoutBlock)(void);
- (void)verifyUnverifyButtonTapped:(UIGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state == UIGestureRecognizerStateRecognized) {
[TSStorageManager.sharedManager.newDatabaseConnection readWriteWithBlock:^(
[OWSPrimaryStorage.sharedManager.newDatabaseConnection readWriteWithBlock:^(
YapDatabaseReadWriteTransaction *transaction) {
BOOL isVerified = [[OWSIdentityManager sharedManager] verificationStateForRecipientId:self.recipientId
transaction:transaction]

View File

@ -9,6 +9,7 @@
#import "InboxTableViewCell.h"
#import "NewContactThreadViewController.h"
#import "OWSNavigationController.h"
#import "OWSPrimaryStorage.h"
#import "ProfileViewController.h"
#import "PushManager.h"
#import "Signal-Swift.h"
@ -16,7 +17,6 @@
#import "TSAccountManager.h"
#import "TSDatabaseView.h"
#import "TSGroupThread.h"
#import "TSStorageManager.h"
#import "ViewControllerUtils.h"
#import <PromiseKit/AnyPromise.h>
#import <SignalMessaging/OWSContactsManager.h>
@ -136,7 +136,7 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yapDatabaseModified:)
name:YapDatabaseModifiedNotification
object:TSStorageManager.sharedManager.dbNotificationObject];
object:OWSPrimaryStorage.sharedManager.dbNotificationObject];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yapDatabaseModifiedExternally:)
name:YapDatabaseModifiedExternallyNotification
@ -254,7 +254,7 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
[super viewDidLoad];
[self.navigationController.navigationBar setTranslucent:NO];
self.editingDbConnection = TSStorageManager.sharedManager.newDatabaseConnection;
self.editingDbConnection = OWSPrimaryStorage.sharedManager.newDatabaseConnection;
// Create the database connection.
[self uiDatabaseConnection];
@ -922,7 +922,7 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
OWSAssertIsOnMainThread();
if (!_uiDatabaseConnection) {
_uiDatabaseConnection = [TSStorageManager.sharedManager newDatabaseConnection];
_uiDatabaseConnection = [OWSPrimaryStorage.sharedManager newDatabaseConnection];
[_uiDatabaseConnection beginLongLivedReadTransaction];
}
return _uiDatabaseConnection;

View File

@ -60,7 +60,7 @@ class MessageDetailViewController: OWSViewController, UIScrollViewDelegate, Medi
self.viewItem = viewItem
self.message = message
self.mode = mode
self.databaseConnection = TSStorageManager.shared().newDatabaseConnection()
self.databaseConnection = OWSPrimaryStorage.shared().newDatabaseConnection()
super.init(nibName: nil, bundle: nil)
}
@ -83,7 +83,7 @@ class MessageDetailViewController: OWSViewController, UIScrollViewDelegate, Medi
NotificationCenter.default.addObserver(self,
selector: #selector(yapDatabaseModified),
name: NSNotification.Name.YapDatabaseModified,
object: TSStorageManager.shared().dbNotificationObject)
object: OWSPrimaryStorage.shared().dbNotificationObject)
}
override func viewWillAppear(_ animated: Bool) {
@ -263,13 +263,13 @@ class MessageDetailViewController: OWSViewController, UIScrollViewDelegate, Medi
rows.append(valueRow(name: NSLocalizedString("MESSAGE_METADATA_VIEW_SENT_DATE_TIME",
comment: "Label for the 'sent date & time' field of the 'message metadata' view."),
value: DateUtil.formatPastTimestampRelativeToNow(message.timestamp,
isRTL:self.view.isRTL())))
isRTL: self.view.isRTL())))
if message as? TSIncomingMessage != nil {
rows.append(valueRow(name: NSLocalizedString("MESSAGE_METADATA_VIEW_RECEIVED_DATE_TIME",
comment: "Label for the 'received date & time' field of the 'message metadata' view."),
value: DateUtil.formatPastTimestampRelativeToNow(message.timestampForSorting(),
isRTL:self.view.isRTL())))
isRTL: self.view.isRTL())))
}
rows += addAttachmentMetadataRows()
@ -295,7 +295,7 @@ class MessageDetailViewController: OWSViewController, UIScrollViewDelegate, Medi
}
if let mediaMessageView = mediaMessageView {
mediaMessageView.autoMatch(.height, to: .width, of: mediaMessageView, withOffset:0, relation: .lessThanOrEqual)
mediaMessageView.autoMatch(.height, to: .width, of: mediaMessageView, withOffset: 0, relation: .lessThanOrEqual)
}
updateTextLayout()
@ -362,7 +362,7 @@ class MessageDetailViewController: OWSViewController, UIScrollViewDelegate, Medi
messageTextProxyView.addSubview(messageTextView)
messageTextView.autoPinWidthToSuperview()
self.messageTextTopConstraint = messageTextView.autoPinEdge(toSuperviewEdge: .top, withInset: 0)
self.messageTextHeightLayoutConstraint = messageTextView.autoSetDimension(.height, toSize:0)
self.messageTextHeightLayoutConstraint = messageTextView.autoSetDimension(.height, toSize: 0)
let bubbleView = UIImageView(image: bubbleImageData.messageBubbleImage)
self.bubbleView = bubbleView
@ -373,13 +373,13 @@ class MessageDetailViewController: OWSViewController, UIScrollViewDelegate, Medi
messageTextProxyView.autoPinEdge(toSuperviewEdge: isIncoming ? .leading : .trailing, withInset: messageTailEdgeMargin)
messageTextProxyView.autoPinEdge(toSuperviewEdge: isIncoming ? .trailing : .leading, withInset: messageNoTailEdgeMargin)
messageTextProxyView.autoPinHeightToSuperview(withMargin: 10)
self.messageTextProxyViewHeightConstraint = messageTextProxyView.autoSetDimension(.height, toSize:0)
self.messageTextProxyViewHeightConstraint = messageTextProxyView.autoSetDimension(.height, toSize: 0)
let row = UIView()
row.addSubview(bubbleView)
bubbleView.autoPinHeightToSuperview()
bubbleView.autoPinEdge(toSuperviewEdge: isIncoming ? .leading : .trailing, withInset: bubbleViewHMargin)
self.bubbleViewWidthConstraint = bubbleView.autoSetDimension(.width, toSize:0)
self.bubbleViewWidthConstraint = bubbleView.autoSetDimension(.width, toSize: 0)
rows.append(row)
}
@ -705,13 +705,13 @@ class MessageDetailViewController: OWSViewController, UIScrollViewDelegate, Medi
let maxBubbleWidth = bubbleSuperview.width() - (bubbleViewHMargin * 2)
let maxTextWidth = maxBubbleWidth - (messageTailEdgeMargin + messageNoTailEdgeMargin)
// Measure the total text size.
let textSize = messageTextView.sizeThatFits(CGSize(width:maxTextWidth, height:CGFloat.greatestFiniteMagnitude))
let textSize = messageTextView.sizeThatFits(CGSize(width: maxTextWidth, height: CGFloat.greatestFiniteMagnitude))
// Measure the size of the scroll view viewport.
let scrollViewSize = scrollView.frame.size
// Obtain the current scroll view content offset (scroll state).
let scrollViewContentOffset = scrollView.contentOffset
// Obtain the location of the text view proxy relative to the content view.
let textProxyOffset = contentView.convert(CGPoint.zero, from:messageTextProxyView)
let textProxyOffset = contentView.convert(CGPoint.zero, from: messageTextProxyView)
// 1. The bubble view's width should fit the text content.
let bubbleViewWidth = ceil(textSize.width + messageTailEdgeMargin + messageNoTailEdgeMargin)
@ -738,7 +738,7 @@ class MessageDetailViewController: OWSViewController, UIScrollViewDelegate, Medi
// 5. We want to scroll the text view's content so that the text view
// renders the appropriate content for the scrollview's scroll state.
messageTextView.contentOffset = CGPoint(x:0, y:messageTextViewY)
messageTextView.contentOffset = CGPoint(x: 0, y: messageTextViewY)
}
public func scrollViewDidScroll(_ scrollView: UIScrollView) {
@ -751,7 +751,7 @@ class MessageDetailViewController: OWSViewController, UIScrollViewDelegate, Medi
public func presentDetails(mediaMessageView: MediaMessageView, fromView: UIView) {
let window = UIApplication.shared.keyWindow
let convertedRect = fromView.convert(fromView.bounds, to:window)
let convertedRect = fromView.convert(fromView.bounds, to: window)
guard let attachmentStream = self.attachmentStream else {
owsFail("attachment stream unexpectedly nil")
return

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "NewGroupViewController.h"
@ -446,7 +446,7 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68;
TSGroupModel *model = [self makeGroup];
__block TSGroupThread *thread;
[TSStorageManager.dbReadWriteConnection
[OWSPrimaryStorage.dbReadWriteConnection
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
thread = [TSGroupThread getOrCreateThreadWithGroupModel:model transaction:transaction];
}];

View File

@ -28,9 +28,9 @@
#import <SignalServiceKit/OWSDisappearingMessagesConfiguration.h>
#import <SignalServiceKit/OWSMessageSender.h>
#import <SignalServiceKit/OWSNotifyRemoteOfUpdatedDisappearingConfigurationJob.h>
#import <SignalServiceKit/OWSPrimaryStorage.h>
#import <SignalServiceKit/TSGroupThread.h>
#import <SignalServiceKit/TSOutgoingMessage.h>
#import <SignalServiceKit/TSStorageManager.h>
#import <SignalServiceKit/TSThread.h>
@import ContactsUI;

View File

@ -33,7 +33,7 @@ NS_ASSUME_NONNULL_BEGIN
{
[super viewDidLoad];
self.dbConnection = [[TSStorageManager sharedManager] newDatabaseConnection];
self.dbConnection = [[OWSPrimaryStorage sharedManager] newDatabaseConnection];
// HACK to get full width preview layer
CGRect oldFrame = self.qrScanningView.frame;

View File

@ -10,8 +10,8 @@
#import <SignalServiceKit/NSTimer+OWS.h>
#import <SignalServiceKit/OWSDevice.h>
#import <SignalServiceKit/OWSDevicesService.h>
#import <SignalServiceKit/OWSPrimaryStorage.h>
#import <SignalServiceKit/TSDatabaseView.h>
#import <SignalServiceKit/TSStorageManager.h>
#import <YapDatabase/YapDatabase.h>
#import <YapDatabase/YapDatabaseViewConnection.h>
#import <YapDatabase/YapDatabaseViewMappings.h>
@ -54,7 +54,7 @@ int const OWSLinkedDevicesTableViewControllerSectionAddDevice = 1;
#pragma clang diagnostic pop
}
self.dbConnection = [[TSStorageManager sharedManager] newDatabaseConnection];
self.dbConnection = [[OWSPrimaryStorage sharedManager] newDatabaseConnection];
[self.dbConnection beginLongLivedReadTransaction];
self.deviceMappings = [[YapDatabaseViewMappings alloc] initWithGroups:@[ TSSecondaryDevicesGroup ]
view:TSSecondaryDevicesDatabaseViewExtensionName];
@ -65,7 +65,7 @@ int const OWSLinkedDevicesTableViewControllerSectionAddDevice = 1;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yapDatabaseModified:)
name:YapDatabaseModifiedNotification
object:TSStorageManager.sharedManager.dbNotificationObject];
object:OWSPrimaryStorage.sharedManager.dbNotificationObject];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yapDatabaseModifiedExternally:)
name:YapDatabaseModifiedExternallyNotification

View File

@ -176,7 +176,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)deleteThreadsAndMessages
{
[TSStorageManager.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[transaction removeAllObjectsInCollection:[TSThread collection]];
[transaction removeAllObjectsInCollection:[SignalRecipient collection]];
[transaction removeAllObjectsInCollection:[TSInteraction collection]];

View File

@ -16,7 +16,7 @@
#import <SignalMessaging/OWSProfileManager.h>
#import <SignalMessaging/UIViewController+OWS.h>
#import <SignalServiceKit/NSDate+OWS.h>
#import <SignalServiceKit/TSStorageManager.h>
#import <SignalServiceKit/OWSPrimaryStorage.h>
NS_ASSUME_NONNULL_BEGIN
@ -63,10 +63,10 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
self.profileViewMode = profileViewMode;
// Use the TSStorageManager.dbReadWriteConnection for consistency with the reads below.
[[[TSStorageManager sharedManager] dbReadWriteConnection] setDate:[NSDate new]
forKey:kProfileView_LastPresentedDate
inCollection:kProfileView_Collection];
// Use the OWSPrimaryStorage.dbReadWriteConnection for consistency with the reads below.
[[[OWSPrimaryStorage sharedManager] dbReadWriteConnection] setDate:[NSDate new]
forKey:kProfileView_LastPresentedDate
inCollection:kProfileView_Collection];
return self;
}
@ -530,11 +530,11 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
return NO;
}
// Use the TSStorageManager.dbReadWriteConnection for consistency with the writes above.
// Use the OWSPrimaryStorage.dbReadWriteConnection for consistency with the writes above.
NSTimeInterval kProfileNagFrequency = kDayInterval * 30;
NSDate *_Nullable lastPresentedDate =
[[[TSStorageManager sharedManager] dbReadWriteConnection] dateForKey:kProfileView_LastPresentedDate
inCollection:kProfileView_Collection];
[[[OWSPrimaryStorage sharedManager] dbReadWriteConnection] dateForKey:kProfileView_LastPresentedDate
inCollection:kProfileView_Collection];
return (!lastPresentedDate || fabs([lastPresentedDate timeIntervalSinceNow]) > kProfileNagFrequency);
}

View File

@ -10,11 +10,11 @@ class SafetyNumberConfirmationAlert: NSObject {
let TAG = "[SafetyNumberConfirmationAlert]"
private let contactsManager: OWSContactsManager
private let storageManager: TSStorageManager
private let primaryStorage: OWSPrimaryStorage
init(contactsManager: OWSContactsManager) {
self.contactsManager = contactsManager
self.storageManager = TSStorageManager.shared()
self.primaryStorage = OWSPrimaryStorage.shared()
}
public class func presentAlertIfNecessary(recipientId: String, confirmationText: String, contactsManager: OWSContactsManager, completion: @escaping (Bool) -> Void) -> Bool {
@ -59,12 +59,12 @@ class SafetyNumberConfirmationAlert: NSObject {
comment: "Action sheet body presented when a user's SN have recently changed. Embeds {{contact's name or phone nubmer}}")
let body = String(format: bodyFormat, displayName)
let actionSheetController = UIAlertController(title: title, message:body, preferredStyle: .actionSheet)
let actionSheetController = UIAlertController(title: title, message: body, preferredStyle: .actionSheet)
let confirmAction = UIAlertAction(title: confirmationText, style: .default) { _ in
Logger.info("\(self.TAG) Confirmed identity: \(untrustedIdentity)")
self.storageManager.newDatabaseConnection().asyncReadWrite { (transaction) in
self.primaryStorage.newDatabaseConnection().asyncReadWrite { (transaction) in
OWSIdentityManager.shared().setVerificationState(.default, identityKey: untrustedIdentity.identityKey, recipientId: untrustedIdentity.recipientId, isUserInitiatedChange: true, transaction: transaction)
DispatchQueue.main.async {
completion(true)
@ -103,7 +103,7 @@ class SafetyNumberConfirmationAlert: NSObject {
Logger.info("\(self.TAG) Missing frontmostViewController")
return
}
FingerprintViewController.present(from:fromViewController, recipientId:theirRecipientId)
FingerprintViewController.present(from: fromViewController, recipientId: theirRecipientId)
}
private func untrustedIdentityForSending(recipientIds: [String]) -> OWSRecipientIdentity? {

View File

@ -110,7 +110,7 @@ protocol CallServiceObserver: class {
private let accountManager: AccountManager
private let messageSender: MessageSender
private let contactsManager: OWSContactsManager
private let storageManager: TSStorageManager
private let primaryStorage: OWSPrimaryStorage
// Exposed by environment.m
internal let notificationsAdapter: CallNotificationsAdapter
@ -209,7 +209,7 @@ protocol CallServiceObserver: class {
self.contactsManager = contactsManager
self.messageSender = messageSender
self.notificationsAdapter = notificationsAdapter
self.storageManager = TSStorageManager.shared()
self.primaryStorage = OWSPrimaryStorage.shared()
super.init()

View File

@ -40,7 +40,7 @@ final class CallKitCallManager: NSObject {
} else {
let callKitId = CallKitCallManager.kAnonymousCallHandlePrefix + call.localId.uuidString
handle = CXHandle(type: .generic, value: callKitId)
TSStorageManager.shared().setPhoneNumber(call.remotePhoneNumber, forCallKitId:callKitId)
OWSPrimaryStorage.shared().setPhoneNumber(call.remotePhoneNumber, forCallKitId: callKitId)
}
let startCallAction = CXStartCallAction(call: call.localId, handle: handle)

View File

@ -131,7 +131,7 @@ final class CallKitCallUIAdaptee: NSObject, CallUIAdaptee, CXProviderDelegate {
} else {
let callKitId = CallKitCallManager.kAnonymousCallHandlePrefix + call.localId.uuidString
update.remoteHandle = CXHandle(type: .generic, value: callKitId)
TSStorageManager.shared().setPhoneNumber(call.remotePhoneNumber, forCallKitId: callKitId)
OWSPrimaryStorage.shared().setPhoneNumber(call.remotePhoneNumber, forCallKitId: callKitId)
update.localizedCallerName = NSLocalizedString("CALLKIT_ANONYMOUS_CONTACT_NAME", comment: "The generic name used for calls if CallKit privacy is enabled")
}

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "SignalApp.h"
@ -8,9 +8,9 @@
#import "Signal-Swift.h"
#import <SignalMessaging/DebugLogger.h>
#import <SignalMessaging/Environment.h>
#import <SignalServiceKit/OWSPrimaryStorage.h>
#import <SignalServiceKit/TSContactThread.h>
#import <SignalServiceKit/TSGroupThread.h>
#import <SignalServiceKit/TSStorageManager.h>
#import <SignalServiceKit/Threading.h>
@interface SignalApp ()
@ -172,7 +172,7 @@
DispatchMainThreadSafe(^{
__block TSThread *thread = nil;
[TSStorageManager.dbReadWriteConnection
[OWSPrimaryStorage.dbReadWriteConnection
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
thread = [TSContactThread getOrCreateThreadWithContactId:recipientId transaction:transaction];
}];

View File

@ -57,14 +57,14 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe
- (instancetype)initDefault
{
return [self initWithMessageFetcherJob:SignalApp.sharedApp.messageFetcherJob
storageManager:[TSStorageManager sharedManager]
primaryStorage:[OWSPrimaryStorage sharedManager]
callUIAdapter:SignalApp.sharedApp.callService.callUIAdapter
messageSender:[Environment current].messageSender
notificationsManager:SignalApp.sharedApp.notificationsManager];
}
- (instancetype)initWithMessageFetcherJob:(OWSMessageFetcherJob *)messageFetcherJob
storageManager:(TSStorageManager *)storageManager
primaryStorage:(OWSPrimaryStorage *)primaryStorage
callUIAdapter:(CallUIAdapter *)callUIAdapter
messageSender:(OWSMessageSender *)messageSender
notificationsManager:(NotificationsManager *)notificationsManager
@ -278,7 +278,7 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe
NSString *threadId = userInfo[Signal_Thread_UserInfo_Key];
TSThread *thread = [TSThread fetchObjectWithUniqueID:threadId];
[TSStorageManager.dbReadWriteConnection
[OWSPrimaryStorage.dbReadWriteConnection
asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
// TODO: I suspect we only want to mark the message in
// question as read.

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "AppUpdateNag.h"
@ -7,10 +7,10 @@
#import "Signal-Swift.h"
#import <ATAppUpdater/ATAppUpdater.h>
#import <SignalServiceKit/NSDate+OWS.h>
#import <SignalServiceKit/TSStorageManager.h>
#import <SignalServiceKit/OWSPrimaryStorage.h>
NSString *const TSStorageManagerAppUpgradeNagCollection = @"TSStorageManagerAppUpgradeNagCollection";
NSString *const TSStorageManagerAppUpgradeNagDate = @"TSStorageManagerAppUpgradeNagDate";
NSString *const OWSPrimaryStorageAppUpgradeNagCollection = @"TSStorageManagerAppUpgradeNagCollection";
NSString *const OWSPrimaryStorageAppUpgradeNagDate = @"TSStorageManagerAppUpgradeNagDate";
@interface AppUpdateNag () <ATAppUpdaterDelegate>
@ -34,12 +34,12 @@ NSString *const TSStorageManagerAppUpgradeNagDate = @"TSStorageManagerAppUpgrade
- (instancetype)initDefault
{
TSStorageManager *storageManager = [TSStorageManager sharedManager];
OWSPrimaryStorage *primaryStorage = [OWSPrimaryStorage sharedManager];
return [self initWithStorageManager:storageManager];
return [self initWithPrimaryStorage:primaryStorage];
}
- (instancetype)initWithStorageManager:(TSStorageManager *)storageManager
- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage
{
self = [super init];
@ -47,9 +47,9 @@ NSString *const TSStorageManagerAppUpgradeNagDate = @"TSStorageManagerAppUpgrade
return self;
}
OWSAssert(storageManager);
OWSAssert(primaryStorage);
_dbConnection = storageManager.newDatabaseConnection;
_dbConnection = primaryStorage.newDatabaseConnection;
OWSSingletonAssert();
@ -69,8 +69,8 @@ NSString *const TSStorageManagerAppUpgradeNagDate = @"TSStorageManagerAppUpgrade
return;
}
NSDate *lastNagDate = [self.dbConnection dateForKey:TSStorageManagerAppUpgradeNagDate
inCollection:TSStorageManagerAppUpgradeNagCollection];
NSDate *lastNagDate = [self.dbConnection dateForKey:OWSPrimaryStorageAppUpgradeNagDate
inCollection:OWSPrimaryStorageAppUpgradeNagCollection];
const NSTimeInterval kNagFrequency = kDayInterval * 14;
BOOL canNag = (!lastNagDate || fabs(lastNagDate.timeIntervalSinceNow) > kNagFrequency);
if (!canNag) {
@ -97,8 +97,8 @@ NSString *const TSStorageManagerAppUpgradeNagDate = @"TSStorageManagerAppUpgrade
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
[self.dbConnection setDate:[NSDate new]
forKey:TSStorageManagerAppUpgradeNagDate
inCollection:TSStorageManagerAppUpgradeNagCollection];
forKey:OWSPrimaryStorageAppUpgradeNagDate
inCollection:OWSPrimaryStorageAppUpgradeNagCollection];
}
- (void)appUpdaterUserDidLaunchAppStore

View File

@ -11,7 +11,7 @@
#import <SignalMessaging/SignalMessaging-Swift.h>
#import <SignalServiceKit/Cryptography.h>
#import <SignalServiceKit/OWSFileSystem.h>
#import <SignalServiceKit/TSStorageManager.h>
#import <SignalServiceKit/OWSPrimaryStorage.h>
NS_ASSUME_NONNULL_BEGIN
@ -212,7 +212,7 @@ NSString *const Keychain_ImportBackupKey = @"ImportBackupKey";
OWSAES256Key *encryptionKey = [OWSAES256Key generateRandomKey];
self.encryptionKey = encryptionKey;
NSData *databasePassword = [TSStorageManager sharedManager].databasePassword;
NSData *databasePassword = [OWSPrimaryStorage sharedManager].databasePassword;
// TODO: We don't want this to reside unencrypted on disk even temporarily.
// We need to encrypt this with a key that we hide in the keychain.
@ -246,7 +246,7 @@ NSString *const Keychain_ImportBackupKey = @"ImportBackupKey";
// Use a read/write transaction to acquire a file lock on the database files.
//
// TODO: If we use multiple database files, lock them too.
[TSStorageManager.sharedManager.newDatabaseConnection
[OWSPrimaryStorage.sharedManager.newDatabaseConnection
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
if (![self copyDirectory:OWSFileSystem.appDocumentDirectoryPath
dstDirName:OWSBackup_AppDocumentDirName

View File

@ -12,9 +12,9 @@
#import <SignalMessaging/DebugLogger.h>
#import <SignalMessaging/Environment.h>
#import <SignalServiceKit/AppContext.h>
#import <SignalServiceKit/OWSPrimaryStorage.h>
#import <SignalServiceKit/TSAccountManager.h>
#import <SignalServiceKit/TSContactThread.h>
#import <SignalServiceKit/TSStorageManager.h>
#import <SignalServiceKit/Threading.h>
NS_ASSUME_NONNULL_BEGIN
@ -513,7 +513,7 @@ typedef void (^DebugLogUploadFailure)(DebugLogUploader *uploader, NSError *error
DispatchMainThreadSafe(^{
__block TSThread *thread = nil;
[TSStorageManager.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
thread = [TSContactThread getOrCreateThreadWithContactId:recipientId transaction:transaction];
}];
[ThreadUtil sendMessageWithText:url.absoluteString inThread:thread messageSender:messageSender];
@ -530,7 +530,7 @@ typedef void (^DebugLogUploadFailure)(DebugLogUploader *uploader, NSError *error
}
__block TSThread *thread = nil;
[TSStorageManager.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
[OWSPrimaryStorage.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
thread = [[transaction ext:TSThreadDatabaseViewExtensionName] firstObjectInGroup:TSInboxGroup];
}];
DispatchMainThreadSafe(^{

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
import XCTest
@ -48,7 +48,7 @@ class TokenObtainingTSAccountManager: VerifyingTSAccountManager {
class AccountManagerTest: XCTestCase {
let tsAccountManager = FailingTSAccountManager(networkManager: TSNetworkManager.shared(), storageManager: TSStorageManager.shared())
let tsAccountManager = FailingTSAccountManager(networkManager: TSNetworkManager.shared(), primaryStorage: OWSPrimaryStorage.shared())
var preferences = OWSPreferences()
func testRegisterWhenEmptyCode() {
@ -96,7 +96,7 @@ class AccountManagerTest: XCTestCase {
Environment.clearCurrentForTests()
Environment.setCurrent(Release.releaseEnvironment())
let tsAccountManager = TokenObtainingTSAccountManager(networkManager: TSNetworkManager.shared(), storageManager: TSStorageManager.shared())
let tsAccountManager = TokenObtainingTSAccountManager(networkManager: TSNetworkManager.shared(), primaryStorage: OWSPrimaryStorage.shared())
let accountManager = AccountManager(textSecureAccountManager: tsAccountManager, preferences: self.preferences)

View File

@ -244,7 +244,7 @@ NS_ASSUME_NONNULL_BEGIN
{
if (!_nonSignalContacts) {
NSMutableSet<Contact *> *nonSignalContacts = [NSMutableSet new];
[TSStorageManager.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
[OWSPrimaryStorage.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
for (Contact *contact in self.contactsManager.allContactsMap.allValues) {
NSArray<SignalRecipient *> *signalRecipients = [contact signalRecipientsWithTransaction:transaction];
if (signalRecipients.count < 1) {

View File

@ -4,8 +4,8 @@
#import "ThreadViewHelper.h"
#import <SignalServiceKit/AppContext.h>
#import <SignalServiceKit/OWSPrimaryStorage.h>
#import <SignalServiceKit/TSDatabaseView.h>
#import <SignalServiceKit/TSStorageManager.h>
#import <SignalServiceKit/TSThread.h>
#import <YapDatabase/YapDatabase.h>
#import <YapDatabase/YapDatabaseViewChange.h>
@ -52,7 +52,7 @@ NS_ASSUME_NONNULL_BEGIN
[[YapDatabaseViewMappings alloc] initWithGroups:@[ grouping ] view:TSThreadDatabaseViewExtensionName];
[self.threadMappings setIsReversed:YES forGroup:grouping];
self.uiDatabaseConnection = [TSStorageManager.sharedManager newDatabaseConnection];
self.uiDatabaseConnection = [OWSPrimaryStorage.sharedManager newDatabaseConnection];
[self.uiDatabaseConnection beginLongLivedReadTransaction];
[[NSNotificationCenter defaultCenter] addObserver:self
@ -99,7 +99,7 @@ NS_ASSUME_NONNULL_BEGIN
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yapDatabaseModified:)
name:YapDatabaseModifiedNotification
object:TSStorageManager.sharedManager.dbNotificationObject];
object:OWSPrimaryStorage.sharedManager.dbNotificationObject];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yapDatabaseModifiedExternally:)
name:YapDatabaseModifiedExternallyNotification
@ -107,7 +107,7 @@ NS_ASSUME_NONNULL_BEGIN
} else {
[[NSNotificationCenter defaultCenter] removeObserver:self
name:YapDatabaseModifiedNotification
object:TSStorageManager.sharedManager.dbNotificationObject];
object:OWSPrimaryStorage.sharedManager.dbNotificationObject];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:YapDatabaseModifiedExternallyNotification
object:nil];

View File

@ -398,7 +398,7 @@ typedef void (^SendMessageBlock)(SendCompletionBlock completion);
DDLogDebug(@"%@ Confirming identity for recipient: %@", self.logTag, recipientId);
[TSStorageManager.sharedManager.newDatabaseConnection asyncReadWriteWithBlock:^(
[OWSPrimaryStorage.sharedManager.newDatabaseConnection asyncReadWriteWithBlock:^(
YapDatabaseReadWriteTransaction *transaction) {
OWSVerificationState verificationState =
[[OWSIdentityManager sharedManager] verificationStateForRecipientId:recipientId transaction:transaction];

View File

@ -15,9 +15,9 @@
#import <SignalServiceKit/NSNotificationCenter+OWS.h>
#import <SignalServiceKit/NSString+SSK.h>
#import <SignalServiceKit/OWSError.h>
#import <SignalServiceKit/OWSPrimaryStorage.h>
#import <SignalServiceKit/PhoneNumber.h>
#import <SignalServiceKit/SignalAccount.h>
#import <SignalServiceKit/TSStorageManager.h>
@import Contacts;
@ -51,8 +51,8 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification
// TODO: We need to configure the limits of this cache.
_avatarCache = [ImageCache new];
_dbReadConnection = [TSStorageManager sharedManager].newDatabaseConnection;
_dbWriteConnection = [TSStorageManager sharedManager].newDatabaseConnection;
_dbReadConnection = [OWSPrimaryStorage sharedManager].newDatabaseConnection;
_dbWriteConnection = [OWSPrimaryStorage sharedManager].newDatabaseConnection;
_allContacts = @[];
_allContactsMap = @{};

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSContactsSyncing.h"
@ -9,16 +9,16 @@
#import <SignalServiceKit/DataSource.h>
#import <SignalServiceKit/MIMETypeUtil.h>
#import <SignalServiceKit/OWSMessageSender.h>
#import <SignalServiceKit/OWSPrimaryStorage.h>
#import <SignalServiceKit/OWSSyncContactsMessage.h>
#import <SignalServiceKit/TSAccountManager.h>
#import <SignalServiceKit/TSStorageManager.h>
#import <SignalServiceKit/YapDatabaseConnection+OWS.h>
NS_ASSUME_NONNULL_BEGIN
NSString *const kTSStorageManagerOWSContactsSyncingCollection = @"kTSStorageManagerOWSContactsSyncingCollection";
NSString *const kTSStorageManagerOWSContactsSyncingLastMessageKey
= @"kTSStorageManagerOWSContactsSyncingLastMessageKey";
NSString *const kOWSPrimaryStorageOWSContactsSyncingCollection = @"kOWSPrimaryStorageOWSContactsSyncingCollection";
NSString *const kOWSPrimaryStorageOWSContactsSyncingLastMessageKey
= @"kOWSPrimaryStorageOWSContactsSyncingLastMessageKey";
@interface OWSContactsSyncing ()
@ -122,8 +122,8 @@ NSString *const kTSStorageManagerOWSContactsSyncingLastMessageKey
NSData *messageData = [syncContactsMessage buildPlainTextAttachmentData];
NSData *lastMessageData =
[TSStorageManager.dbReadConnection objectForKey:kTSStorageManagerOWSContactsSyncingLastMessageKey
inCollection:kTSStorageManagerOWSContactsSyncingCollection];
[OWSPrimaryStorage.dbReadConnection objectForKey:kOWSPrimaryStorageOWSContactsSyncingLastMessageKey
inCollection:kOWSPrimaryStorageOWSContactsSyncingCollection];
if (lastMessageData && [lastMessageData isEqual:messageData]) {
// Ignore redundant contacts sync message.
@ -140,9 +140,9 @@ NSString *const kTSStorageManagerOWSContactsSyncingLastMessageKey
success:^{
DDLogInfo(@"%@ Successfully sent contacts sync message.", self.logTag);
[TSStorageManager.dbReadWriteConnection setObject:messageData
forKey:kTSStorageManagerOWSContactsSyncingLastMessageKey
inCollection:kTSStorageManagerOWSContactsSyncingCollection];
[OWSPrimaryStorage.dbReadWriteConnection setObject:messageData
forKey:kOWSPrimaryStorageOWSContactsSyncingLastMessageKey
inCollection:kOWSPrimaryStorageOWSContactsSyncingCollection];
dispatch_async(self.serialQueue, ^{
self.isRequestInFlight = NO;

View File

@ -62,7 +62,7 @@ NS_ASSUME_NONNULL_BEGIN
_threadViewHelper = [ThreadViewHelper new];
_threadViewHelper.delegate = self;
_uiDatabaseConnection = [[TSStorageManager sharedManager] newDatabaseConnection];
_uiDatabaseConnection = [[OWSPrimaryStorage sharedManager] newDatabaseConnection];
#ifdef DEBUG
_uiDatabaseConnection.permittedTransactions = YDB_AnyReadTransaction;
#endif
@ -70,7 +70,7 @@ NS_ASSUME_NONNULL_BEGIN
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yapDatabaseModified:)
name:YapDatabaseModifiedNotification
object:TSStorageManager.sharedManager.dbNotificationObject];
object:OWSPrimaryStorage.sharedManager.dbNotificationObject];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yapDatabaseModifiedExternally:)
name:YapDatabaseModifiedExternallyNotification
@ -333,7 +333,7 @@ NS_ASSUME_NONNULL_BEGIN
}
__block TSThread *thread = nil;
[TSStorageManager.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
thread = [TSContactThread getOrCreateThreadWithContactId:signalAccount.recipientId transaction:transaction];
}];
OWSAssert(thread);

View File

@ -5,7 +5,7 @@
#import "OWSSounds.h"
#import "OWSAudioPlayer.h"
#import <SignalServiceKit/OWSFileSystem.h>
#import <SignalServiceKit/TSStorageManager.h>
#import <SignalServiceKit/OWSPrimaryStorage.h>
#import <SignalServiceKit/TSThread.h>
#import <SignalServiceKit/YapDatabaseConnection+OWS.h>
#import <YapDatabase/YapDatabase.h>
@ -37,12 +37,12 @@ NSString *const kOWSSoundsStorageGlobalNotificationKey = @"kOWSSoundsStorageGlob
- (instancetype)initDefault
{
TSStorageManager *storageManager = [TSStorageManager sharedManager];
OWSPrimaryStorage *primaryStorage = [OWSPrimaryStorage sharedManager];
return [self initWithStorageManager:storageManager];
return [self initWithPrimaryStorage:primaryStorage];
}
- (instancetype)initWithStorageManager:(TSStorageManager *)storageManager
- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage
{
self = [super init];
@ -50,9 +50,9 @@ NSString *const kOWSSoundsStorageGlobalNotificationKey = @"kOWSSoundsStorageGlob
return self;
}
OWSAssert(storageManager);
OWSAssert(primaryStorage);
_dbConnection = storageManager.newDatabaseConnection;
_dbConnection = primaryStorage.newDatabaseConnection;
OWSSingletonAssert();

View File

@ -18,12 +18,12 @@
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// Order matters here.
TSStorageManager *storageManager = [TSStorageManager sharedManager];
OWSPrimaryStorage *primaryStorage = [OWSPrimaryStorage sharedManager];
TSNetworkManager *networkManager = [TSNetworkManager sharedManager];
OWSContactsManager *contactsManager = [OWSContactsManager new];
ContactsUpdater *contactsUpdater = [ContactsUpdater sharedUpdater];
OWSMessageSender *messageSender = [[OWSMessageSender alloc] initWithNetworkManager:networkManager
storageManager:storageManager
primaryStorage:primaryStorage
contactsManager:contactsManager
contactsUpdater:contactsUpdater];

View File

@ -1,10 +1,10 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "SignalKeyingStorage.h"
#import <SignalServiceKit/OWSPrimaryStorage.h>
#import <SignalServiceKit/SecurityUtils.h>
#import <SignalServiceKit/TSStorageManager.h>
#import <SignalServiceKit/YapDatabaseConnection+OWS.h>
#define SignalKeyingCollection @"SignalKeyingCollection"
@ -50,7 +50,7 @@
+ (void)storeData:(NSData *)data forKey:(NSString *)key
{
[TSStorageManager.dbReadWriteConnection setObject:data forKey:key inCollection:SignalKeyingCollection];
[OWSPrimaryStorage.dbReadWriteConnection setObject:data forKey:key inCollection:SignalKeyingCollection];
}
+ (NSData *)dataForKey:(NSString *)key andVerifyLength:(uint)length
@ -66,17 +66,17 @@
+ (NSData *)dataForKey:(NSString *)key
{
return [TSStorageManager.dbReadConnection dataForKey:key inCollection:SignalKeyingCollection];
return [OWSPrimaryStorage.dbReadConnection dataForKey:key inCollection:SignalKeyingCollection];
}
+ (NSString *)stringForKey:(NSString *)key
{
return [TSStorageManager.dbReadConnection stringForKey:key inCollection:SignalKeyingCollection];
return [OWSPrimaryStorage.dbReadConnection stringForKey:key inCollection:SignalKeyingCollection];
}
+ (void)storeString:(NSString *)string forKey:(NSString *)key
{
[TSStorageManager.dbReadWriteConnection setObject:string forKey:key inCollection:SignalKeyingCollection];
[OWSPrimaryStorage.dbReadWriteConnection setObject:string forKey:key inCollection:SignalKeyingCollection];
}
@end

View File

@ -49,7 +49,7 @@ NS_ASSUME_NONNULL_BEGIN
if (!previousVersion) {
DDLogInfo(@"No previous version found. Probably first launch since install - nothing to migrate.");
OWSDatabaseMigrationRunner *runner =
[[OWSDatabaseMigrationRunner alloc] initWithStorageManager:[TSStorageManager sharedManager]];
[[OWSDatabaseMigrationRunner alloc] initWithPrimaryStorage:[OWSPrimaryStorage sharedManager]];
[runner assumeAllExistingMigrationsRun];
dispatch_async(dispatch_get_main_queue(), ^{
completion();
@ -86,7 +86,7 @@ NS_ASSUME_NONNULL_BEGIN
[self clearBloomFilterCache];
}
[[[OWSDatabaseMigrationRunner alloc] initWithStorageManager:[TSStorageManager sharedManager]]
[[[OWSDatabaseMigrationRunner alloc] initWithPrimaryStorage:[OWSPrimaryStorage sharedManager]]
runAllOutstandingWithCompletion:completion];
}
@ -183,7 +183,7 @@ NS_ASSUME_NONNULL_BEGIN
NSError *deleteError;
if ([fm removeItemAtPath:bloomFilterPath error:&deleteError]) {
DDLogInfo(@"Successfully removed bloom filter cache.");
[TSStorageManager.dbReadWriteConnection
[OWSPrimaryStorage.dbReadWriteConnection
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
[transaction removeAllObjectsInCollection:@"TSRecipient"];
}];

View File

@ -31,7 +31,7 @@ static NSString *const OWS104CreateRecipientIdentitiesMigrationId = @"104";
NSMutableDictionary<NSString *, NSData *> *identityKeys = [NSMutableDictionary new];
[transaction
enumerateKeysAndObjectsInCollection:TSStorageManagerTrustedKeysCollection
enumerateKeysAndObjectsInCollection:OWSPrimaryStorageTrustedKeysCollection
usingBlock:^(NSString *_Nonnull recipientId, id _Nonnull object, BOOL *_Nonnull stop) {
if (![object isKindOfClass:[NSData class]]) {
OWSFail(@"%@ Unexpected object in trusted keys collection key: %@ object: %@",

View File

@ -8,13 +8,13 @@ NS_ASSUME_NONNULL_BEGIN
typedef void (^OWSDatabaseMigrationCompletion)(void);
@class TSStorageManager;
@class OWSPrimaryStorage;
@interface OWSDatabaseMigration : TSYapDatabaseObject
- (instancetype)initWithStorageManager:(TSStorageManager *)storageManager;
- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage;
@property (nonatomic, readonly) TSStorageManager *storageManager;
@property (nonatomic, readonly) OWSPrimaryStorage *primaryStorage;
// Prefer nonblocking (async) migrations by overriding `runUpWithTransaction:` in a subclass.
// Blocking migrations running too long will crash the app, effectively bricking install

View File

@ -3,27 +3,27 @@
//
#import "OWSDatabaseMigration.h"
#import <SignalServiceKit/TSStorageManager.h>
#import <SignalServiceKit/OWSPrimaryStorage.h>
NS_ASSUME_NONNULL_BEGIN
@implementation OWSDatabaseMigration
- (instancetype)initWithStorageManager:(TSStorageManager *)storageManager
- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage
{
self = [super initWithUniqueId:[self.class migrationId]];
if (!self) {
return self;
}
_storageManager = storageManager;
_primaryStorage = primaryStorage;
return self;
}
+ (MTLPropertyStorage)storageBehaviorForPropertyWithKey:(NSString *)propertyKey
{
if ([propertyKey isEqualToString:@"storageManager"]) {
if ([propertyKey isEqualToString:@"primaryStorage"]) {
return MTLPropertyStorageNone;
} else {
return [super storageBehaviorForPropertyWithKey:propertyKey];
@ -50,7 +50,7 @@ NS_ASSUME_NONNULL_BEGIN
{
OWSAssert(completion);
OWSDatabaseConnection *dbConnection = (OWSDatabaseConnection *)self.storageManager.newDatabaseConnection;
OWSDatabaseConnection *dbConnection = (OWSDatabaseConnection *)self.primaryStorage.newDatabaseConnection;
// These migrations won't be run until storage registrations are enqueued,
// but this transaction might begin before all registrations are marked as
// complete, so disable this checking.
@ -89,7 +89,7 @@ NS_ASSUME_NONNULL_BEGIN
static dispatch_once_t onceToken;
static YapDatabaseConnection *sharedDBConnection;
dispatch_once(&onceToken, ^{
sharedDBConnection = [TSStorageManager sharedManager].newDatabaseConnection;
sharedDBConnection = [OWSPrimaryStorage sharedManager].newDatabaseConnection;
OWSAssert([sharedDBConnection isKindOfClass:[OWSDatabaseConnection class]]);
((OWSDatabaseConnection *)sharedDBConnection).canWriteBeforeStorageReady = YES;

View File

@ -6,13 +6,13 @@ NS_ASSUME_NONNULL_BEGIN
typedef void (^OWSDatabaseMigrationCompletion)(void);
@class TSStorageManager;
@class OWSPrimaryStorage;
@interface OWSDatabaseMigrationRunner : NSObject
- (instancetype)initWithStorageManager:(TSStorageManager *)storageManager;
- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage;
@property (nonatomic, readonly) TSStorageManager *storageManager;
@property (nonatomic, readonly) OWSPrimaryStorage *primaryStorage;
/**
* Run any outstanding version migrations.

View File

@ -17,14 +17,14 @@ NS_ASSUME_NONNULL_BEGIN
@implementation OWSDatabaseMigrationRunner
- (instancetype)initWithStorageManager:(TSStorageManager *)storageManager
- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage
{
self = [super init];
if (!self) {
return self;
}
_storageManager = storageManager;
_primaryStorage = primaryStorage;
return self;
}
@ -32,15 +32,15 @@ NS_ASSUME_NONNULL_BEGIN
// This should all migrations which do NOT qualify as safeBlockingMigrations:
- (NSArray<OWSDatabaseMigration *> *)allMigrations
{
TSStorageManager *storageManager = TSStorageManager.sharedManager;
OWSPrimaryStorage *primaryStorage = OWSPrimaryStorage.sharedManager;
return @[
[[OWS100RemoveTSRecipientsMigration alloc] initWithStorageManager:storageManager],
[[OWS102MoveLoggingPreferenceToUserDefaults alloc] initWithStorageManager:storageManager],
[[OWS103EnableVideoCalling alloc] initWithStorageManager:storageManager],
[[OWS104CreateRecipientIdentities alloc] initWithStorageManager:storageManager],
[[OWS105AttachmentFilePaths alloc] initWithStorageManager:storageManager],
[[OWS106EnsureProfileComplete alloc] initWithStorageManager:storageManager],
[[OWS107LegacySounds alloc] initWithStorageManager:storageManager]
[[OWS100RemoveTSRecipientsMigration alloc] initWithPrimaryStorage:primaryStorage],
[[OWS102MoveLoggingPreferenceToUserDefaults alloc] initWithPrimaryStorage:primaryStorage],
[[OWS103EnableVideoCalling alloc] initWithPrimaryStorage:primaryStorage],
[[OWS104CreateRecipientIdentities alloc] initWithPrimaryStorage:primaryStorage],
[[OWS105AttachmentFilePaths alloc] initWithPrimaryStorage:primaryStorage],
[[OWS106EnsureProfileComplete alloc] initWithPrimaryStorage:primaryStorage],
[[OWS107LegacySounds alloc] initWithPrimaryStorage:primaryStorage]
];
}

View File

@ -17,6 +17,7 @@
#import <SignalServiceKit/NSNotificationCenter+OWS.h>
#import <SignalServiceKit/OWSFileSystem.h>
#import <SignalServiceKit/OWSMessageSender.h>
#import <SignalServiceKit/OWSPrimaryStorage.h>
#import <SignalServiceKit/OWSProfileKeyMessage.h>
#import <SignalServiceKit/OWSRequestBuilder.h>
#import <SignalServiceKit/OWSSignalService.h>
@ -24,7 +25,6 @@
#import <SignalServiceKit/TSAccountManager.h>
#import <SignalServiceKit/TSGroupThread.h>
#import <SignalServiceKit/TSNetworkManager.h>
#import <SignalServiceKit/TSStorageManager.h>
#import <SignalServiceKit/TSThread.h>
#import <SignalServiceKit/TSYapDatabaseObject.h>
#import <SignalServiceKit/TextSecureKitEnv.h>
@ -79,14 +79,14 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
- (instancetype)initDefault
{
TSStorageManager *storageManager = [TSStorageManager sharedManager];
OWSPrimaryStorage *primaryStorage = [OWSPrimaryStorage sharedManager];
OWSMessageSender *messageSender = [Environment current].messageSender;
TSNetworkManager *networkManager = [Environment current].networkManager;
return [self initWithStorageManager:storageManager messageSender:messageSender networkManager:networkManager];
return [self initWithPrimaryStorage:primaryStorage messageSender:messageSender networkManager:networkManager];
}
- (instancetype)initWithStorageManager:(TSStorageManager *)storageManager
- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage
messageSender:(OWSMessageSender *)messageSender
networkManager:(TSNetworkManager *)networkManager
{
@ -97,12 +97,12 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
}
OWSAssertIsOnMainThread();
OWSAssert(storageManager);
OWSAssert(primaryStorage);
OWSAssert(messageSender);
OWSAssert(messageSender);
_messageSender = messageSender;
_dbConnection = storageManager.newDatabaseConnection;
_dbConnection = primaryStorage.newDatabaseConnection;
_networkManager = networkManager;
_profileAvatarImageCache = [NSCache new];

View File

@ -12,7 +12,7 @@ public class ProfileFetcherJob: NSObject {
let TAG = "[ProfileFetcherJob]"
let networkManager: TSNetworkManager
let storageManager: TSStorageManager
let primaryStorage: OWSPrimaryStorage
// This property is only accessed on the main queue.
static var fetchDateMap = [String: Date]()
@ -31,7 +31,7 @@ public class ProfileFetcherJob: NSObject {
public init(networkManager: TSNetworkManager, ignoreThrottling: Bool = false) {
self.networkManager = networkManager
self.storageManager = TSStorageManager.shared()
self.primaryStorage = OWSPrimaryStorage.shared()
self.ignoreThrottling = ignoreThrottling
}
@ -130,10 +130,10 @@ public class ProfileFetcherJob: NSObject {
}
private func verifyIdentityUpToDateAsync(recipientId: String, latestIdentityKey: Data) {
storageManager.newDatabaseConnection().asyncReadWrite { (transaction) in
primaryStorage.newDatabaseConnection().asyncReadWrite { (transaction) in
if OWSIdentityManager.shared().saveRemoteIdentity(latestIdentityKey, recipientId: recipientId, protocolContext: transaction) {
Logger.info("\(self.TAG) updated identity key with fetched profile for recipient: \(recipientId)")
self.storageManager.archiveAllSessions(forContact: recipientId, protocolContext: transaction)
self.primaryStorage.archiveAllSessions(forContact: recipientId, protocolContext: transaction)
} else {
// no change in identity.
}

View File

@ -52,16 +52,16 @@ NSString *const OWSPreferencesKeySystemCallLogEnabled = @"OWSPreferencesKeySyste
- (nullable id)tryGetValueForKey:(NSString *)key
{
OWSAssert(key != nil);
return [TSStorageManager.dbReadConnection objectForKey:key inCollection:OWSPreferencesSignalDatabaseCollection];
return [OWSPrimaryStorage.dbReadConnection objectForKey:key inCollection:OWSPreferencesSignalDatabaseCollection];
}
- (void)setValueForKey:(NSString *)key toValue:(nullable id)value
{
OWSAssert(key != nil);
[TSStorageManager.dbReadWriteConnection setObject:value
forKey:key
inCollection:OWSPreferencesSignalDatabaseCollection];
[OWSPrimaryStorage.dbReadWriteConnection setObject:value
forKey:key
inCollection:OWSPreferencesSignalDatabaseCollection];
}
#pragma mark - Specific Preferences

View File

@ -11,8 +11,8 @@ extern NSString *const TSRegistrationErrorUserInfoHTTPStatus;
extern NSString *const RegistrationStateDidChangeNotification;
extern NSString *const kNSNotificationName_LocalNumberDidChange;
@class OWSPrimaryStorage;
@class TSNetworkManager;
@class TSStorageManager;
@class YapDatabaseReadWriteTransaction;
@interface TSAccountManager : NSObject
@ -22,7 +22,7 @@ extern NSString *const kNSNotificationName_LocalNumberDidChange;
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithNetworkManager:(TSNetworkManager *)networkManager
storageManager:(TSStorageManager *)storageManager NS_DESIGNATED_INITIALIZER;
primaryStorage:(OWSPrimaryStorage *)primaryStorage NS_DESIGNATED_INITIALIZER;
+ (instancetype)sharedInstance;

View File

@ -9,11 +9,11 @@
#import "NSNotificationCenter+OWS.h"
#import "NSURLSessionDataTask+StatusCode.h"
#import "OWSError.h"
#import "OWSPrimaryStorage+SessionStore.h"
#import "OWSRequestFactory.h"
#import "SecurityUtils.h"
#import "TSNetworkManager.h"
#import "TSPreKeyManager.h"
#import "TSStorageManager+SessionStore.h"
#import "TSVerifyCodeRequest.h"
#import "YapDatabaseConnection+OWS.h"
#import <YapDatabase/YapDatabase.h>
@ -48,7 +48,7 @@ NSString *const TSAccountManager_ServerSignalingKey = @"TSStorageServerSignaling
@synthesize isRegistered = _isRegistered;
- (instancetype)initWithNetworkManager:(TSNetworkManager *)networkManager
storageManager:(TSStorageManager *)storageManager
primaryStorage:(OWSPrimaryStorage *)primaryStorage
{
self = [super init];
if (!self) {
@ -56,7 +56,7 @@ NSString *const TSAccountManager_ServerSignalingKey = @"TSStorageServerSignaling
}
_networkManager = networkManager;
_dbConnection = [storageManager newDatabaseConnection];
_dbConnection = [primaryStorage newDatabaseConnection];
OWSSingletonAssert();
@ -81,7 +81,7 @@ NSString *const TSAccountManager_ServerSignalingKey = @"TSStorageServerSignaling
static id sharedInstance = nil;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] initWithNetworkManager:[TSNetworkManager sharedManager]
storageManager:[TSStorageManager sharedManager]];
primaryStorage:[OWSPrimaryStorage sharedManager]];
});
return sharedInstance;
@ -106,7 +106,7 @@ NSString *const TSAccountManager_ServerSignalingKey = @"TSStorageServerSignaling
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
[transaction removeAllObjectsInCollection:TSAccountManager_UserAccountCollection];
[[TSStorageManager sharedManager] resetSessionStore:transaction];
[[OWSPrimaryStorage sharedManager] resetSessionStore:transaction];
}];
}
}

View File

@ -7,10 +7,10 @@
#import "NSDate+OWS.h"
#import "NSURLSessionDataTask+StatusCode.h"
#import "OWSIdentityManager.h"
#import "OWSPrimaryStorage+SignedPreKeyStore.h"
#import "OWSRequestFactory.h"
#import "TSNetworkManager.h"
#import "TSStorageHeaders.h"
#import "TSStorageManager+SignedPreKeyStore.h"
// Time before deletion of signed prekeys (measured in seconds)
//
@ -52,30 +52,30 @@ static const NSUInteger kMaxPrekeyUpdateFailureCount = 5;
{
// Only disable message sending if we have failed more than N times
// over a period of at least M days.
TSStorageManager *storageManager = [TSStorageManager sharedManager];
return ([storageManager prekeyUpdateFailureCount] >= kMaxPrekeyUpdateFailureCount &&
[storageManager firstPrekeyUpdateFailureDate] != nil
&& fabs([[storageManager firstPrekeyUpdateFailureDate] timeIntervalSinceNow])
OWSPrimaryStorage *primaryStorage = [OWSPrimaryStorage sharedManager];
return ([primaryStorage prekeyUpdateFailureCount] >= kMaxPrekeyUpdateFailureCount &&
[primaryStorage firstPrekeyUpdateFailureDate] != nil
&& fabs([[primaryStorage firstPrekeyUpdateFailureDate] timeIntervalSinceNow])
>= kSignedPreKeyUpdateFailureMaxFailureDuration);
}
+ (void)incrementPreKeyUpdateFailureCount
{
// Record a prekey update failure.
TSStorageManager *storageManager = [TSStorageManager sharedManager];
int failureCount = [storageManager incrementPrekeyUpdateFailureCount];
if (failureCount == 1 || ![storageManager firstPrekeyUpdateFailureDate]) {
OWSPrimaryStorage *primaryStorage = [OWSPrimaryStorage sharedManager];
int failureCount = [primaryStorage incrementPrekeyUpdateFailureCount];
if (failureCount == 1 || ![primaryStorage firstPrekeyUpdateFailureDate]) {
// If this is the "first" failure, record the timestamp of that
// failure.
[storageManager setFirstPrekeyUpdateFailureDate:[NSDate new]];
[primaryStorage setFirstPrekeyUpdateFailureDate:[NSDate new]];
}
}
+ (void)clearPreKeyUpdateFailureCount
{
TSStorageManager *storageManager = [TSStorageManager sharedManager];
[storageManager clearFirstPrekeyUpdateFailureDate];
[storageManager clearPrekeyUpdateFailureCount];
OWSPrimaryStorage *primaryStorage = [OWSPrimaryStorage sharedManager];
[primaryStorage clearFirstPrekeyUpdateFailureDate];
[primaryStorage clearPrekeyUpdateFailureCount];
}
// We should never dispatch sync to this queue.
@ -133,7 +133,7 @@ static const NSUInteger kMaxPrekeyUpdateFailureCount = 5;
lastPreKeyCheckTimestamp = [NSDate date];
RefreshPreKeysMode modeCopy = mode;
TSStorageManager *storageManager = [TSStorageManager sharedManager];
OWSPrimaryStorage *primaryStorage = [OWSPrimaryStorage sharedManager];
ECKeyPair *identityKeyPair = [[OWSIdentityManager sharedManager] identityKeyPair];
if (!identityKeyPair) {
@ -144,21 +144,21 @@ static const NSUInteger kMaxPrekeyUpdateFailureCount = 5;
modeCopy = RefreshPreKeysMode_SignedAndOneTime;
}
SignedPreKeyRecord *signedPreKey = [storageManager generateRandomSignedRecord];
SignedPreKeyRecord *signedPreKey = [primaryStorage generateRandomSignedRecord];
// Store the new signed key immediately, before it is sent to the
// service to prevent race conditions and other edge cases.
[storageManager storeSignedPreKey:signedPreKey.Id signedPreKeyRecord:signedPreKey];
[primaryStorage storeSignedPreKey:signedPreKey.Id signedPreKeyRecord:signedPreKey];
NSArray *preKeys = nil;
TSRequest *request;
NSString *description;
if (modeCopy == RefreshPreKeysMode_SignedAndOneTime) {
description = @"signed and one-time prekeys";
PreKeyRecord *lastResortPreKey = [storageManager getOrGenerateLastResortKey];
preKeys = [storageManager generatePreKeyRecords];
PreKeyRecord *lastResortPreKey = [primaryStorage getOrGenerateLastResortKey];
preKeys = [primaryStorage generatePreKeyRecords];
// Store the new one-time keys immediately, before they are sent to the
// service to prevent race conditions and other edge cases.
[storageManager storePreKeyRecords:preKeys];
[primaryStorage storePreKeyRecords:preKeys];
request = [OWSRequestFactory registerPrekeysRequestWithPrekeyArray:preKeys
identityKey:identityKeyPair.publicKey
@ -175,10 +175,10 @@ static const NSUInteger kMaxPrekeyUpdateFailureCount = 5;
// Mark signed prekey as accepted by service.
[signedPreKey markAsAcceptedByService];
[storageManager storeSignedPreKey:signedPreKey.Id signedPreKeyRecord:signedPreKey];
[primaryStorage storeSignedPreKey:signedPreKey.Id signedPreKeyRecord:signedPreKey];
// On success, update the "current" signed prekey state.
[storageManager setCurrentSignedPrekeyId:signedPreKey.Id];
[primaryStorage setCurrentSignedPrekeyId:signedPreKey.Id];
successHandler();
@ -261,14 +261,15 @@ static const NSUInteger kMaxPrekeyUpdateFailureCount = 5;
updatePreKeys(RefreshPreKeysMode_SignedAndOneTime);
didUpdatePreKeys = YES;
} else {
TSStorageManager *storageManager = [TSStorageManager sharedManager];
NSNumber *currentSignedPrekeyId = [storageManager currentSignedPrekeyId];
OWSPrimaryStorage *primaryStorage = [OWSPrimaryStorage sharedManager];
NSNumber *currentSignedPrekeyId = [primaryStorage currentSignedPrekeyId];
BOOL shouldUpdateSignedPrekey = NO;
if (!currentSignedPrekeyId) {
DDLogError(@"%@ %s Couldn't find current signed prekey id", self.logTag, __PRETTY_FUNCTION__);
shouldUpdateSignedPrekey = YES;
} else {
SignedPreKeyRecord *currentRecord = [storageManager loadSignedPrekeyOrNil:currentSignedPrekeyId.intValue];
SignedPreKeyRecord *currentRecord =
[primaryStorage loadSignedPrekeyOrNil:currentSignedPrekeyId.intValue];
if (!currentRecord) {
OWSFail(@"%@ %s Couldn't find signed prekey for id: %@",
self.logTag,
@ -301,8 +302,8 @@ static const NSUInteger kMaxPrekeyUpdateFailureCount = 5;
NSNumber *keyId = [responseObject objectForKey:keyIdDictKey];
OWSAssert(keyId);
TSStorageManager *storageManager = [TSStorageManager sharedManager];
NSNumber *currentSignedPrekeyId = [storageManager currentSignedPrekeyId];
OWSPrimaryStorage *primaryStorage = [OWSPrimaryStorage sharedManager];
NSNumber *currentSignedPrekeyId = [primaryStorage currentSignedPrekeyId];
if (!keyId || !currentSignedPrekeyId || ![currentSignedPrekeyId isEqualToNumber:keyId]) {
DDLogError(
@ -343,8 +344,8 @@ static const NSUInteger kMaxPrekeyUpdateFailureCount = 5;
}
+ (void)clearSignedPreKeyRecords {
TSStorageManager *storageManager = [TSStorageManager sharedManager];
NSNumber *currentSignedPrekeyId = [storageManager currentSignedPrekeyId];
OWSPrimaryStorage *primaryStorage = [OWSPrimaryStorage sharedManager];
NSNumber *currentSignedPrekeyId = [primaryStorage currentSignedPrekeyId];
[self clearSignedPreKeyRecordsWithKeyId:currentSignedPrekeyId success:nil];
}
@ -358,12 +359,12 @@ static const NSUInteger kMaxPrekeyUpdateFailureCount = 5;
// We use prekeyQueue to serialize this logic and ensure that only
// one thread is "registering" or "clearing" prekeys at a time.
dispatch_async(TSPreKeyManager.prekeyQueue, ^{
TSStorageManager *storageManager = [TSStorageManager sharedManager];
SignedPreKeyRecord *currentRecord = [storageManager loadSignedPrekeyOrNil:keyId.intValue];
OWSPrimaryStorage *primaryStorage = [OWSPrimaryStorage sharedManager];
SignedPreKeyRecord *currentRecord = [primaryStorage loadSignedPrekeyOrNil:keyId.intValue];
if (!currentRecord) {
OWSFail(@"%@ %s Couldn't find signed prekey for id: %@", self.logTag, __PRETTY_FUNCTION__, keyId);
}
NSArray *allSignedPrekeys = [storageManager loadSignedPreKeys];
NSArray *allSignedPrekeys = [primaryStorage loadSignedPreKeys];
NSArray *oldSignedPrekeys
= (currentRecord != nil ? [self removeCurrentRecord:currentRecord fromRecords:allSignedPrekeys]
: allSignedPrekeys);
@ -416,7 +417,7 @@ static const NSUInteger kMaxPrekeyUpdateFailureCount = 5;
}
oldSignedPreKeyCount--;
[storageManager removeSignedPreKey:signedPrekey.Id];
[primaryStorage removeSignedPreKey:signedPrekey.Id];
}
if (successHandler) {

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 "Contact.h"
#import "Cryptography.h"
#import "OWSPrimaryStorage.h"
#import "PhoneNumber.h"
#import "SignalRecipient.h"
#import "TSAccountManager.h"
#import "TSStorageManager.h"
@import Contacts;
@ -268,7 +268,7 @@ NS_ASSUME_NONNULL_BEGIN
- (NSArray<NSString *> *)textSecureIdentifiers {
__block NSMutableArray *identifiers = [NSMutableArray array];
[TSStorageManager.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
[OWSPrimaryStorage.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
for (PhoneNumber *number in self.parsedPhoneNumbers) {
if ([SignalRecipient recipientWithTextSecureIdentifier:number.toE164 withTransaction:transaction]) {
[identifiers addObject:number.toE164];

View File

@ -6,10 +6,10 @@
#import "Contact.h"
#import "Cryptography.h"
#import "OWSError.h"
#import "OWSPrimaryStorage.h"
#import "OWSRequestFactory.h"
#import "PhoneNumber.h"
#import "TSNetworkManager.h"
#import "TSStorageManager.h"
#import <YapDatabase/YapDatabase.h>
NS_ASSUME_NONNULL_BEGIN
@ -123,7 +123,7 @@ NS_ASSUME_NONNULL_BEGIN
}
NSMutableSet *recipientIds = [NSMutableSet set];
[TSStorageManager.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) {
[OWSPrimaryStorage.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) {
NSArray *allRecipientKeys = [transaction allKeysInCollection:[SignalRecipient collection]];
[recipientIds addObjectsFromArray:allRecipientKeys];
}];
@ -135,7 +135,7 @@ NS_ASSUME_NONNULL_BEGIN
[recipientIds minusSet:matchedIds];
// Cleaning up unregistered identifiers
[TSStorageManager.dbReadWriteConnection
[OWSPrimaryStorage.dbReadWriteConnection
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
for (NSString *identifier in recipientIds) {
SignalRecipient *recipient =
@ -185,7 +185,7 @@ NS_ASSUME_NONNULL_BEGIN
}
// Insert or update contact attributes
[TSStorageManager.dbReadWriteConnection
[OWSPrimaryStorage.dbReadWriteConnection
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
for (NSString *identifier in attributesForIdentifier) {
SignalRecipient *recipient = [SignalRecipient recipientWithTextSecureIdentifier:identifier

View File

@ -5,8 +5,8 @@
#import "SignalAccount.h"
#import "Contact.h"
#import "NSString+SSK.h"
#import "OWSPrimaryStorage.h"
#import "SignalRecipient.h"
#import "TSStorageManager.h"
NS_ASSUME_NONNULL_BEGIN

View File

@ -3,6 +3,7 @@
//
#import "TSThread.h"
#import "OWSPrimaryStorage.h"
#import "OWSReadTracking.h"
#import "TSDatabaseView.h"
#import "TSIncomingMessage.h"
@ -10,7 +11,6 @@
#import "TSInteraction.h"
#import "TSInvalidIdentityKeyReceivingErrorMessage.h"
#import "TSOutgoingMessage.h"
#import "TSStorageManager.h"
#import <YapDatabase/YapDatabase.h>
NS_ASSUME_NONNULL_BEGIN
@ -227,7 +227,7 @@ NS_ASSUME_NONNULL_BEGIN
- (TSInteraction *) lastInteraction {
__block TSInteraction *last;
[TSStorageManager.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
[OWSPrimaryStorage.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
last = [[transaction ext:TSMessageDatabaseViewExtensionName] lastObjectInGroup:self.uniqueId];
}];
return last;
@ -236,7 +236,7 @@ NS_ASSUME_NONNULL_BEGIN
- (TSInteraction *)lastInteractionForInbox
{
__block TSInteraction *last = nil;
[TSStorageManager.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
[OWSPrimaryStorage.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
[[transaction ext:TSMessageDatabaseViewExtensionName]
enumerateRowsInGroup:self.uniqueId
withOptions:NSEnumerationReverse

View File

@ -5,7 +5,7 @@
#import "OWSDevice.h"
#import "NSDate+OWS.h"
#import "OWSError.h"
#import "TSStorageManager.h"
#import "OWSPrimaryStorage.h"
#import "YapDatabaseConnection+OWS.h"
#import "YapDatabaseConnection.h"
#import "YapDatabaseTransaction.h"
@ -14,8 +14,8 @@
NS_ASSUME_NONNULL_BEGIN
uint32_t const OWSDevicePrimaryDeviceId = 1;
NSString *const kTSStorageManager_OWSDeviceCollection = @"kTSStorageManager_OWSDeviceCollection";
NSString *const kTSStorageManager_MayHaveLinkedDevices = @"kTSStorageManager_MayHaveLinkedDevices";
NSString *const kOWSPrimaryStorage_OWSDeviceCollection = @"kOWSPrimaryStorage_OWSDeviceCollection";
NSString *const kOWSPrimaryStorage_MayHaveLinkedDevices = @"kOWSPrimaryStorage_MayHaveLinkedDevices";
@interface OWSDeviceManager ()
@ -46,8 +46,8 @@ NSString *const kTSStorageManager_MayHaveLinkedDevices = @"kTSStorageManager_May
{
OWSAssert(dbConnection);
return [dbConnection boolForKey:kTSStorageManager_MayHaveLinkedDevices
inCollection:kTSStorageManager_OWSDeviceCollection
return [dbConnection boolForKey:kOWSPrimaryStorage_MayHaveLinkedDevices
inCollection:kOWSPrimaryStorage_OWSDeviceCollection
defaultValue:YES];
}
@ -61,13 +61,13 @@ NSString *const kTSStorageManager_MayHaveLinkedDevices = @"kTSStorageManager_May
- (void)clearMayHaveLinkedDevicesIfNotSet
{
// Note that we write async to avoid opening transactions within transactions.
[TSStorageManager.sharedManager.newDatabaseConnection
[OWSPrimaryStorage.sharedManager.newDatabaseConnection
asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
if (![transaction objectForKey:kTSStorageManager_MayHaveLinkedDevices
inCollection:kTSStorageManager_OWSDeviceCollection]) {
if (![transaction objectForKey:kOWSPrimaryStorage_MayHaveLinkedDevices
inCollection:kOWSPrimaryStorage_OWSDeviceCollection]) {
[transaction setObject:@(NO)
forKey:kTSStorageManager_MayHaveLinkedDevices
inCollection:kTSStorageManager_OWSDeviceCollection];
forKey:kOWSPrimaryStorage_MayHaveLinkedDevices
inCollection:kOWSPrimaryStorage_OWSDeviceCollection];
}
}];
}
@ -75,11 +75,11 @@ NSString *const kTSStorageManager_MayHaveLinkedDevices = @"kTSStorageManager_May
- (void)setMayHaveLinkedDevices
{
// Note that we write async to avoid opening transactions within transactions.
[TSStorageManager.sharedManager.newDatabaseConnection
[OWSPrimaryStorage.sharedManager.newDatabaseConnection
asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
[transaction setObject:@(YES)
forKey:kTSStorageManager_MayHaveLinkedDevices
inCollection:kTSStorageManager_OWSDeviceCollection];
forKey:kOWSPrimaryStorage_MayHaveLinkedDevices
inCollection:kOWSPrimaryStorage_OWSDeviceCollection];
}];
}

View File

@ -1,14 +1,14 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
NS_ASSUME_NONNULL_BEGIN
@class OWSIncomingSentMessageTranscript;
@class OWSPrimaryStorage;
@class OWSReadReceiptManager;
@class TSAttachmentStream;
@class TSNetworkManager;
@class TSStorageManager;
@class YapDatabaseReadWriteTransaction;
@protocol ContactsManagerProtocol;
@ -20,7 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithIncomingSentMessageTranscript:(OWSIncomingSentMessageTranscript *)incomingSentMessageTranscript;
- (instancetype)initWithIncomingSentMessageTranscript:(OWSIncomingSentMessageTranscript *)incomingSentMessageTranscript
networkManager:(TSNetworkManager *)networkManager
storageManager:(TSStorageManager *)storageManager
primaryStorage:(OWSPrimaryStorage *)primaryStorage
readReceiptManager:(OWSReadReceiptManager *)readReceiptManager
contactsManager:(id<ContactsManagerProtocol>)contactsManager
NS_DESIGNATED_INITIALIZER;

View File

@ -6,11 +6,11 @@
#import "OWSAttachmentsProcessor.h"
#import "OWSDisappearingMessagesJob.h"
#import "OWSIncomingSentMessageTranscript.h"
#import "OWSPrimaryStorage+SessionStore.h"
#import "OWSReadReceiptManager.h"
#import "TSInfoMessage.h"
#import "TSNetworkManager.h"
#import "TSOutgoingMessage.h"
#import "TSStorageManager+SessionStore.h"
#import "TextSecureKitEnv.h"
NS_ASSUME_NONNULL_BEGIN
@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface OWSRecordTranscriptJob ()
@property (nonatomic, readonly) TSNetworkManager *networkManager;
@property (nonatomic, readonly) TSStorageManager *storageManager;
@property (nonatomic, readonly) OWSPrimaryStorage *primaryStorage;
@property (nonatomic, readonly) OWSReadReceiptManager *readReceiptManager;
@property (nonatomic, readonly) id<ContactsManagerProtocol> contactsManager;
@ -32,14 +32,14 @@ NS_ASSUME_NONNULL_BEGIN
{
return [self initWithIncomingSentMessageTranscript:incomingSentMessageTranscript
networkManager:TSNetworkManager.sharedManager
storageManager:TSStorageManager.sharedManager
primaryStorage:OWSPrimaryStorage.sharedManager
readReceiptManager:OWSReadReceiptManager.sharedManager
contactsManager:[TextSecureKitEnv sharedEnv].contactsManager];
}
- (instancetype)initWithIncomingSentMessageTranscript:(OWSIncomingSentMessageTranscript *)incomingSentMessageTranscript
networkManager:(TSNetworkManager *)networkManager
storageManager:(TSStorageManager *)storageManager
primaryStorage:(OWSPrimaryStorage *)primaryStorage
readReceiptManager:(OWSReadReceiptManager *)readReceiptManager
contactsManager:(id<ContactsManagerProtocol>)contactsManager
{
@ -50,7 +50,7 @@ NS_ASSUME_NONNULL_BEGIN
_incomingSentMessageTranscript = incomingSentMessageTranscript;
_networkManager = networkManager;
_storageManager = storageManager;
_primaryStorage = primaryStorage;
_readReceiptManager = readReceiptManager;
_contactsManager = contactsManager;
@ -68,7 +68,7 @@ NS_ASSUME_NONNULL_BEGIN
TSThread *thread = [transcript threadWithTransaction:transaction];
if (transcript.isEndSessionMessage) {
DDLogInfo(@"%@ EndSession was sent to recipient: %@.", self.logTag, transcript.recipientId);
[self.storageManager deleteAllSessionsForContact:transcript.recipientId protocolContext:transaction];
[self.primaryStorage deleteAllSessionsForContact:transcript.recipientId protocolContext:transaction];
[[[TSInfoMessage alloc] initWithTimestamp:transcript.timestamp
inThread:thread
messageType:TSInfoMessageTypeSessionDidEnd] saveWithTransaction:transaction];
@ -83,7 +83,7 @@ NS_ASSUME_NONNULL_BEGIN
relay:transcript.relay
thread:thread
networkManager:self.networkManager
storageManager:self.storageManager
primaryStorage:self.primaryStorage
transaction:transaction];
// TODO group updates. Currently desktop doesn't support group updates, so not a problem yet.

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
NS_ASSUME_NONNULL_BEGIN
@ -8,13 +8,13 @@ extern NSString *const kAttachmentDownloadProgressNotification;
extern NSString *const kAttachmentDownloadProgressKey;
extern NSString *const kAttachmentDownloadAttachmentIDKey;
@class OWSPrimaryStorage;
@class OWSSignalServiceProtosAttachmentPointer;
@class TSAttachmentPointer;
@class TSAttachmentStream;
@class TSMessage;
@class TSNetworkManager;
@class TSStorageManager;
@class TSThread;
@class OWSSignalServiceProtosAttachmentPointer;
@class YapDatabaseReadWriteTransaction;
/**
@ -34,7 +34,7 @@ extern NSString *const kAttachmentDownloadAttachmentIDKey;
relay:(nullable NSString *)relay
thread:(TSThread *)thread
networkManager:(TSNetworkManager *)networkManager
storageManager:(TSStorageManager *)storageManager
primaryStorage:(OWSPrimaryStorage *)primaryStorage
transaction:(YapDatabaseReadWriteTransaction *)transaction NS_DESIGNATED_INITIALIZER;
/*
@ -42,10 +42,10 @@ extern NSString *const kAttachmentDownloadAttachmentIDKey;
*/
- (instancetype)initWithAttachmentPointer:(TSAttachmentPointer *)attachmentPointer
networkManager:(TSNetworkManager *)networkManager
storageManager:(TSStorageManager *)storageManager NS_DESIGNATED_INITIALIZER;
primaryStorage:(OWSPrimaryStorage *)primaryStorage NS_DESIGNATED_INITIALIZER;
- (void)fetchAttachmentsForMessage:(nullable TSMessage *)message
storageManager:(TSStorageManager *)storageManager
primaryStorage:(OWSPrimaryStorage *)primaryStorage
success:(void (^)(TSAttachmentStream *attachmentStream))successHandler
failure:(void (^)(NSError *error))failureHandler;
- (void)fetchAttachmentsForMessage:(nullable TSMessage *)message

View File

@ -9,6 +9,7 @@
#import "NSNotificationCenter+OWS.h"
#import "OWSBackgroundTask.h"
#import "OWSError.h"
#import "OWSPrimaryStorage.h"
#import "OWSRequestFactory.h"
#import "OWSSignalServiceProtos.pb.h"
#import "TSAttachmentPointer.h"
@ -18,7 +19,6 @@
#import "TSInfoMessage.h"
#import "TSMessage.h"
#import "TSNetworkManager.h"
#import "TSStorageManager.h"
#import "TSThread.h"
#import <YapDatabase/YapDatabaseConnection.h>
@ -35,7 +35,7 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
@interface OWSAttachmentsProcessor ()
@property (nonatomic, readonly) TSNetworkManager *networkManager;
@property (nonatomic, readonly) TSStorageManager *storageManager;
@property (nonatomic, readonly) OWSPrimaryStorage *primaryStorage;
@property (nonatomic, readonly) NSArray<TSAttachmentPointer *> *supportedAttachmentPointers;
@end
@ -44,7 +44,7 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
- (instancetype)initWithAttachmentPointer:(TSAttachmentPointer *)attachmentPointer
networkManager:(TSNetworkManager *)networkManager
storageManager:(TSStorageManager *)storageManager
primaryStorage:(OWSPrimaryStorage *)primaryStorage
{
self = [super init];
if (!self) {
@ -52,7 +52,7 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
}
_networkManager = networkManager;
_storageManager = storageManager;
_primaryStorage = primaryStorage;
_supportedAttachmentPointers = @[ attachmentPointer ];
_supportedAttachmentIds = @[ attachmentPointer.uniqueId ];
@ -65,7 +65,7 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
relay:(nullable NSString *)relay
thread:(TSThread *)thread
networkManager:(TSNetworkManager *)networkManager
storageManager:(TSStorageManager *)storageManager
primaryStorage:(OWSPrimaryStorage *)primaryStorage
transaction:(YapDatabaseReadWriteTransaction *)transaction
{
self = [super init];
@ -74,7 +74,7 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
}
_networkManager = networkManager;
_storageManager = storageManager;
_primaryStorage = primaryStorage;
NSMutableArray<NSString *> *attachmentIds = [NSMutableArray new];
NSMutableArray<TSAttachmentPointer *> *supportedAttachmentPointers = [NSMutableArray new];
@ -121,11 +121,11 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
}
- (void)fetchAttachmentsForMessage:(nullable TSMessage *)message
storageManager:(TSStorageManager *)storageManager
primaryStorage:(OWSPrimaryStorage *)primaryStorage
success:(void (^)(TSAttachmentStream *attachmentStream))successHandler
failure:(void (^)(NSError *error))failureHandler
{
[[storageManager newDatabaseConnection] readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[[primaryStorage newDatabaseConnection] readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[self fetchAttachmentsForMessage:message
transaction:transaction
success:successHandler

View File

@ -1,15 +1,15 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSIncomingSentMessageTranscript.h"
#import "OWSMessageManager.h"
#import "OWSPrimaryStorage.h"
#import "OWSSignalServiceProtos.pb.h"
#import "TSContactThread.h"
#import "TSGroupModel.h"
#import "TSGroupThread.h"
#import "TSOutgoingMessage.h"
#import "TSStorageManager.h"
#import "TSThread.h"
NS_ASSUME_NONNULL_BEGIN

View File

@ -1,11 +1,11 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSInteraction.h"
#import "NSDate+OWS.h"
#import "OWSPrimaryStorage+messageIDs.h"
#import "TSDatabaseSecondaryIndexes.h"
#import "TSStorageManager+messageIDs.h"
#import "TSThread.h"
NS_ASSUME_NONNULL_BEGIN
@ -133,7 +133,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)saveWithTransaction:(YapDatabaseReadWriteTransaction *)transaction {
if (!self.uniqueId) {
self.uniqueId = [TSStorageManager getAndIncrementMessageIdWithTransaction:transaction];
self.uniqueId = [OWSPrimaryStorage getAndIncrementMessageIdWithTransaction:transaction];
}
[super saveWithTransaction:transaction];

View File

@ -7,11 +7,11 @@
#import "OWSIdentityManager.h"
#import "OWSMessageManager.h"
#import "OWSMessageReceiver.h"
#import "OWSPrimaryStorage+SessionStore.h"
#import "OWSPrimaryStorage.h"
#import "TSContactThread.h"
#import "TSDatabaseView.h"
#import "TSErrorMessage_privateConstructor.h"
#import "TSStorageManager+SessionStore.h"
#import "TSStorageManager.h"
#import <AxolotlKit/NSData+keyVersionByte.h>
#import <AxolotlKit/PreKeyWhisperMessage.h>
#import <YapDatabase/YapDatabaseTransaction.h>

View File

@ -5,13 +5,13 @@
#import "TSInvalidIdentityKeySendingErrorMessage.h"
#import "OWSFingerprint.h"
#import "OWSIdentityManager.h"
#import "OWSPrimaryStorage+SessionStore.h"
#import "OWSPrimaryStorage.h"
#import "PreKeyBundle+jsonDict.h"
#import "SignalRecipient.h"
#import "TSContactThread.h"
#import "TSErrorMessage_privateConstructor.h"
#import "TSOutgoingMessage.h"
#import "TSStorageManager+SessionStore.h"
#import "TSStorageManager.h"
#import <AxolotlKit/NSData+keyVersionByte.h>
NS_ASSUME_NONNULL_BEGIN

View File

@ -8,12 +8,12 @@
#import "NSArray+OWS.h"
#import "OWSBackgroundTask.h"
#import "OWSMessageManager.h"
#import "OWSPrimaryStorage+SessionStore.h"
#import "OWSPrimaryStorage.h"
#import "OWSQueues.h"
#import "OWSSignalServiceProtos.pb.h"
#import "OWSStorage.h"
#import "TSDatabaseView.h"
#import "TSStorageManager+SessionStore.h"
#import "TSStorageManager.h"
#import "TSYapDatabaseObject.h"
#import "Threading.h"
#import <YapDatabase/YapDatabaseAutoView.h>
@ -227,7 +227,7 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
@property (nonatomic) BOOL isDrainingQueue;
- (instancetype)initWithMessagesManager:(OWSMessageManager *)messagesManager
storageManager:(TSStorageManager *)storageManager
primaryStorage:(OWSPrimaryStorage *)primaryStorage
finder:(OWSMessageContentJobFinder *)finder NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;
@ -238,7 +238,7 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
@implementation OWSMessageContentQueue
- (instancetype)initWithMessagesManager:(OWSMessageManager *)messagesManager
storageManager:(TSStorageManager *)storageManager
primaryStorage:(OWSPrimaryStorage *)primaryStorage
finder:(OWSMessageContentJobFinder *)finder
{
OWSSingletonAssert();
@ -249,7 +249,7 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
}
_messagesManager = messagesManager;
_dbConnection = [storageManager newDatabaseConnection];
_dbConnection = [primaryStorage newDatabaseConnection];
_finder = finder;
_isDrainingQueue = NO;
@ -370,7 +370,7 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
- (instancetype)initWithDBConnection:(YapDatabaseConnection *)dbConnection
messagesManager:(OWSMessageManager *)messagesManager
storageManager:(TSStorageManager *)storageManager
primaryStorage:(OWSPrimaryStorage *)primaryStorage
{
OWSSingletonAssert();
@ -381,7 +381,7 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
OWSMessageContentJobFinder *finder = [[OWSMessageContentJobFinder alloc] initWithDBConnection:dbConnection];
OWSMessageContentQueue *processingQueue = [[OWSMessageContentQueue alloc] initWithMessagesManager:messagesManager
storageManager:storageManager
primaryStorage:primaryStorage
finder:finder];
_processingQueue = processingQueue;
@ -392,11 +392,11 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
- (instancetype)initDefault
{
// For concurrency coherency we use the same dbConnection to persist and read the unprocessed envelopes
YapDatabaseConnection *dbConnection = [[TSStorageManager sharedManager] newDatabaseConnection];
YapDatabaseConnection *dbConnection = [[OWSPrimaryStorage sharedManager] newDatabaseConnection];
OWSMessageManager *messagesManager = [OWSMessageManager sharedManager];
TSStorageManager *storageManager = [TSStorageManager sharedManager];
OWSPrimaryStorage *primaryStorage = [OWSPrimaryStorage sharedManager];
return [self initWithDBConnection:dbConnection messagesManager:messagesManager storageManager:storageManager];
return [self initWithDBConnection:dbConnection messagesManager:messagesManager primaryStorage:primaryStorage];
}
+ (instancetype)sharedInstance

View File

@ -8,7 +8,7 @@
#import "NSNotificationCenter+OWS.h"
#import "OWSBlockedPhoneNumbersMessage.h"
#import "OWSMessageSender.h"
#import "TSStorageManager.h"
#import "OWSPrimaryStorage.h"
#import "TextSecureKitEnv.h"
#import "YapDatabaseConnection+OWS.h"
@ -50,13 +50,14 @@ NSString *const kOWSBlockingManager_SyncedBlockedPhoneNumbersKey = @"kOWSBlockin
- (instancetype)initDefault
{
TSStorageManager *storageManager = [TSStorageManager sharedManager];
OWSPrimaryStorage *primaryStorage = [OWSPrimaryStorage sharedManager];
OWSMessageSender *messageSender = [TextSecureKitEnv sharedEnv].messageSender;
return [self initWithStorageManager:storageManager messageSender:messageSender];
return [self initWithPrimaryStorage:primaryStorage messageSender:messageSender];
}
- (instancetype)initWithStorageManager:(TSStorageManager *)storageManager messageSender:(OWSMessageSender *)messageSender
- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage
messageSender:(OWSMessageSender *)messageSender
{
self = [super init];
@ -64,10 +65,10 @@ NSString *const kOWSBlockingManager_SyncedBlockedPhoneNumbersKey = @"kOWSBlockin
return self;
}
OWSAssert(storageManager);
OWSAssert(primaryStorage);
OWSAssert(messageSender);
_dbConnection = storageManager.newDatabaseConnection;
_dbConnection = primaryStorage.newDatabaseConnection;
_messageSender = messageSender;
OWSSingletonAssert();

View File

@ -4,9 +4,9 @@
NS_ASSUME_NONNULL_BEGIN
@class OWSPrimaryStorage;
@class OWSStorage;
@class TSMessage;
@class TSStorageManager;
@class TSThread;
@class YapDatabaseReadTransaction;

View File

@ -4,9 +4,9 @@
#import "OWSDisappearingMessagesFinder.h"
#import "NSDate+OWS.h"
#import "OWSPrimaryStorage.h"
#import "TSMessage.h"
#import "TSOutgoingMessage.h"
#import "TSStorageManager.h"
#import "TSThread.h"
#import <YapDatabase/YapDatabase.h>
#import <YapDatabase/YapDatabaseQuery.h>

View File

@ -1,12 +1,13 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
NS_ASSUME_NONNULL_BEGIN
@class TSStorageManager;
@class OWSPrimaryStorage;
@class TSMessage;
@class TSThread;
@protocol ContactsManagerProtocol;
@interface OWSDisappearingMessagesJob : NSObject

View File

@ -12,9 +12,9 @@
#import "OWSDisappearingConfigurationUpdateInfoMessage.h"
#import "OWSDisappearingMessagesConfiguration.h"
#import "OWSDisappearingMessagesFinder.h"
#import "OWSPrimaryStorage.h"
#import "TSIncomingMessage.h"
#import "TSMessage.h"
#import "TSStorageManager.h"
NS_ASSUME_NONNULL_BEGIN
// Can we move to Signal-iOS?
@ -40,19 +40,19 @@ NS_ASSUME_NONNULL_BEGIN
static OWSDisappearingMessagesJob *sharedJob = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedJob = [[self alloc] initWithStorageManager:[TSStorageManager sharedManager]];
sharedJob = [[self alloc] initWithPrimaryStorage:[OWSPrimaryStorage sharedManager]];
});
return sharedJob;
}
- (instancetype)initWithStorageManager:(TSStorageManager *)storageManager
- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage
{
self = [super init];
if (!self) {
return self;
}
_databaseConnection = storageManager.newDatabaseConnection;
_databaseConnection = primaryStorage.newDatabaseConnection;
_disappearingMessagesFinder = [OWSDisappearingMessagesFinder new];
OWSSingletonAssert();

View File

@ -4,20 +4,20 @@
NS_ASSUME_NONNULL_BEGIN
@class OWSPrimaryStorage;
@class OWSStorage;
@class TSStorageManager;
@interface OWSFailedAttachmentDownloadsJob : NSObject
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithStorageManager:(TSStorageManager *)storageManager NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage NS_DESIGNATED_INITIALIZER;
- (void)run;
/**
* Database extensions required for class to work.
*/
+ (void)asyncRegisterDatabaseExtensionsWithStorageManager:(OWSStorage *)storage;
+ (void)asyncRegisterDatabaseExtensionsWithPrimaryStorage:(OWSStorage *)storage;
#ifdef DEBUG
/**

View File

@ -3,8 +3,8 @@
//
#import "OWSFailedAttachmentDownloadsJob.h"
#import "OWSPrimaryStorage.h"
#import "TSAttachmentPointer.h"
#import "TSStorageManager.h"
#import <YapDatabase/YapDatabase.h>
#import <YapDatabase/YapDatabaseQuery.h>
#import <YapDatabase/YapDatabaseSecondaryIndex.h>
@ -16,7 +16,7 @@ static NSString *const OWSFailedAttachmentDownloadsJobAttachmentStateIndex = @"i
@interface OWSFailedAttachmentDownloadsJob ()
@property (nonatomic, readonly) TSStorageManager *storageManager;
@property (nonatomic, readonly) OWSPrimaryStorage *primaryStorage;
@end
@ -24,14 +24,14 @@ static NSString *const OWSFailedAttachmentDownloadsJobAttachmentStateIndex = @"i
@implementation OWSFailedAttachmentDownloadsJob
- (instancetype)initWithStorageManager:(TSStorageManager *)storageManager
- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage
{
self = [super init];
if (!self) {
return self;
}
_storageManager = storageManager;
_primaryStorage = primaryStorage;
return self;
}
@ -77,7 +77,7 @@ static NSString *const OWSFailedAttachmentDownloadsJobAttachmentStateIndex = @"i
- (void)run
{
__block uint count = 0;
[[self.storageManager newDatabaseConnection]
[[self.primaryStorage newDatabaseConnection]
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
[self enumerateAttemptingOutAttachmentsWithBlock:^(TSAttachmentPointer *attachment) {
// sanity check
@ -121,12 +121,12 @@ static NSString *const OWSFailedAttachmentDownloadsJobAttachmentStateIndex = @"i
// Useful for tests, don't use in app startup path because it's slow.
- (void)blockingRegisterDatabaseExtensions
{
[self.storageManager registerExtension:[self.class indexDatabaseExtension]
[self.primaryStorage registerExtension:[self.class indexDatabaseExtension]
withName:OWSFailedAttachmentDownloadsJobAttachmentStateIndex];
}
#endif
+ (void)asyncRegisterDatabaseExtensionsWithStorageManager:(OWSStorage *)storage
+ (void)asyncRegisterDatabaseExtensionsWithPrimaryStorage:(OWSStorage *)storage
{
[storage asyncRegisterExtension:[self indexDatabaseExtension]
withName:OWSFailedAttachmentDownloadsJobAttachmentStateIndex];

View File

@ -4,20 +4,20 @@
NS_ASSUME_NONNULL_BEGIN
@class OWSPrimaryStorage;
@class OWSStorage;
@class TSStorageManager;
@interface OWSFailedMessagesJob : NSObject
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithStorageManager:(TSStorageManager *)storageManager NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage NS_DESIGNATED_INITIALIZER;
- (void)run;
/**
* Database extensions required for class to work.
*/
+ (void)asyncRegisterDatabaseExtensionsWithStorageManager:(OWSStorage *)storage;
+ (void)asyncRegisterDatabaseExtensionsWithPrimaryStorage:(OWSStorage *)storage;
#ifdef DEBUG
/**

View File

@ -3,9 +3,9 @@
//
#import "OWSFailedMessagesJob.h"
#import "OWSPrimaryStorage.h"
#import "TSMessage.h"
#import "TSOutgoingMessage.h"
#import "TSStorageManager.h"
#import <YapDatabase/YapDatabase.h>
#import <YapDatabase/YapDatabaseQuery.h>
#import <YapDatabase/YapDatabaseSecondaryIndex.h>
@ -17,7 +17,7 @@ static NSString *const OWSFailedMessagesJobMessageStateIndex = @"index_outoing_m
@interface OWSFailedMessagesJob ()
@property (nonatomic, readonly) TSStorageManager *storageManager;
@property (nonatomic, readonly) OWSPrimaryStorage *primaryStorage;
@end
@ -25,14 +25,14 @@ static NSString *const OWSFailedMessagesJobMessageStateIndex = @"index_outoing_m
@implementation OWSFailedMessagesJob
- (instancetype)initWithStorageManager:(TSStorageManager *)storageManager
- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage
{
self = [super init];
if (!self) {
return self;
}
_storageManager = storageManager;
_primaryStorage = primaryStorage;
return self;
}
@ -79,7 +79,7 @@ static NSString *const OWSFailedMessagesJobMessageStateIndex = @"index_outoing_m
{
__block uint count = 0;
[[self.storageManager newDatabaseConnection]
[[self.primaryStorage newDatabaseConnection]
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
[self enumerateAttemptingOutMessagesWithBlock:^(TSOutgoingMessage *message) {
// sanity check
@ -131,12 +131,12 @@ static NSString *const OWSFailedMessagesJobMessageStateIndex = @"index_outoing_m
// Useful for tests, don't use in app startup path because it's slow.
- (void)blockingRegisterDatabaseExtensions
{
[self.storageManager registerExtension:[self.class indexDatabaseExtension]
[self.primaryStorage registerExtension:[self.class indexDatabaseExtension]
withName:OWSFailedMessagesJobMessageStateIndex];
}
#endif
+ (void)asyncRegisterDatabaseExtensionsWithStorageManager:(OWSStorage *)storage
+ (void)asyncRegisterDatabaseExtensionsWithPrimaryStorage:(OWSStorage *)storage
{
[storage asyncRegisterExtension:[self indexDatabaseExtension] withName:OWSFailedMessagesJobMessageStateIndex];
}

View File

@ -7,7 +7,7 @@
NS_ASSUME_NONNULL_BEGIN
extern NSString *const TSStorageManagerTrustedKeysCollection;
extern NSString *const OWSPrimaryStorageTrustedKeysCollection;
// This notification will be fired whenever identities are created
// or their verification state changes.

View File

@ -12,6 +12,8 @@
#import "OWSFileSystem.h"
#import "OWSMessageSender.h"
#import "OWSOutgoingNullMessage.h"
#import "OWSPrimaryStorage+sessionStore.h"
#import "OWSPrimaryStorage.h"
#import "OWSRecipientIdentity.h"
#import "OWSVerificationStateChangeMessage.h"
#import "OWSVerificationStateSyncMessage.h"
@ -19,8 +21,6 @@
#import "TSContactThread.h"
#import "TSErrorMessage.h"
#import "TSGroupThread.h"
#import "TSStorageManager+sessionStore.h"
#import "TSStorageManager.h"
#import "TextSecureKitEnv.h"
#import "YapDatabaseConnection+OWS.h"
#import "YapDatabaseTransaction+OWS.h"
@ -31,11 +31,11 @@
NS_ASSUME_NONNULL_BEGIN
// Storing our own identity key
NSString *const TSStorageManagerIdentityKeyStoreIdentityKey = @"TSStorageManagerIdentityKeyStoreIdentityKey";
NSString *const TSStorageManagerIdentityKeyStoreCollection = @"TSStorageManagerIdentityKeyStoreCollection";
NSString *const OWSPrimaryStorageIdentityKeyStoreIdentityKey = @"TSStorageManagerIdentityKeyStoreIdentityKey";
NSString *const OWSPrimaryStorageIdentityKeyStoreCollection = @"TSStorageManagerIdentityKeyStoreCollection";
// Storing recipients identity keys
NSString *const TSStorageManagerTrustedKeysCollection = @"TSStorageManagerTrustedKeysCollection";
NSString *const OWSPrimaryStorageTrustedKeysCollection = @"TSStorageManagerTrustedKeysCollection";
NSString *const OWSIdentityManager_QueuedVerificationStateSyncMessages =
@"OWSIdentityManager_QueuedVerificationStateSyncMessages";
@ -55,7 +55,7 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
@interface OWSIdentityManager ()
@property (nonatomic, readonly) TSStorageManager *storageManager;
@property (nonatomic, readonly) OWSPrimaryStorage *primaryStorage;
@property (nonatomic, readonly) YapDatabaseConnection *dbConnection;
@property (nonatomic, readonly) OWSMessageSender *messageSender;
@ -77,13 +77,13 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
- (instancetype)initDefault
{
TSStorageManager *storageManager = [TSStorageManager sharedManager];
OWSPrimaryStorage *primaryStorage = [OWSPrimaryStorage sharedManager];
OWSMessageSender *messageSender = [TextSecureKitEnv sharedEnv].messageSender;
return [self initWithStorageManager:storageManager messageSender:messageSender];
return [self initWithPrimaryStorage:primaryStorage messageSender:messageSender];
}
- (instancetype)initWithStorageManager:(TSStorageManager *)storageManager
- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage
messageSender:(OWSMessageSender *)messageSender
{
self = [super init];
@ -92,11 +92,11 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
return self;
}
OWSAssert(storageManager);
OWSAssert(primaryStorage);
OWSAssert(messageSender);
_storageManager = storageManager;
_dbConnection = storageManager.newDatabaseConnection;
_primaryStorage = primaryStorage;
_dbConnection = primaryStorage.newDatabaseConnection;
self.dbConnection.objectCacheEnabled = NO;
_messageSender = messageSender;
@ -123,8 +123,8 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
- (void)generateNewIdentityKey
{
[self.dbConnection setObject:[Curve25519 generateKeyPair]
forKey:TSStorageManagerIdentityKeyStoreIdentityKey
inCollection:TSStorageManagerIdentityKeyStoreCollection];
forKey:OWSPrimaryStorageIdentityKeyStoreIdentityKey
inCollection:OWSPrimaryStorageIdentityKeyStoreCollection];
}
- (nullable NSData *)identityKeyForRecipientId:(NSString *)recipientId
@ -169,8 +169,8 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
{
OWSAssert(transaction);
ECKeyPair *_Nullable identityKeyPair = [transaction keyPairForKey:TSStorageManagerIdentityKeyStoreIdentityKey
inCollection:TSStorageManagerIdentityKeyStoreCollection];
ECKeyPair *_Nullable identityKeyPair = [transaction keyPairForKey:OWSPrimaryStorageIdentityKeyStoreIdentityKey
inCollection:OWSPrimaryStorageIdentityKeyStoreCollection];
return identityKeyPair;
}
@ -206,11 +206,11 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
YapDatabaseReadWriteTransaction *transaction = protocolContext;
// Deprecated. We actually no longer use the TSStorageManagerTrustedKeysCollection for trust
// Deprecated. We actually no longer use the OWSPrimaryStorageTrustedKeysCollection for trust
// decisions, but it's desirable to try to keep it up to date with our trusted identitys
// while we're switching between versions, e.g. so we don't get into a state where we have a
// session for an identity not in our key store.
[transaction setObject:identityKey forKey:recipientId inCollection:TSStorageManagerTrustedKeysCollection];
[transaction setObject:identityKey forKey:recipientId inCollection:OWSPrimaryStorageTrustedKeysCollection];
OWSRecipientIdentity *existingIdentity =
[OWSRecipientIdentity fetchObjectWithUniqueID:recipientId transaction:transaction];
@ -257,7 +257,7 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
createdAt:[NSDate new]
verificationState:verificationState] saveWithTransaction:transaction];
[self.storageManager archiveAllSessionsForContact:recipientId protocolContext:protocolContext];
[self.primaryStorage archiveAllSessionsForContact:recipientId protocolContext:protocolContext];
// Cancel any pending verification state sync messages for this recipient.
[self clearSyncMessageForRecipientId:recipientId transaction:transaction];
@ -887,18 +887,18 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
OWSAssert(transaction);
NSMutableArray<NSString *> *identityKeysToRemove = [NSMutableArray new];
[transaction enumerateKeysInCollection:TSStorageManagerIdentityKeyStoreCollection
[transaction enumerateKeysInCollection:OWSPrimaryStorageIdentityKeyStoreCollection
usingBlock:^(NSString *_Nonnull key, BOOL *_Nonnull stop) {
if ([key isEqualToString:TSStorageManagerIdentityKeyStoreIdentityKey]) {
if ([key isEqualToString:OWSPrimaryStorageIdentityKeyStoreIdentityKey]) {
// Don't delete our own key.
return;
}
[identityKeysToRemove addObject:key];
}];
for (NSString *key in identityKeysToRemove) {
[transaction removeObjectForKey:key inCollection:TSStorageManagerIdentityKeyStoreCollection];
[transaction removeObjectForKey:key inCollection:OWSPrimaryStorageIdentityKeyStoreCollection];
}
[transaction removeAllObjectsInCollection:TSStorageManagerTrustedKeysCollection];
[transaction removeAllObjectsInCollection:OWSPrimaryStorageTrustedKeysCollection];
}
- (NSString *)identityKeySnapshotFilePath
@ -919,9 +919,9 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
{
OWSAssert(transaction);
[transaction snapshotCollection:TSStorageManagerIdentityKeyStoreCollection
[transaction snapshotCollection:OWSPrimaryStorageIdentityKeyStoreCollection
snapshotFilePath:self.identityKeySnapshotFilePath];
[transaction snapshotCollection:TSStorageManagerTrustedKeysCollection
[transaction snapshotCollection:OWSPrimaryStorageTrustedKeysCollection
snapshotFilePath:self.trustedKeySnapshotFilePath];
}
@ -929,9 +929,9 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
{
OWSAssert(transaction);
[transaction restoreSnapshotOfCollection:TSStorageManagerIdentityKeyStoreCollection
[transaction restoreSnapshotOfCollection:OWSPrimaryStorageIdentityKeyStoreCollection
snapshotFilePath:self.identityKeySnapshotFilePath];
[transaction restoreSnapshotOfCollection:TSStorageManagerTrustedKeysCollection
[transaction restoreSnapshotOfCollection:OWSPrimaryStorageTrustedKeysCollection
snapshotFilePath:self.trustedKeySnapshotFilePath];
}

View File

@ -9,15 +9,15 @@
#import "OWSBlockingManager.h"
#import "OWSError.h"
#import "OWSIdentityManager.h"
#import "OWSPrimaryStorage+PreKeyStore.h"
#import "OWSPrimaryStorage+SessionStore.h"
#import "OWSPrimaryStorage+SignedPreKeyStore.h"
#import "OWSPrimaryStorage.h"
#import "OWSSignalServiceProtos.pb.h"
#import "TSAccountManager.h"
#import "TSContactThread.h"
#import "TSErrorMessage.h"
#import "TSPreKeyManager.h"
#import "TSStorageManager+PreKeyStore.h"
#import "TSStorageManager+SessionStore.h"
#import "TSStorageManager+SignedPreKeyStore.h"
#import "TSStorageManager.h"
#import "TextSecureKitEnv.h"
#import <AxolotlKit/AxolotlExceptions.h>
#import <AxolotlKit/SessionCipher.h>
@ -26,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface OWSMessageDecrypter ()
@property (nonatomic, readonly) TSStorageManager *storageManager;
@property (nonatomic, readonly) OWSPrimaryStorage *primaryStorage;
@property (nonatomic, readonly) YapDatabaseConnection *dbConnection;
@property (nonatomic, readonly) OWSBlockingManager *blockingManager;
@property (nonatomic, readonly) OWSIdentityManager *identityManager;
@ -49,14 +49,14 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initDefault
{
TSStorageManager *storageManager = [TSStorageManager sharedManager];
OWSPrimaryStorage *primaryStorage = [OWSPrimaryStorage sharedManager];
OWSIdentityManager *identityManager = [OWSIdentityManager sharedManager];
OWSBlockingManager *blockingManager = [OWSBlockingManager sharedManager];
return [self initWithStorageManager:storageManager identityManager:identityManager blockingManager:blockingManager];
return [self initWithPrimaryStorage:primaryStorage identityManager:identityManager blockingManager:blockingManager];
}
- (instancetype)initWithStorageManager:(TSStorageManager *)storageManager
- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage
identityManager:(OWSIdentityManager *)identityManager
blockingManager:(OWSBlockingManager *)blockingManager
{
@ -66,11 +66,11 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
_storageManager = storageManager;
_primaryStorage = primaryStorage;
_identityManager = identityManager;
_blockingManager = blockingManager;
_dbConnection = storageManager.newDatabaseConnection;
_dbConnection = primaryStorage.newDatabaseConnection;
OWSSingletonAssert();
@ -223,7 +223,7 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(successBlock);
OWSAssert(failureBlock);
TSStorageManager *storageManager = self.storageManager;
OWSPrimaryStorage *primaryStorage = self.primaryStorage;
NSString *recipientId = envelope.source;
int deviceId = envelope.sourceDevice;
@ -239,9 +239,9 @@ NS_ASSUME_NONNULL_BEGIN
asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
@try {
id<CipherMessage> cipherMessage = cipherMessageBlock(encryptedData);
SessionCipher *cipher = [[SessionCipher alloc] initWithSessionStore:storageManager
preKeyStore:storageManager
signedPreKeyStore:storageManager
SessionCipher *cipher = [[SessionCipher alloc] initWithSessionStore:primaryStorage
preKeyStore:primaryStorage
signedPreKeyStore:primaryStorage
identityKeyStore:self.identityManager
recipientId:recipientId
deviceId:deviceId];

View File

@ -23,6 +23,8 @@
#import "OWSIncomingSentMessageTranscript.h"
#import "OWSMessageSender.h"
#import "OWSMessageUtils.h"
#import "OWSPrimaryStorage+SessionStore.h"
#import "OWSPrimaryStorage.h"
#import "OWSReadReceiptManager.h"
#import "OWSRecordTranscriptJob.h"
#import "OWSSyncConfigurationMessage.h"
@ -39,8 +41,6 @@
#import "TSInfoMessage.h"
#import "TSNetworkManager.h"
#import "TSOutgoingMessage.h"
#import "TSStorageManager+SessionStore.h"
#import "TSStorageManager.h"
#import "TextSecureKitEnv.h"
#import <YapDatabase/YapDatabase.h>
@ -50,7 +50,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly) id<OWSCallMessageHandler> callMessageHandler;
@property (nonatomic, readonly) id<ContactsManagerProtocol> contactsManager;
@property (nonatomic, readonly) TSStorageManager *storageManager;
@property (nonatomic, readonly) OWSPrimaryStorage *primaryStorage;
@property (nonatomic, readonly) OWSMessageSender *messageSender;
@property (nonatomic, readonly) OWSIncomingMessageFinder *incomingMessageFinder;
@property (nonatomic, readonly) OWSBlockingManager *blockingManager;
@ -77,7 +77,7 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initDefault
{
TSNetworkManager *networkManager = [TSNetworkManager sharedManager];
TSStorageManager *storageManager = [TSStorageManager sharedManager];
OWSPrimaryStorage *primaryStorage = [OWSPrimaryStorage sharedManager];
id<ContactsManagerProtocol> contactsManager = [TextSecureKitEnv sharedEnv].contactsManager;
id<OWSCallMessageHandler> callMessageHandler = [TextSecureKitEnv sharedEnv].callMessageHandler;
OWSIdentityManager *identityManager = [OWSIdentityManager sharedManager];
@ -85,7 +85,7 @@ NS_ASSUME_NONNULL_BEGIN
return [self initWithNetworkManager:networkManager
storageManager:storageManager
primaryStorage:primaryStorage
callMessageHandler:callMessageHandler
contactsManager:contactsManager
identityManager:identityManager
@ -93,7 +93,7 @@ NS_ASSUME_NONNULL_BEGIN
}
- (instancetype)initWithNetworkManager:(TSNetworkManager *)networkManager
storageManager:(TSStorageManager *)storageManager
primaryStorage:(OWSPrimaryStorage *)primaryStorage
callMessageHandler:(id<OWSCallMessageHandler>)callMessageHandler
contactsManager:(id<ContactsManagerProtocol>)contactsManager
identityManager:(OWSIdentityManager *)identityManager
@ -105,15 +105,15 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
_storageManager = storageManager;
_primaryStorage = primaryStorage;
_networkManager = networkManager;
_callMessageHandler = callMessageHandler;
_contactsManager = contactsManager;
_identityManager = identityManager;
_messageSender = messageSender;
_dbConnection = storageManager.newDatabaseConnection;
_incomingMessageFinder = [[OWSIncomingMessageFinder alloc] initWithStorageManager:storageManager];
_dbConnection = primaryStorage.newDatabaseConnection;
_incomingMessageFinder = [[OWSIncomingMessageFinder alloc] initWithPrimaryStorage:primaryStorage];
_blockingManager = [OWSBlockingManager sharedManager];
OWSSingletonAssert();
@ -129,7 +129,7 @@ NS_ASSUME_NONNULL_BEGIN
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yapDatabaseModified:)
name:YapDatabaseModifiedNotification
object:TSStorageManager.sharedManager.dbNotificationObject];
object:OWSPrimaryStorage.sharedManager.dbNotificationObject];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yapDatabaseModified:)
name:YapDatabaseModifiedExternallyNotification
@ -515,7 +515,7 @@ NS_ASSUME_NONNULL_BEGIN
relay:envelope.relay
thread:groupThread
networkManager:self.networkManager
storageManager:self.storageManager
primaryStorage:self.primaryStorage
transaction:transaction];
if (!attachmentsProcessor.hasSupportedAttachments) {
@ -555,7 +555,7 @@ NS_ASSUME_NONNULL_BEGIN
relay:envelope.relay
thread:thread
networkManager:self.networkManager
storageManager:self.storageManager
primaryStorage:self.primaryStorage
transaction:transaction];
if (!attachmentsProcessor.hasSupportedAttachments) {
DDLogWarn(@"%@ received unsupported media envelope", self.logTag);
@ -734,7 +734,7 @@ NS_ASSUME_NONNULL_BEGIN
inThread:thread
messageType:TSInfoMessageTypeSessionDidEnd] saveWithTransaction:transaction];
[self.storageManager deleteAllSessionsForContact:envelope.source protocolContext:transaction];
[self.primaryStorage deleteAllSessionsForContact:envelope.source protocolContext:transaction];
}
- (void)handleExpirationTimerUpdateMessageWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope

View File

@ -9,11 +9,11 @@
#import "OWSBackgroundTask.h"
#import "OWSBatchMessageProcessor.h"
#import "OWSMessageDecrypter.h"
#import "OWSPrimaryStorage.h"
#import "OWSQueues.h"
#import "OWSSignalServiceProtos.pb.h"
#import "OWSStorage.h"
#import "TSDatabaseView.h"
#import "TSStorageManager.h"
#import "TSYapDatabaseObject.h"
#import "Threading.h"
#import <YapDatabase/YapDatabaseAutoView.h>
@ -379,7 +379,7 @@ NSString *const OWSMessageDecryptJobFinderExtensionGroup = @"OWSMessageProcessin
- (instancetype)initDefault
{
// For concurrency coherency we use the same dbConnection to persist and read the unprocessed envelopes
YapDatabaseConnection *dbConnection = [[TSStorageManager sharedManager] newDatabaseConnection];
YapDatabaseConnection *dbConnection = [[OWSPrimaryStorage sharedManager] newDatabaseConnection];
OWSMessageDecrypter *messageDecrypter = [OWSMessageDecrypter sharedManager];
OWSBatchMessageProcessor *batchMessageProcessor = [OWSBatchMessageProcessor sharedInstance];

View File

@ -10,12 +10,12 @@ extern const NSUInteger kOversizeTextMessageSizeThreshold;
@class ContactsUpdater;
@class OWSBlockingManager;
@class OWSPrimaryStorage;
@class OWSUploadingService;
@class SignalRecipient;
@class TSInvalidIdentityKeySendingErrorMessage;
@class TSNetworkManager;
@class TSOutgoingMessage;
@class TSStorageManager;
@class TSThread;
@class YapDatabaseReadWriteTransaction;
@ -57,7 +57,7 @@ NS_SWIFT_NAME(MessageSender)
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithNetworkManager:(TSNetworkManager *)networkManager
storageManager:(TSStorageManager *)storageManager
primaryStorage:(OWSPrimaryStorage *)primaryStorage
contactsManager:(id<ContactsManagerProtocol>)contactsManager
contactsUpdater:(ContactsUpdater *)contactsUpdater;

View File

@ -16,6 +16,10 @@
#import "OWSMessageServiceParams.h"
#import "OWSOutgoingSentMessageTranscript.h"
#import "OWSOutgoingSyncMessage.h"
#import "OWSPrimaryStorage+PreKeyStore.h"
#import "OWSPrimaryStorage+SignedPreKeyStore.h"
#import "OWSPrimaryStorage+sessionStore.h"
#import "OWSPrimaryStorage.h"
#import "OWSRequestFactory.h"
#import "OWSUploadingService.h"
#import "PreKeyBundle+jsonDict.h"
@ -30,10 +34,6 @@
#import "TSNetworkManager.h"
#import "TSOutgoingMessage.h"
#import "TSPreKeyManager.h"
#import "TSStorageManager+PreKeyStore.h"
#import "TSStorageManager+SignedPreKeyStore.h"
#import "TSStorageManager+sessionStore.h"
#import "TSStorageManager.h"
#import "TSThread.h"
#import "Threading.h"
#import <AxolotlKit/AxolotlExceptions.h>
@ -313,7 +313,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
@interface OWSMessageSender ()
@property (nonatomic, readonly) TSNetworkManager *networkManager;
@property (nonatomic, readonly) TSStorageManager *storageManager;
@property (nonatomic, readonly) OWSPrimaryStorage *primaryStorage;
@property (nonatomic, readonly) OWSBlockingManager *blockingManager;
@property (nonatomic, readonly) OWSUploadingService *uploadingService;
@property (nonatomic, readonly) YapDatabaseConnection *dbConnection;
@ -326,7 +326,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
@implementation OWSMessageSender
- (instancetype)initWithNetworkManager:(TSNetworkManager *)networkManager
storageManager:(TSStorageManager *)storageManager
primaryStorage:(OWSPrimaryStorage *)primaryStorage
contactsManager:(id<ContactsManagerProtocol>)contactsManager
contactsUpdater:(ContactsUpdater *)contactsUpdater
{
@ -336,13 +336,13 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
}
_networkManager = networkManager;
_storageManager = storageManager;
_primaryStorage = primaryStorage;
_contactsManager = contactsManager;
_contactsUpdater = contactsUpdater;
_sendingQueueMap = [NSMutableDictionary new];
_uploadingService = [[OWSUploadingService alloc] initWithNetworkManager:networkManager];
_dbConnection = storageManager.newDatabaseConnection;
_dbConnection = primaryStorage.newDatabaseConnection;
OWSSingletonAssert();
@ -1139,7 +1139,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
if (extraDevices && extraDevices.count > 0) {
DDLogInfo(@"%@ removing extra devices: %@", self.logTag, extraDevices);
for (NSNumber *extraDeviceId in extraDevices) {
[self.storageManager deleteSessionForContact:recipient.uniqueId
[self.primaryStorage deleteSessionForContact:recipient.uniqueId
deviceId:extraDeviceId.intValue
protocolContext:transaction];
}
@ -1293,7 +1293,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
messageDict = [self encryptedMessageWithPlaintext:plainText
toRecipient:recipient.uniqueId
deviceId:deviceNumber
keyingStorage:self.storageManager
keyingStorage:self.primaryStorage
isSilent:message.isSilent
transaction:transaction];
} @catch (NSException *exception) {
@ -1326,7 +1326,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
- (NSDictionary *)encryptedMessageWithPlaintext:(NSData *)plainText
toRecipient:(NSString *)identifier
deviceId:(NSNumber *)deviceNumber
keyingStorage:(TSStorageManager *)storage
keyingStorage:(OWSPrimaryStorage *)storage
isSilent:(BOOL)isSilent
transaction:(YapDatabaseReadWriteTransaction *)transaction
{
@ -1478,9 +1478,9 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
[self.dbConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
for (NSUInteger i = 0; i < [devices count]; i++) {
int deviceNumber = [devices[i] intValue];
[[TSStorageManager sharedManager] deleteSessionForContact:identifier
deviceId:deviceNumber
protocolContext:transaction];
[[OWSPrimaryStorage sharedManager] deleteSessionForContact:identifier
deviceId:deviceNumber
protocolContext:transaction];
}
}];
completionHandler();

View File

@ -4,8 +4,8 @@
#import "OWSMessageUtils.h"
#import "AppContext.h"
#import "OWSPrimaryStorage.h"
#import "TSDatabaseView.h"
#import "TSStorageManager.h"
#import "TSThread.h"
#import <YapDatabase/YapDatabase.h>
@ -33,12 +33,12 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initDefault
{
TSStorageManager *storageManager = [TSStorageManager sharedManager];
OWSPrimaryStorage *primaryStorage = [OWSPrimaryStorage sharedManager];
return [self initWithStorageManager:storageManager];
return [self initWithPrimaryStorage:primaryStorage];
}
- (instancetype)initWithStorageManager:(TSStorageManager *)storageManager
- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage
{
self = [super init];
@ -46,7 +46,7 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
_dbConnection = storageManager.newDatabaseConnection;
_dbConnection = primaryStorage.newDatabaseConnection;
OWSSingletonAssert();

View File

@ -7,6 +7,7 @@
#import "NSNotificationCenter+OWS.h"
#import "OWSLinkedDeviceReadReceipt.h"
#import "OWSMessageSender.h"
#import "OWSPrimaryStorage.h"
#import "OWSReadReceiptsForLinkedDevicesMessage.h"
#import "OWSReadReceiptsForSenderMessage.h"
#import "OWSSignalServiceProtos.pb.h"
@ -16,7 +17,6 @@
#import "TSContactThread.h"
#import "TSDatabaseView.h"
#import "TSIncomingMessage.h"
#import "TSStorageManager.h"
#import "TextSecureKitEnv.h"
#import "Threading.h"
#import "YapDatabaseConnection+OWS.h"
@ -156,13 +156,13 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
- (instancetype)initDefault
{
OWSMessageSender *messageSender = [TextSecureKitEnv sharedEnv].messageSender;
TSStorageManager *storageManager = [TSStorageManager sharedManager];
OWSPrimaryStorage *primaryStorage = [OWSPrimaryStorage sharedManager];
return [self initWithMessageSender:messageSender storageManager:storageManager];
return [self initWithMessageSender:messageSender primaryStorage:primaryStorage];
}
- (instancetype)initWithMessageSender:(OWSMessageSender *)messageSender
storageManager:(TSStorageManager *)storageManager
primaryStorage:(OWSPrimaryStorage *)primaryStorage
{
self = [super init];
@ -171,7 +171,7 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
}
_messageSender = messageSender;
_dbConnection = storageManager.newDatabaseConnection;
_dbConnection = primaryStorage.newDatabaseConnection;
_toLinkedDevicesReadReceiptMap = [NSMutableDictionary new];
_toSenderReadReceiptMap = [NSMutableDictionary new];

View File

@ -1,10 +1,10 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
NS_ASSUME_NONNULL_BEGIN
@class TSStorageManager;
@class OWSPrimaryStorage;
@interface OWSCensorshipConfiguration : NSObject

View File

@ -1,10 +1,10 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSCensorshipConfiguration.h"
#import "OWSPrimaryStorage.h"
#import "TSConstants.h"
#import "TSStorageManager.h"
NS_ASSUME_NONNULL_BEGIN

View File

@ -1,14 +1,14 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
NS_ASSUME_NONNULL_BEGIN
extern NSString *const kNSNotificationName_IsCensorshipCircumventionActiveDidChange;
@class TSStorageManager;
@class TSAccountManager;
@class AFHTTPSessionManager;
@class OWSPrimaryStorage;
@class TSAccountManager;
@interface OWSSignalService : NSObject

View File

@ -7,21 +7,21 @@
#import "OWSCensorshipConfiguration.h"
#import "OWSError.h"
#import "OWSHTTPSecurityPolicy.h"
#import "OWSPrimaryStorage.h"
#import "TSAccountManager.h"
#import "TSConstants.h"
#import "TSStorageManager.h"
#import "YapDatabaseConnection+OWS.h"
#import <AFNetworking/AFHTTPSessionManager.h>
NS_ASSUME_NONNULL_BEGIN
NSString *const kTSStorageManager_OWSSignalService = @"kTSStorageManager_OWSSignalService";
NSString *const kTSStorageManager_isCensorshipCircumventionManuallyActivated =
@"kTSStorageManager_isCensorshipCircumventionManuallyActivated";
NSString *const kTSStorageManager_ManualCensorshipCircumventionDomain =
@"kTSStorageManager_ManualCensorshipCircumventionDomain";
NSString *const kTSStorageManager_ManualCensorshipCircumventionCountryCode =
@"kTSStorageManager_ManualCensorshipCircumventionCountryCode";
NSString *const kOWSPrimaryStorage_OWSSignalService = @"kOWSPrimaryStorage_OWSSignalService";
NSString *const kOWSPrimaryStorage_isCensorshipCircumventionManuallyActivated
= @"kOWSPrimaryStorage_isCensorshipCircumventionManuallyActivated";
NSString *const kOWSPrimaryStorage_ManualCensorshipCircumventionDomain
= @"kOWSPrimaryStorage_ManualCensorshipCircumventionDomain";
NSString *const kOWSPrimaryStorage_ManualCensorshipCircumventionCountryCode
= @"kOWSPrimaryStorage_ManualCensorshipCircumventionCountryCode";
NSString *const kNSNotificationName_IsCensorshipCircumventionActiveDidChange =
@"kNSNotificationName_IsCensorshipCircumventionActiveDidChange";
@ -104,15 +104,16 @@ NSString *const kNSNotificationName_IsCensorshipCircumventionActiveDidChange =
- (BOOL)isCensorshipCircumventionManuallyActivated
{
return [[TSStorageManager dbReadConnection] boolForKey:kTSStorageManager_isCensorshipCircumventionManuallyActivated
inCollection:kTSStorageManager_OWSSignalService];
return
[[OWSPrimaryStorage dbReadConnection] boolForKey:kOWSPrimaryStorage_isCensorshipCircumventionManuallyActivated
inCollection:kOWSPrimaryStorage_OWSSignalService];
}
- (void)setIsCensorshipCircumventionManuallyActivated:(BOOL)value
{
[[TSStorageManager dbReadWriteConnection] setObject:@(value)
forKey:kTSStorageManager_isCensorshipCircumventionManuallyActivated
inCollection:kTSStorageManager_OWSSignalService];
[[OWSPrimaryStorage dbReadWriteConnection] setObject:@(value)
forKey:kOWSPrimaryStorage_isCensorshipCircumventionManuallyActivated
inCollection:kOWSPrimaryStorage_OWSSignalService];
[self updateIsCensorshipCircumventionActive];
}
@ -340,28 +341,29 @@ NSString *const kNSNotificationName_IsCensorshipCircumventionActiveDidChange =
- (NSString *)manualCensorshipCircumventionDomain
{
return [[TSStorageManager dbReadConnection] objectForKey:kTSStorageManager_ManualCensorshipCircumventionDomain
inCollection:kTSStorageManager_OWSSignalService];
return [[OWSPrimaryStorage dbReadConnection] objectForKey:kOWSPrimaryStorage_ManualCensorshipCircumventionDomain
inCollection:kOWSPrimaryStorage_OWSSignalService];
}
- (void)setManualCensorshipCircumventionDomain:(NSString *)value
{
[[TSStorageManager dbReadWriteConnection] setObject:value
forKey:kTSStorageManager_ManualCensorshipCircumventionDomain
inCollection:kTSStorageManager_OWSSignalService];
[[OWSPrimaryStorage dbReadWriteConnection] setObject:value
forKey:kOWSPrimaryStorage_ManualCensorshipCircumventionDomain
inCollection:kOWSPrimaryStorage_OWSSignalService];
}
- (NSString *)manualCensorshipCircumventionCountryCode
{
return [[TSStorageManager dbReadConnection] objectForKey:kTSStorageManager_ManualCensorshipCircumventionCountryCode
inCollection:kTSStorageManager_OWSSignalService];
return
[[OWSPrimaryStorage dbReadConnection] objectForKey:kOWSPrimaryStorage_ManualCensorshipCircumventionCountryCode
inCollection:kOWSPrimaryStorage_OWSSignalService];
}
- (void)setManualCensorshipCircumventionCountryCode:(NSString *)value
{
[[TSStorageManager dbReadWriteConnection] setObject:value
forKey:kTSStorageManager_ManualCensorshipCircumventionCountryCode
inCollection:kTSStorageManager_OWSSignalService];
[[OWSPrimaryStorage dbReadWriteConnection] setObject:value
forKey:kOWSPrimaryStorage_ManualCensorshipCircumventionCountryCode
inCollection:kOWSPrimaryStorage_OWSSignalService];
}
@end

View File

@ -3,8 +3,8 @@
//
#import "OWSRecipientIdentity.h"
#import "TSStorageManager+SessionStore.h"
#import "TSStorageManager.h"
#import "OWSPrimaryStorage+SessionStore.h"
#import "OWSPrimaryStorage.h"
#import <YapDatabase/YapDatabase.h>
NS_ASSUME_NONNULL_BEGIN

View File

@ -1,12 +1,12 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSStorageManager.h"
#import "OWSPrimaryStorage.h"
NS_ASSUME_NONNULL_BEGIN
@interface TSStorageManager (Calling)
@interface OWSPrimaryStorage (Calling)
// phoneNumber is an e164 formatted phone number.
//

View File

@ -0,0 +1,34 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSPrimaryStorage+Calling.h"
#import "YapDatabaseConnection+OWS.h"
NS_ASSUME_NONNULL_BEGIN
NSString *const OWSPrimaryStorageCallKitIdToPhoneNumberCollection = @"TSStorageManagerCallKitIdToPhoneNumberCollection";
@implementation OWSPrimaryStorage (Calling)
- (void)setPhoneNumber:(NSString *)phoneNumber forCallKitId:(NSString *)callKitId
{
OWSAssert(phoneNumber.length > 0);
OWSAssert(callKitId.length > 0);
[self.dbReadWriteConnection setObject:phoneNumber
forKey:callKitId
inCollection:OWSPrimaryStorageCallKitIdToPhoneNumberCollection];
}
- (NSString *)phoneNumberForCallKitId:(NSString *)callKitId
{
OWSAssert(callKitId.length > 0);
return
[self.dbReadConnection objectForKey:callKitId inCollection:OWSPrimaryStorageCallKitIdToPhoneNumberCollection];
}
@end
NS_ASSUME_NONNULL_END

View File

@ -1,11 +1,11 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSPrimaryStorage.h"
#import <AxolotlKit/PreKeyStore.h>
#import "TSStorageManager.h"
@interface TSStorageManager (PreKeyStore) <PreKeyStore>
@interface OWSPrimaryStorage (PreKeyStore) <PreKeyStore>
- (NSArray *)generatePreKeyRecords;
- (PreKeyRecord *)getOrGenerateLastResortKey;

View File

@ -2,20 +2,21 @@
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSPrimaryStorage+PreKeyStore.h"
#import "OWSPrimaryStorage+keyFromIntLong.h"
#import "TSStorageKeys.h"
#import "TSStorageManager+PreKeyStore.h"
#import "TSStorageManager+keyFromIntLong.h"
#import "YapDatabaseConnection+OWS.h"
#import <AxolotlKit/AxolotlExceptions.h>
#import <AxolotlKit/SessionBuilder.h>
#define TSStorageManagerPreKeyStoreCollection @"TSStorageManagerPreKeyStoreCollection"
#define OWSPrimaryStoragePreKeyStoreCollection @"TSStorageManagerPreKeyStoreCollection"
#define TSNextPrekeyIdKey @"TSStorageInternalSettingsNextPreKeyId"
#define BATCH_SIZE 100
@implementation TSStorageManager (PreKeyStore)
@implementation OWSPrimaryStorage (PreKeyStore)
- (PreKeyRecord *)getOrGenerateLastResortKey {
- (PreKeyRecord *)getOrGenerateLastResortKey
{
if ([self containsPreKey:kPreKeyOfLastResortId]) {
return [self loadPreKey:kPreKeyOfLastResortId];
} else {
@ -26,15 +27,17 @@
}
}
- (NSArray *)generatePreKeyRecords {
- (NSArray *)generatePreKeyRecords
{
NSMutableArray *preKeyRecords = [NSMutableArray array];
@synchronized(self) {
@synchronized(self)
{
int preKeyId = [self nextPreKeyId];
DDLogInfo(@"%@ building %d new preKeys starting from preKeyId: %d", self.logTag, BATCH_SIZE, preKeyId);
for (int i = 0; i < BATCH_SIZE; i++) {
ECKeyPair *keyPair = [Curve25519 generateKeyPair];
ECKeyPair *keyPair = [Curve25519 generateKeyPair];
PreKeyRecord *record = [[PreKeyRecord alloc] initWithId:preKeyId keyPair:keyPair];
[preKeyRecords addObject:record];
@ -48,17 +51,19 @@
return preKeyRecords;
}
- (void)storePreKeyRecords:(NSArray *)preKeyRecords {
- (void)storePreKeyRecords:(NSArray *)preKeyRecords
{
for (PreKeyRecord *record in preKeyRecords) {
[self.dbReadWriteConnection setObject:record
forKey:[self keyFromInt:record.Id]
inCollection:TSStorageManagerPreKeyStoreCollection];
inCollection:OWSPrimaryStoragePreKeyStoreCollection];
}
}
- (PreKeyRecord *)loadPreKey:(int)preKeyId {
- (PreKeyRecord *)loadPreKey:(int)preKeyId
{
PreKeyRecord *preKeyRecord = [self.dbReadConnection preKeyRecordForKey:[self keyFromInt:preKeyId]
inCollection:TSStorageManagerPreKeyStoreCollection];
inCollection:OWSPrimaryStoragePreKeyStoreCollection];
if (!preKeyRecord) {
OWSRaiseException(InvalidKeyIdException, @"No pre key found matching key id");
@ -67,24 +72,28 @@
}
}
- (void)storePreKey:(int)preKeyId preKeyRecord:(PreKeyRecord *)record {
- (void)storePreKey:(int)preKeyId preKeyRecord:(PreKeyRecord *)record
{
[self.dbReadWriteConnection setObject:record
forKey:[self keyFromInt:preKeyId]
inCollection:TSStorageManagerPreKeyStoreCollection];
inCollection:OWSPrimaryStoragePreKeyStoreCollection];
}
- (BOOL)containsPreKey:(int)preKeyId {
- (BOOL)containsPreKey:(int)preKeyId
{
PreKeyRecord *preKeyRecord = [self.dbReadConnection preKeyRecordForKey:[self keyFromInt:preKeyId]
inCollection:TSStorageManagerPreKeyStoreCollection];
inCollection:OWSPrimaryStoragePreKeyStoreCollection];
return (preKeyRecord != nil);
}
- (void)removePreKey:(int)preKeyId {
- (void)removePreKey:(int)preKeyId
{
[self.dbReadWriteConnection removeObjectForKey:[self keyFromInt:preKeyId]
inCollection:TSStorageManagerPreKeyStoreCollection];
inCollection:OWSPrimaryStoragePreKeyStoreCollection];
}
- (int)nextPreKeyId {
- (int)nextPreKeyId
{
int lastPreKeyId =
[self.dbReadConnection intForKey:TSNextPrekeyIdKey inCollection:TSStorageInternalSettingsCollection];

View File

@ -2,12 +2,12 @@
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSStorageManager.h"
#import "OWSPrimaryStorage.h"
#import <AxolotlKit/SessionStore.h>
NS_ASSUME_NONNULL_BEGIN
@interface TSStorageManager (SessionStore) <SessionStore>
@interface OWSPrimaryStorage (SessionStore) <SessionStore>
- (void)archiveAllSessionsForContact:(NSString *)contactIdentifier protocolContext:(nullable id)protocolContext;

View File

@ -3,7 +3,7 @@
//
#import "OWSFileSystem.h"
#import "TSStorageManager+SessionStore.h"
#import "OWSPrimaryStorage+SessionStore.h"
#import "YapDatabaseConnection+OWS.h"
#import "YapDatabaseTransaction+OWS.h"
#import <AxolotlKit/SessionRecord.h>
@ -11,10 +11,10 @@
NS_ASSUME_NONNULL_BEGIN
NSString *const TSStorageManagerSessionStoreCollection = @"TSStorageManagerSessionStoreCollection";
NSString *const OWSPrimaryStorageSessionStoreCollection = @"TSStorageManagerSessionStoreCollection";
NSString *const kSessionStoreDBConnectionKey = @"kSessionStoreDBConnectionKey";
@implementation TSStorageManager (SessionStore)
@implementation OWSPrimaryStorage (SessionStore)
/**
* Special purpose dbConnection which disables the object cache to better enforce transaction semantics on the store.
@ -26,7 +26,7 @@ NSString *const kSessionStoreDBConnectionKey = @"kSessionStoreDBConnectionKey";
static dispatch_once_t onceToken;
static YapDatabaseConnection *sessionStoreDBConnection;
dispatch_once(&onceToken, ^{
sessionStoreDBConnection = [TSStorageManager sharedManager].newDatabaseConnection;
sessionStoreDBConnection = [OWSPrimaryStorage sharedManager].newDatabaseConnection;
sessionStoreDBConnection.objectCacheEnabled = NO;
});
@ -51,7 +51,7 @@ NSString *const kSessionStoreDBConnectionKey = @"kSessionStoreDBConnectionKey";
YapDatabaseReadWriteTransaction *transaction = protocolContext;
NSDictionary *_Nullable dictionary =
[transaction objectForKey:contactIdentifier inCollection:TSStorageManagerSessionStoreCollection];
[transaction objectForKey:contactIdentifier inCollection:OWSPrimaryStorageSessionStoreCollection];
SessionRecord *record;
@ -78,7 +78,7 @@ NSString *const kSessionStoreDBConnectionKey = @"kSessionStoreDBConnectionKey";
YapDatabaseReadWriteTransaction *transaction = protocolContext;
NSDictionary *_Nullable dictionary =
[transaction objectForKey:contactIdentifier inCollection:TSStorageManagerSessionStoreCollection];
[transaction objectForKey:contactIdentifier inCollection:OWSPrimaryStorageSessionStoreCollection];
return dictionary ? dictionary.allKeys : @[];
}
@ -103,7 +103,7 @@ NSString *const kSessionStoreDBConnectionKey = @"kSessionStoreDBConnectionKey";
[session markAsUnFresh];
NSDictionary *immutableDictionary =
[transaction objectForKey:contactIdentifier inCollection:TSStorageManagerSessionStoreCollection];
[transaction objectForKey:contactIdentifier inCollection:OWSPrimaryStorageSessionStoreCollection];
NSMutableDictionary *dictionary
= (immutableDictionary ? [immutableDictionary mutableCopy] : [NSMutableDictionary new]);
@ -112,7 +112,7 @@ NSString *const kSessionStoreDBConnectionKey = @"kSessionStoreDBConnectionKey";
[transaction setObject:[dictionary copy]
forKey:contactIdentifier
inCollection:TSStorageManagerSessionStoreCollection];
inCollection:OWSPrimaryStorageSessionStoreCollection];
}
- (BOOL)containsSession:(NSString *)contactIdentifier
@ -138,10 +138,10 @@ NSString *const kSessionStoreDBConnectionKey = @"kSessionStoreDBConnectionKey";
YapDatabaseReadWriteTransaction *transaction = protocolContext;
DDLogInfo(
@"[TSStorageManager (SessionStore)] deleting session for contact: %@ device: %d", contactIdentifier, deviceId);
@"[OWSPrimaryStorage (SessionStore)] deleting session for contact: %@ device: %d", contactIdentifier, deviceId);
NSDictionary *immutableDictionary =
[transaction objectForKey:contactIdentifier inCollection:TSStorageManagerSessionStoreCollection];
[transaction objectForKey:contactIdentifier inCollection:OWSPrimaryStorageSessionStoreCollection];
NSMutableDictionary *dictionary
= (immutableDictionary ? [immutableDictionary mutableCopy] : [NSMutableDictionary new]);
@ -150,7 +150,7 @@ NSString *const kSessionStoreDBConnectionKey = @"kSessionStoreDBConnectionKey";
[transaction setObject:[dictionary copy]
forKey:contactIdentifier
inCollection:TSStorageManagerSessionStoreCollection];
inCollection:OWSPrimaryStorageSessionStoreCollection];
}
- (void)deleteAllSessionsForContact:(NSString *)contactIdentifier protocolContext:(nullable id)protocolContext
@ -160,9 +160,9 @@ NSString *const kSessionStoreDBConnectionKey = @"kSessionStoreDBConnectionKey";
YapDatabaseReadWriteTransaction *transaction = protocolContext;
DDLogInfo(@"[TSStorageManager (SessionStore)] deleting all sessions for contact:%@", contactIdentifier);
DDLogInfo(@"[OWSPrimaryStorage (SessionStore)] deleting all sessions for contact:%@", contactIdentifier);
[transaction removeObjectForKey:contactIdentifier inCollection:TSStorageManagerSessionStoreCollection];
[transaction removeObjectForKey:contactIdentifier inCollection:OWSPrimaryStorageSessionStoreCollection];
}
- (void)archiveAllSessionsForContact:(NSString *)contactIdentifier protocolContext:(nullable id)protocolContext
@ -172,10 +172,10 @@ NSString *const kSessionStoreDBConnectionKey = @"kSessionStoreDBConnectionKey";
YapDatabaseReadWriteTransaction *transaction = protocolContext;
DDLogInfo(@"[TSStorageManager (SessionStore)] archiving all sessions for contact: %@", contactIdentifier);
DDLogInfo(@"[OWSPrimaryStorage (SessionStore)] archiving all sessions for contact: %@", contactIdentifier);
__block NSDictionary<NSNumber *, SessionRecord *> *sessionRecords =
[transaction objectForKey:contactIdentifier inCollection:TSStorageManagerSessionStoreCollection];
[transaction objectForKey:contactIdentifier inCollection:OWSPrimaryStorageSessionStoreCollection];
for (id deviceId in sessionRecords) {
id object = sessionRecords[deviceId];
@ -186,11 +186,11 @@ NSString *const kSessionStoreDBConnectionKey = @"kSessionStoreDBConnectionKey";
SessionRecord *sessionRecord = (SessionRecord *)object;
[sessionRecord archiveCurrentState];
}
}
[transaction setObject:sessionRecords
forKey:contactIdentifier
inCollection:TSStorageManagerSessionStoreCollection];
[transaction setObject:sessionRecords
forKey:contactIdentifier
inCollection:OWSPrimaryStorageSessionStoreCollection];
}
#pragma mark - debug
@ -201,16 +201,16 @@ NSString *const kSessionStoreDBConnectionKey = @"kSessionStoreDBConnectionKey";
DDLogWarn(@"%@ resetting session store", self.logTag);
[transaction removeAllObjectsInCollection:TSStorageManagerSessionStoreCollection];
[transaction removeAllObjectsInCollection:OWSPrimaryStorageSessionStoreCollection];
}
- (void)printAllSessions
{
NSString *tag = @"[TSStorageManager (SessionStore)]";
NSString *tag = @"[OWSPrimaryStorage (SessionStore)]";
[self.sessionStoreDBConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) {
DDLogDebug(@"%@ All Sessions:", tag);
[transaction
enumerateKeysAndObjectsInCollection:TSStorageManagerSessionStoreCollection
enumerateKeysAndObjectsInCollection:OWSPrimaryStorageSessionStoreCollection
usingBlock:^(NSString *_Nonnull key,
id _Nonnull deviceSessionsObject,
BOOL *_Nonnull stop) {
@ -258,14 +258,14 @@ NSString *const kSessionStoreDBConnectionKey = @"kSessionStoreDBConnectionKey";
{
OWSAssert(transaction);
[transaction snapshotCollection:TSStorageManagerSessionStoreCollection snapshotFilePath:self.snapshotFilePath];
[transaction snapshotCollection:OWSPrimaryStorageSessionStoreCollection snapshotFilePath:self.snapshotFilePath];
}
- (void)restoreSessionStore:(YapDatabaseReadWriteTransaction *)transaction
{
OWSAssert(transaction);
[transaction restoreSnapshotOfCollection:TSStorageManagerSessionStoreCollection
[transaction restoreSnapshotOfCollection:OWSPrimaryStorageSessionStoreCollection
snapshotFilePath:self.snapshotFilePath];
}
#endif

View File

@ -1,16 +1,16 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSPrimaryStorage.h"
#import <AxolotlKit/SignedPreKeyStore.h>
#import "TSStorageManager.h"
NS_ASSUME_NONNULL_BEGIN
// Used for testing
extern NSString *const TSStorageManagerSignedPreKeyStoreCollection;
extern NSString *const OWSPrimaryStorageSignedPreKeyStoreCollection;
@interface TSStorageManager (SignedPreKeyStore) <SignedPreKeyStore>
@interface OWSPrimaryStorage (SignedPreKeyStore) <SignedPreKeyStore>
- (SignedPreKeyRecord *)generateRandomSignedRecord;

View File

@ -3,9 +3,9 @@
//
#import "OWSIdentityManager.h"
#import "TSStorageManager+PreKeyStore.h"
#import "TSStorageManager+SignedPreKeyStore.h"
#import "TSStorageManager+keyFromIntLong.h"
#import "OWSPrimaryStorage+PreKeyStore.h"
#import "OWSPrimaryStorage+SignedPreKeyStore.h"
#import "OWSPrimaryStorage+keyFromIntLong.h"
#import "YapDatabaseConnection+OWS.h"
#import <AxolotlKit/AxolotlExceptions.h>
#import <AxolotlKit/NSData+keyVersionByte.h>
@ -14,15 +14,16 @@
NS_ASSUME_NONNULL_BEGIN
NSString *const TSStorageManagerSignedPreKeyStoreCollection = @"TSStorageManagerSignedPreKeyStoreCollection";
NSString *const TSStorageManagerSignedPreKeyMetadataCollection = @"TSStorageManagerSignedPreKeyMetadataCollection";
NSString *const TSStorageManagerKeyPrekeyUpdateFailureCount = @"prekeyUpdateFailureCount";
NSString *const TSStorageManagerKeyFirstPrekeyUpdateFailureDate = @"firstPrekeyUpdateFailureDate";
NSString *const TSStorageManagerKeyPrekeyCurrentSignedPrekeyId = @"currentSignedPrekeyId";
NSString *const OWSPrimaryStorageSignedPreKeyStoreCollection = @"TSStorageManagerSignedPreKeyStoreCollection";
NSString *const OWSPrimaryStorageSignedPreKeyMetadataCollection = @"TSStorageManagerSignedPreKeyMetadataCollection";
NSString *const OWSPrimaryStorageKeyPrekeyUpdateFailureCount = @"prekeyUpdateFailureCount";
NSString *const OWSPrimaryStorageKeyFirstPrekeyUpdateFailureDate = @"firstPrekeyUpdateFailureDate";
NSString *const OWSPrimaryStorageKeyPrekeyCurrentSignedPrekeyId = @"currentSignedPrekeyId";
@implementation TSStorageManager (SignedPreKeyStore)
@implementation OWSPrimaryStorage (SignedPreKeyStore)
- (SignedPreKeyRecord *)generateRandomSignedRecord {
- (SignedPreKeyRecord *)generateRandomSignedRecord
{
ECKeyPair *keyPair = [Curve25519 generateKeyPair];
// Signed prekey ids must be > 0.
@ -35,10 +36,11 @@ NSString *const TSStorageManagerKeyPrekeyCurrentSignedPrekeyId = @"currentSigned
generatedAt:[NSDate date]];
}
- (SignedPreKeyRecord *)loadSignedPrekey:(int)signedPreKeyId {
- (SignedPreKeyRecord *)loadSignedPrekey:(int)signedPreKeyId
{
SignedPreKeyRecord *preKeyRecord =
[self.dbReadConnection signedPreKeyRecordForKey:[self keyFromInt:signedPreKeyId]
inCollection:TSStorageManagerSignedPreKeyStoreCollection];
inCollection:OWSPrimaryStorageSignedPreKeyStoreCollection];
if (!preKeyRecord) {
OWSRaiseException(InvalidKeyIdException, @"No signed pre key found matching key id");
@ -50,101 +52,105 @@ NSString *const TSStorageManagerKeyPrekeyCurrentSignedPrekeyId = @"currentSigned
- (nullable SignedPreKeyRecord *)loadSignedPrekeyOrNil:(int)signedPreKeyId
{
return [self.dbReadConnection signedPreKeyRecordForKey:[self keyFromInt:signedPreKeyId]
inCollection:TSStorageManagerSignedPreKeyStoreCollection];
inCollection:OWSPrimaryStorageSignedPreKeyStoreCollection];
}
- (NSArray *)loadSignedPreKeys {
- (NSArray *)loadSignedPreKeys
{
NSMutableArray *signedPreKeyRecords = [NSMutableArray array];
YapDatabaseConnection *conn = [self newDatabaseConnection];
[conn readWithBlock:^(YapDatabaseReadTransaction *transaction) {
[transaction enumerateRowsInCollection:TSStorageManagerSignedPreKeyStoreCollection
usingBlock:^(NSString *key, id object, id metadata, BOOL *stop) {
[signedPreKeyRecords addObject:object];
}];
[transaction enumerateRowsInCollection:OWSPrimaryStorageSignedPreKeyStoreCollection
usingBlock:^(NSString *key, id object, id metadata, BOOL *stop) {
[signedPreKeyRecords addObject:object];
}];
}];
return signedPreKeyRecords;
}
- (void)storeSignedPreKey:(int)signedPreKeyId signedPreKeyRecord:(SignedPreKeyRecord *)signedPreKeyRecord {
- (void)storeSignedPreKey:(int)signedPreKeyId signedPreKeyRecord:(SignedPreKeyRecord *)signedPreKeyRecord
{
[self.dbReadWriteConnection setObject:signedPreKeyRecord
forKey:[self keyFromInt:signedPreKeyId]
inCollection:TSStorageManagerSignedPreKeyStoreCollection];
inCollection:OWSPrimaryStorageSignedPreKeyStoreCollection];
}
- (BOOL)containsSignedPreKey:(int)signedPreKeyId {
- (BOOL)containsSignedPreKey:(int)signedPreKeyId
{
PreKeyRecord *preKeyRecord =
[self.dbReadConnection signedPreKeyRecordForKey:[self keyFromInt:signedPreKeyId]
inCollection:TSStorageManagerSignedPreKeyStoreCollection];
inCollection:OWSPrimaryStorageSignedPreKeyStoreCollection];
return (preKeyRecord != nil);
}
- (void)removeSignedPreKey:(int)signedPrekeyId {
- (void)removeSignedPreKey:(int)signedPrekeyId
{
[self.dbReadWriteConnection removeObjectForKey:[self keyFromInt:signedPrekeyId]
inCollection:TSStorageManagerSignedPreKeyStoreCollection];
inCollection:OWSPrimaryStorageSignedPreKeyStoreCollection];
}
- (nullable NSNumber *)currentSignedPrekeyId
{
return [self.dbReadConnection objectForKey:TSStorageManagerKeyPrekeyCurrentSignedPrekeyId
inCollection:TSStorageManagerSignedPreKeyMetadataCollection];
return [self.dbReadConnection objectForKey:OWSPrimaryStorageKeyPrekeyCurrentSignedPrekeyId
inCollection:OWSPrimaryStorageSignedPreKeyMetadataCollection];
}
- (void)setCurrentSignedPrekeyId:(int)value
{
[self.dbReadWriteConnection setObject:@(value)
forKey:TSStorageManagerKeyPrekeyCurrentSignedPrekeyId
inCollection:TSStorageManagerSignedPreKeyMetadataCollection];
forKey:OWSPrimaryStorageKeyPrekeyCurrentSignedPrekeyId
inCollection:OWSPrimaryStorageSignedPreKeyMetadataCollection];
}
#pragma mark - Prekey update failures
- (int)prekeyUpdateFailureCount
{
NSNumber *value = [self.dbReadConnection objectForKey:TSStorageManagerKeyPrekeyUpdateFailureCount
inCollection:TSStorageManagerSignedPreKeyMetadataCollection];
NSNumber *value = [self.dbReadConnection objectForKey:OWSPrimaryStorageKeyPrekeyUpdateFailureCount
inCollection:OWSPrimaryStorageSignedPreKeyMetadataCollection];
// Will default to zero.
return [value intValue];
}
- (void)clearPrekeyUpdateFailureCount
{
[self.dbReadWriteConnection removeObjectForKey:TSStorageManagerKeyPrekeyUpdateFailureCount
inCollection:TSStorageManagerSignedPreKeyMetadataCollection];
[self.dbReadWriteConnection removeObjectForKey:OWSPrimaryStorageKeyPrekeyUpdateFailureCount
inCollection:OWSPrimaryStorageSignedPreKeyMetadataCollection];
}
- (int)incrementPrekeyUpdateFailureCount
{
return [self.dbReadWriteConnection incrementIntForKey:TSStorageManagerKeyPrekeyUpdateFailureCount
inCollection:TSStorageManagerSignedPreKeyMetadataCollection];
return [self.dbReadWriteConnection incrementIntForKey:OWSPrimaryStorageKeyPrekeyUpdateFailureCount
inCollection:OWSPrimaryStorageSignedPreKeyMetadataCollection];
}
- (nullable NSDate *)firstPrekeyUpdateFailureDate
{
return [self.dbReadConnection dateForKey:TSStorageManagerKeyFirstPrekeyUpdateFailureDate
inCollection:TSStorageManagerSignedPreKeyMetadataCollection];
return [self.dbReadConnection dateForKey:OWSPrimaryStorageKeyFirstPrekeyUpdateFailureDate
inCollection:OWSPrimaryStorageSignedPreKeyMetadataCollection];
}
- (void)setFirstPrekeyUpdateFailureDate:(nonnull NSDate *)value
{
[self.dbReadWriteConnection setDate:value
forKey:TSStorageManagerKeyFirstPrekeyUpdateFailureDate
inCollection:TSStorageManagerSignedPreKeyMetadataCollection];
forKey:OWSPrimaryStorageKeyFirstPrekeyUpdateFailureDate
inCollection:OWSPrimaryStorageSignedPreKeyMetadataCollection];
}
- (void)clearFirstPrekeyUpdateFailureDate
{
[self.dbReadWriteConnection removeObjectForKey:TSStorageManagerKeyFirstPrekeyUpdateFailureDate
inCollection:TSStorageManagerSignedPreKeyMetadataCollection];
[self.dbReadWriteConnection removeObjectForKey:OWSPrimaryStorageKeyFirstPrekeyUpdateFailureDate
inCollection:OWSPrimaryStorageSignedPreKeyMetadataCollection];
}
#pragma mark - Debugging
- (void)logSignedPreKeyReport
{
NSString *tag = @"[TSStorageManager (SignedPreKeyStore)]";
NSString *tag = @"[OWSPrimaryStorage (SignedPreKeyStore)]";
NSNumber *currentId = [self currentSignedPrekeyId];
NSDate *firstPrekeyUpdateFailureDate = [self firstPrekeyUpdateFailureDate];
@ -158,11 +164,11 @@ NSString *const TSStorageManagerKeyPrekeyCurrentSignedPrekeyId = @"currentSigned
DDLogInfo(@"%@ firstPrekeyUpdateFailureDate: %@", tag, firstPrekeyUpdateFailureDate);
DDLogInfo(@"%@ prekeyUpdateFailureCount: %lu", tag, (unsigned long)prekeyUpdateFailureCount);
NSUInteger count = [transaction numberOfKeysInCollection:TSStorageManagerSignedPreKeyStoreCollection];
NSUInteger count = [transaction numberOfKeysInCollection:OWSPrimaryStorageSignedPreKeyStoreCollection];
DDLogInfo(@"%@ All Keys (count: %lu):", tag, (unsigned long)count);
[transaction
enumerateKeysAndObjectsInCollection:TSStorageManagerSignedPreKeyStoreCollection
enumerateKeysAndObjectsInCollection:OWSPrimaryStorageSignedPreKeyStoreCollection
usingBlock:^(
NSString *_Nonnull key, id _Nonnull signedPreKeyObject, BOOL *_Nonnull stop) {
i++;

View File

@ -0,0 +1,11 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSPrimaryStorage.h"
@interface OWSPrimaryStorage (keyFromIntLong)
- (NSString *)keyFromInt:(int)integer;
@end

View File

@ -0,0 +1,14 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSPrimaryStorage+keyFromIntLong.h"
@implementation OWSPrimaryStorage (keyFromIntLong)
- (NSString *)keyFromInt:(int)integer
{
return [[NSNumber numberWithInteger:integer] stringValue];
}
@end

Some files were not shown because too many files have changed in this diff Show More