mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.9 KiB
Matlab
68 lines
2.9 KiB
Matlab
8 years ago
|
//
|
||
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "OWS104CreateRecipientIdentities.h"
|
||
8 years ago
|
#import <SignalServiceKit/OWSIdentityManager.h>
|
||
8 years ago
|
#import <SignalServiceKit/OWSRecipientIdentity.h>
|
||
|
#import <YapDatabase/YapDatabaseConnection.h>
|
||
|
#import <YapDatabase/YapDatabaseTransaction.h>
|
||
|
|
||
|
NS_ASSUME_NONNULL_BEGIN
|
||
|
|
||
|
// Increment a similar constant for every future DBMigration
|
||
|
static NSString *const OWS104CreateRecipientIdentitiesMigrationId = @"104";
|
||
|
|
||
|
/**
|
||
8 years ago
|
* New SN behavior requires tracking additional state - not just the identity key data.
|
||
8 years ago
|
* So we wrap the key, along with the new meta-data in an OWSRecipientIdentity.
|
||
|
*/
|
||
|
@implementation OWS104CreateRecipientIdentities
|
||
|
|
||
|
+ (NSString *)migrationId
|
||
|
{
|
||
|
return OWS104CreateRecipientIdentitiesMigrationId;
|
||
|
}
|
||
|
|
||
|
// Overriding runUp instead of runUpWithTransaction in order to implement a blocking migration.
|
||
|
- (void)runUp
|
||
|
{
|
||
8 years ago
|
[[OWSRecipientIdentity dbReadWriteConnection] readWriteWithBlock:^(
|
||
|
YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||
8 years ago
|
NSMutableDictionary<NSString *, NSData *> *identityKeys = [NSMutableDictionary new];
|
||
|
|
||
|
[transaction
|
||
|
enumerateKeysAndObjectsInCollection:TSStorageManagerTrustedKeysCollection
|
||
|
usingBlock:^(
|
||
|
NSString *_Nonnull recipientId, id _Nonnull object, BOOL *_Nonnull stop) {
|
||
|
if (![object isKindOfClass:[NSData class]]) {
|
||
8 years ago
|
OWSFail(
|
||
8 years ago
|
@"%@ Unexpected object in trusted keys collection key: %@ object: %@",
|
||
8 years ago
|
self.logTag,
|
||
8 years ago
|
recipientId,
|
||
|
object);
|
||
|
return;
|
||
|
}
|
||
|
NSData *identityKey = (NSData *)object;
|
||
|
[identityKeys setObject:identityKey forKey:recipientId];
|
||
|
}];
|
||
|
|
||
|
[identityKeys enumerateKeysAndObjectsUsingBlock:^(
|
||
|
NSString *_Nonnull recipientId, NSData *_Nonnull identityKey, BOOL *_Nonnull stop) {
|
||
8 years ago
|
DDLogInfo(@"%@ Migrating identity key for recipient: %@", self.logTag, recipientId);
|
||
8 years ago
|
[[[OWSRecipientIdentity alloc] initWithRecipientId:recipientId
|
||
|
identityKey:identityKey
|
||
|
isFirstKnownKey:NO
|
||
|
createdAt:[NSDate dateWithTimeIntervalSince1970:0]
|
||
8 years ago
|
verificationState:OWSVerificationStateDefault]
|
||
|
saveWithTransaction:transaction];
|
||
8 years ago
|
}];
|
||
8 years ago
|
|
||
|
[self saveWithTransaction:transaction];
|
||
8 years ago
|
}];
|
||
|
}
|
||
|
|
||
|
@end
|
||
|
|
||
|
NS_ASSUME_NONNULL_END
|