2017-12-08 19:22:01 +01:00
|
|
|
//
|
|
|
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "OWSUserProfile.h"
|
|
|
|
#import "NSString+OWS.h"
|
2017-12-08 19:45:24 +01:00
|
|
|
#import <SignalServiceKit/AppContext.h>
|
2017-12-08 19:22:01 +01:00
|
|
|
#import <SignalServiceKit/Cryptography.h>
|
2017-12-08 20:43:11 +01:00
|
|
|
#import <SignalServiceKit/NSData+hexString.h>
|
2017-12-08 19:45:24 +01:00
|
|
|
#import <SignalServiceKit/NSNotificationCenter+OWS.h>
|
|
|
|
#import <SignalServiceKit/TSAccountManager.h>
|
2017-12-08 19:22:01 +01:00
|
|
|
#import <YapDatabase/YapDatabaseConnection.h>
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
2017-12-08 19:45:24 +01:00
|
|
|
NSString *const kNSNotificationName_LocalProfileDidChange = @"kNSNotificationName_LocalProfileDidChange";
|
|
|
|
NSString *const kNSNotificationName_OtherUsersProfileWillChange = @"kNSNotificationName_OtherUsersProfileWillChange";
|
|
|
|
NSString *const kNSNotificationName_OtherUsersProfileDidChange = @"kNSNotificationName_OtherUsersProfileDidChange";
|
|
|
|
|
|
|
|
NSString *const kNSNotificationKey_ProfileRecipientId = @"kNSNotificationKey_ProfileRecipientId";
|
|
|
|
NSString *const kNSNotificationKey_ProfileGroupId = @"kNSNotificationKey_ProfileGroupId";
|
|
|
|
|
2017-12-08 19:22:01 +01:00
|
|
|
NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId";
|
|
|
|
|
|
|
|
@interface OWSUserProfile ()
|
|
|
|
|
|
|
|
@property (atomic, nullable) OWSAES256Key *profileKey;
|
|
|
|
@property (atomic, nullable) NSString *profileName;
|
|
|
|
@property (atomic, nullable) NSString *avatarUrlPath;
|
|
|
|
@property (atomic, nullable) NSString *avatarFileName;
|
|
|
|
@property (atomic, nullable) NSDate *lastUpdateDate;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
@implementation OWSUserProfile
|
|
|
|
|
|
|
|
+ (OWSUserProfile *)getOrBuildUserProfileForRecipientId:(NSString *)recipientId
|
|
|
|
dbConnection:(YapDatabaseConnection *)dbConnection
|
|
|
|
{
|
|
|
|
OWSAssert(recipientId.length > 0);
|
|
|
|
|
|
|
|
__block OWSUserProfile *userProfile;
|
|
|
|
[dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
|
|
|
userProfile = [OWSUserProfile fetchObjectWithUniqueID:recipientId transaction:transaction];
|
|
|
|
}];
|
|
|
|
|
|
|
|
if (!userProfile) {
|
|
|
|
userProfile = [[OWSUserProfile alloc] initWithRecipientId:recipientId];
|
|
|
|
|
|
|
|
if ([recipientId isEqualToString:kLocalProfileUniqueId]) {
|
2017-12-08 20:59:36 +01:00
|
|
|
[userProfile updateWithProfileKey:[OWSAES256Key generateRandomKey]
|
|
|
|
dbConnection:dbConnection
|
|
|
|
completion:nil];
|
2017-12-08 19:22:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OWSAssert(userProfile);
|
|
|
|
|
|
|
|
return userProfile;
|
|
|
|
}
|
|
|
|
|
2017-12-08 20:43:11 +01:00
|
|
|
+ (BOOL)localUserProfileExists:(YapDatabaseConnection *)dbConnection
|
|
|
|
{
|
|
|
|
__block BOOL result = NO;
|
|
|
|
[dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
|
|
|
result = [OWSUserProfile fetchObjectWithUniqueID:kLocalProfileUniqueId transaction:transaction] != nil;
|
|
|
|
}];
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-12-08 19:22:01 +01:00
|
|
|
- (instancetype)initWithRecipientId:(NSString *)recipientId
|
|
|
|
{
|
|
|
|
self = [super initWithUniqueId:recipientId];
|
|
|
|
|
|
|
|
if (!self) {
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
OWSAssert(recipientId.length > 0);
|
|
|
|
_recipientId = recipientId;
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Update With... Methods
|
|
|
|
|
2017-12-08 20:59:36 +01:00
|
|
|
- (void)finalizeWithCompletion:(nullable OWSUserProfileCompletion)externalCompletion didChange:(BOOL)didChange
|
2017-12-08 19:45:24 +01:00
|
|
|
{
|
2017-12-08 20:00:04 +01:00
|
|
|
if (externalCompletion) {
|
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), externalCompletion);
|
|
|
|
}
|
2017-12-08 19:45:24 +01:00
|
|
|
|
2017-12-08 20:59:36 +01:00
|
|
|
if (!didChange) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-08 20:00:04 +01:00
|
|
|
BOOL isLocalUserProfile = [self.recipientId isEqualToString:kLocalProfileUniqueId];
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
if (isLocalUserProfile) {
|
|
|
|
// We populate an initial (empty) profile on launch of a new install, but until
|
|
|
|
// we have a registered account, syncing will fail (and there could not be any
|
|
|
|
// linked device to sync to at this point anyway).
|
|
|
|
if ([TSAccountManager isRegistered]) {
|
|
|
|
[CurrentAppContext() doMultiDeviceUpdateWithProfileKey:self.profileKey];
|
2017-12-08 19:45:24 +01:00
|
|
|
}
|
2017-12-08 20:00:04 +01:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationNameAsync:kNSNotificationName_LocalProfileDidChange
|
|
|
|
object:nil
|
|
|
|
userInfo:nil];
|
|
|
|
} else {
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
postNotificationNameAsync:kNSNotificationName_OtherUsersProfileWillChange
|
|
|
|
object:nil
|
|
|
|
userInfo:@{
|
|
|
|
kNSNotificationKey_ProfileRecipientId : self.recipientId,
|
|
|
|
}];
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
postNotificationNameAsync:kNSNotificationName_OtherUsersProfileDidChange
|
|
|
|
object:nil
|
|
|
|
userInfo:@{
|
|
|
|
kNSNotificationKey_ProfileRecipientId : self.recipientId,
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
});
|
2017-12-08 19:45:24 +01:00
|
|
|
}
|
|
|
|
|
2017-12-08 19:22:01 +01:00
|
|
|
- (void)updateWithProfileName:(nullable NSString *)profileName
|
|
|
|
avatarUrlPath:(nullable NSString *)avatarUrlPath
|
|
|
|
avatarFileName:(nullable NSString *)avatarFileName
|
|
|
|
dbConnection:(YapDatabaseConnection *)dbConnection
|
|
|
|
completion:(nullable OWSUserProfileCompletion)completion
|
|
|
|
{
|
2017-12-08 20:59:36 +01:00
|
|
|
__block BOOL didChange = NO;
|
2017-12-08 20:00:04 +01:00
|
|
|
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
2017-12-08 19:22:01 +01:00
|
|
|
[self applyChangeToSelfAndLatestCopy:transaction
|
|
|
|
changeBlock:^(OWSUserProfile *userProfile) {
|
2017-12-08 20:59:36 +01:00
|
|
|
didChange |= [self didStringChange:userProfile.profileName
|
|
|
|
newValue:[profileName ows_stripped]];
|
|
|
|
didChange |=
|
|
|
|
[self didStringChange:userProfile.avatarUrlPath newValue:avatarUrlPath];
|
|
|
|
didChange |=
|
|
|
|
[self didStringChange:userProfile.avatarFileName newValue:avatarFileName];
|
|
|
|
|
2017-12-08 19:22:01 +01:00
|
|
|
[userProfile setProfileName:[profileName ows_stripped]];
|
|
|
|
[userProfile setAvatarUrlPath:avatarUrlPath];
|
|
|
|
[userProfile setAvatarFileName:avatarFileName];
|
2017-12-08 20:43:11 +01:00
|
|
|
}
|
|
|
|
saveIfMissing:YES];
|
2017-12-08 20:00:04 +01:00
|
|
|
}];
|
2017-12-08 20:59:36 +01:00
|
|
|
[self finalizeWithCompletion:completion didChange:didChange];
|
2017-12-08 19:22:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateWithProfileName:(nullable NSString *)profileName
|
|
|
|
avatarUrlPath:(nullable NSString *)avatarUrlPath
|
|
|
|
avatarFileName:(nullable NSString *)avatarFileName
|
|
|
|
lastUpdateDate:(nullable NSDate *)lastUpdateDate
|
|
|
|
dbConnection:(YapDatabaseConnection *)dbConnection
|
|
|
|
completion:(nullable OWSUserProfileCompletion)completion
|
|
|
|
{
|
2017-12-08 20:59:36 +01:00
|
|
|
__block BOOL didChange = NO;
|
2017-12-08 20:00:04 +01:00
|
|
|
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
2017-12-08 20:59:36 +01:00
|
|
|
[self
|
|
|
|
applyChangeToSelfAndLatestCopy:transaction
|
|
|
|
changeBlock:^(OWSUserProfile *userProfile) {
|
|
|
|
didChange |= [self didStringChange:userProfile.profileName
|
|
|
|
newValue:[profileName ows_stripped]];
|
|
|
|
didChange |= [self didStringChange:userProfile.avatarUrlPath newValue:avatarUrlPath];
|
|
|
|
didChange |=
|
|
|
|
[self didStringChange:userProfile.avatarFileName newValue:avatarFileName];
|
|
|
|
didChange |= [self didDateChange:userProfile.lastUpdateDate newValue:lastUpdateDate];
|
|
|
|
|
|
|
|
[userProfile setProfileName:[profileName ows_stripped]];
|
|
|
|
[userProfile setAvatarUrlPath:avatarUrlPath];
|
|
|
|
[userProfile setAvatarFileName:avatarFileName];
|
|
|
|
[userProfile setLastUpdateDate:lastUpdateDate];
|
|
|
|
}
|
|
|
|
saveIfMissing:YES];
|
2017-12-08 20:00:04 +01:00
|
|
|
}];
|
2017-12-08 20:59:36 +01:00
|
|
|
[self finalizeWithCompletion:completion didChange:didChange];
|
2017-12-08 19:22:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateWithProfileName:(nullable NSString *)profileName
|
|
|
|
avatarUrlPath:(nullable NSString *)avatarUrlPath
|
|
|
|
lastUpdateDate:(nullable NSDate *)lastUpdateDate
|
|
|
|
dbConnection:(YapDatabaseConnection *)dbConnection
|
|
|
|
completion:(nullable OWSUserProfileCompletion)completion
|
|
|
|
{
|
2017-12-08 20:59:36 +01:00
|
|
|
__block BOOL didChange = NO;
|
2017-12-08 20:00:04 +01:00
|
|
|
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
2017-12-08 20:59:36 +01:00
|
|
|
[self
|
|
|
|
applyChangeToSelfAndLatestCopy:transaction
|
|
|
|
changeBlock:^(OWSUserProfile *userProfile) {
|
|
|
|
didChange |= [self didStringChange:userProfile.profileName
|
|
|
|
newValue:[profileName ows_stripped]];
|
|
|
|
didChange |= [self didStringChange:userProfile.avatarUrlPath newValue:avatarUrlPath];
|
|
|
|
didChange |= [self didDateChange:userProfile.lastUpdateDate newValue:lastUpdateDate];
|
|
|
|
|
|
|
|
[userProfile setProfileName:[profileName ows_stripped]];
|
|
|
|
[userProfile setAvatarUrlPath:avatarUrlPath];
|
|
|
|
[userProfile setLastUpdateDate:lastUpdateDate];
|
|
|
|
}
|
|
|
|
saveIfMissing:YES];
|
2017-12-08 20:00:04 +01:00
|
|
|
}];
|
2017-12-08 20:59:36 +01:00
|
|
|
[self finalizeWithCompletion:completion didChange:didChange];
|
2017-12-08 19:22:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateWithProfileName:(nullable NSString *)profileName
|
|
|
|
profileKey:(OWSAES256Key *)profileKey
|
|
|
|
avatarUrlPath:(nullable NSString *)avatarUrlPath
|
|
|
|
avatarFileName:(nullable NSString *)avatarFileName
|
|
|
|
dbConnection:(YapDatabaseConnection *)dbConnection
|
|
|
|
completion:(nullable OWSUserProfileCompletion)completion
|
|
|
|
{
|
2017-12-08 20:59:36 +01:00
|
|
|
__block BOOL didChange = NO;
|
2017-12-08 20:00:04 +01:00
|
|
|
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
2017-12-08 19:22:01 +01:00
|
|
|
[self applyChangeToSelfAndLatestCopy:transaction
|
|
|
|
changeBlock:^(OWSUserProfile *userProfile) {
|
2017-12-08 20:59:36 +01:00
|
|
|
didChange |= [self didStringChange:userProfile.profileName
|
|
|
|
newValue:[profileName ows_stripped]];
|
|
|
|
didChange |= [self didKeyChange:userProfile.profileKey newValue:profileKey];
|
|
|
|
didChange |=
|
|
|
|
[self didStringChange:userProfile.avatarUrlPath newValue:avatarUrlPath];
|
|
|
|
didChange |=
|
|
|
|
[self didStringChange:userProfile.avatarFileName newValue:avatarFileName];
|
|
|
|
|
2017-12-08 19:22:01 +01:00
|
|
|
[userProfile setProfileName:[profileName ows_stripped]];
|
|
|
|
[userProfile setProfileKey:profileKey];
|
|
|
|
[userProfile setAvatarUrlPath:avatarUrlPath];
|
|
|
|
[userProfile setAvatarFileName:avatarFileName];
|
2017-12-08 20:43:11 +01:00
|
|
|
}
|
|
|
|
saveIfMissing:YES];
|
2017-12-08 20:00:04 +01:00
|
|
|
}];
|
2017-12-08 20:59:36 +01:00
|
|
|
[self finalizeWithCompletion:completion didChange:didChange];
|
2017-12-08 19:22:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateWithAvatarUrlPath:(nullable NSString *)avatarUrlPath
|
|
|
|
avatarFileName:(nullable NSString *)avatarFileName
|
|
|
|
dbConnection:(YapDatabaseConnection *)dbConnection
|
|
|
|
completion:(nullable OWSUserProfileCompletion)completion
|
|
|
|
{
|
2017-12-08 20:59:36 +01:00
|
|
|
__block BOOL didChange = NO;
|
2017-12-08 20:00:04 +01:00
|
|
|
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
2017-12-08 19:22:01 +01:00
|
|
|
[self applyChangeToSelfAndLatestCopy:transaction
|
|
|
|
changeBlock:^(OWSUserProfile *userProfile) {
|
2017-12-08 20:59:36 +01:00
|
|
|
didChange |=
|
|
|
|
[self didStringChange:userProfile.avatarUrlPath newValue:avatarUrlPath];
|
|
|
|
didChange |=
|
|
|
|
[self didStringChange:userProfile.avatarFileName newValue:avatarFileName];
|
|
|
|
|
2017-12-08 19:22:01 +01:00
|
|
|
[userProfile setAvatarUrlPath:avatarUrlPath];
|
|
|
|
[userProfile setAvatarFileName:avatarFileName];
|
2017-12-08 20:43:11 +01:00
|
|
|
}
|
|
|
|
saveIfMissing:YES];
|
2017-12-08 20:00:04 +01:00
|
|
|
}];
|
2017-12-08 20:59:36 +01:00
|
|
|
[self finalizeWithCompletion:completion didChange:didChange];
|
2017-12-08 19:22:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateWithAvatarFileName:(nullable NSString *)avatarFileName
|
|
|
|
dbConnection:(YapDatabaseConnection *)dbConnection
|
|
|
|
completion:(nullable OWSUserProfileCompletion)completion
|
|
|
|
{
|
2017-12-08 20:59:36 +01:00
|
|
|
__block BOOL didChange = NO;
|
2017-12-08 20:00:04 +01:00
|
|
|
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
2017-12-08 19:22:01 +01:00
|
|
|
[self applyChangeToSelfAndLatestCopy:transaction
|
|
|
|
changeBlock:^(OWSUserProfile *userProfile) {
|
2017-12-08 20:59:36 +01:00
|
|
|
didChange |=
|
|
|
|
[self didStringChange:userProfile.avatarFileName newValue:avatarFileName];
|
|
|
|
|
2017-12-08 19:22:01 +01:00
|
|
|
[userProfile setAvatarFileName:avatarFileName];
|
2017-12-08 20:43:11 +01:00
|
|
|
}
|
|
|
|
saveIfMissing:YES];
|
2017-12-08 20:00:04 +01:00
|
|
|
}];
|
2017-12-08 20:59:36 +01:00
|
|
|
[self finalizeWithCompletion:completion didChange:didChange];
|
2017-12-08 19:22:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateWithLastUpdateDate:(nullable NSDate *)lastUpdateDate
|
|
|
|
dbConnection:(YapDatabaseConnection *)dbConnection
|
|
|
|
completion:(nullable OWSUserProfileCompletion)completion
|
|
|
|
{
|
2017-12-08 20:59:36 +01:00
|
|
|
__block BOOL didChange = NO;
|
2017-12-08 20:00:04 +01:00
|
|
|
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
2017-12-08 19:22:01 +01:00
|
|
|
[self applyChangeToSelfAndLatestCopy:transaction
|
|
|
|
changeBlock:^(OWSUserProfile *userProfile) {
|
2017-12-08 20:59:36 +01:00
|
|
|
didChange |=
|
|
|
|
[self didDateChange:userProfile.lastUpdateDate newValue:lastUpdateDate];
|
|
|
|
|
2017-12-08 19:22:01 +01:00
|
|
|
[userProfile setLastUpdateDate:lastUpdateDate];
|
2017-12-08 20:43:11 +01:00
|
|
|
}
|
|
|
|
saveIfMissing:YES];
|
2017-12-08 20:00:04 +01:00
|
|
|
}];
|
2017-12-08 20:59:36 +01:00
|
|
|
[self finalizeWithCompletion:completion didChange:didChange];
|
2017-12-08 19:22:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)clearWithProfileKey:(OWSAES256Key *)profileKey
|
|
|
|
dbConnection:(YapDatabaseConnection *)dbConnection
|
|
|
|
completion:(nullable OWSUserProfileCompletion)completion;
|
|
|
|
{
|
|
|
|
OWSAssert(profileKey);
|
|
|
|
|
2017-12-08 20:59:36 +01:00
|
|
|
__block BOOL didChange = NO;
|
2017-12-08 20:00:04 +01:00
|
|
|
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
2017-12-08 19:22:01 +01:00
|
|
|
[self applyChangeToSelfAndLatestCopy:transaction
|
|
|
|
changeBlock:^(OWSUserProfile *userProfile) {
|
2017-12-08 20:59:36 +01:00
|
|
|
didChange |= [self didKeyChange:userProfile.profileKey newValue:profileKey];
|
|
|
|
didChange |= [self didStringChange:userProfile.profileName newValue:nil];
|
|
|
|
didChange |= [self didStringChange:userProfile.avatarUrlPath newValue:nil];
|
|
|
|
didChange |= [self didStringChange:userProfile.avatarFileName newValue:nil];
|
|
|
|
didChange |= [self didDateChange:userProfile.lastUpdateDate newValue:nil];
|
|
|
|
|
2017-12-08 19:22:01 +01:00
|
|
|
[userProfile setProfileKey:profileKey];
|
|
|
|
[userProfile setProfileName:nil];
|
|
|
|
[userProfile setAvatarUrlPath:nil];
|
|
|
|
[userProfile setAvatarFileName:nil];
|
|
|
|
[userProfile setLastUpdateDate:nil];
|
2017-12-08 20:43:11 +01:00
|
|
|
}
|
|
|
|
saveIfMissing:YES];
|
2017-12-08 20:00:04 +01:00
|
|
|
}];
|
2017-12-08 20:59:36 +01:00
|
|
|
[self finalizeWithCompletion:completion didChange:didChange];
|
2017-12-08 19:22:01 +01:00
|
|
|
}
|
|
|
|
|
2017-12-08 20:59:36 +01:00
|
|
|
- (void)updateWithProfileKey:(OWSAES256Key *)profileKey
|
|
|
|
dbConnection:(YapDatabaseConnection *)dbConnection
|
|
|
|
completion:(nullable OWSUserProfileCompletion)completion;
|
2017-12-08 19:22:01 +01:00
|
|
|
{
|
|
|
|
OWSAssert(profileKey);
|
|
|
|
|
|
|
|
self.profileKey = profileKey;
|
|
|
|
|
2017-12-08 20:59:36 +01:00
|
|
|
__block BOOL didChange = NO;
|
2017-12-08 20:00:04 +01:00
|
|
|
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
2017-12-08 19:22:01 +01:00
|
|
|
[self applyChangeToSelfAndLatestCopy:transaction
|
|
|
|
changeBlock:^(OWSUserProfile *userProfile) {
|
2017-12-08 20:59:36 +01:00
|
|
|
didChange |= [self didKeyChange:userProfile.profileKey newValue:profileKey];
|
|
|
|
|
2017-12-08 19:22:01 +01:00
|
|
|
[userProfile setProfileKey:profileKey];
|
2017-12-08 20:43:11 +01:00
|
|
|
}
|
|
|
|
saveIfMissing:YES];
|
2017-12-08 20:00:04 +01:00
|
|
|
}];
|
2017-12-08 20:59:36 +01:00
|
|
|
[self finalizeWithCompletion:completion didChange:didChange];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)didStringChange:(NSString *_Nullable)oldValue newValue:(NSString *_Nullable)newValue
|
|
|
|
{
|
|
|
|
if (!oldValue && !newValue) {
|
|
|
|
return NO;
|
|
|
|
} else if (!oldValue || !newValue) {
|
|
|
|
return YES;
|
|
|
|
} else {
|
|
|
|
return ![oldValue isEqualToString:newValue];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)didDateChange:(NSDate *_Nullable)oldValue newValue:(NSDate *_Nullable)newValue
|
|
|
|
{
|
|
|
|
if (!oldValue && !newValue) {
|
|
|
|
return NO;
|
|
|
|
} else if (!oldValue || !newValue) {
|
|
|
|
return YES;
|
|
|
|
} else {
|
|
|
|
return ![oldValue isEqualToDate:newValue];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)didKeyChange:(OWSAES256Key *_Nullable)oldValue newValue:(OWSAES256Key *_Nullable)newValue
|
|
|
|
{
|
|
|
|
if (!oldValue && !newValue) {
|
|
|
|
return NO;
|
|
|
|
} else if (!oldValue || !newValue) {
|
|
|
|
return YES;
|
|
|
|
} else {
|
|
|
|
return ![oldValue.keyData isEqualToData:newValue.keyData];
|
|
|
|
}
|
2017-12-08 19:22:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Database Connection Accessors
|
|
|
|
|
|
|
|
- (YapDatabaseConnection *)dbReadConnection
|
|
|
|
{
|
|
|
|
OWSFail(@"%@ UserProfile should always use OWSProfileManager's database connection.", self.logTag);
|
|
|
|
|
|
|
|
return TSYapDatabaseObject.dbReadConnection;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (YapDatabaseConnection *)dbReadConnection
|
|
|
|
{
|
|
|
|
OWSFail(@"%@ UserProfile should always use OWSProfileManager's database connection.", self.logTag);
|
|
|
|
|
|
|
|
return TSYapDatabaseObject.dbReadConnection;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (YapDatabaseConnection *)dbReadWriteConnection
|
|
|
|
{
|
|
|
|
OWSFail(@"%@ UserProfile should always use OWSProfileManager's database connection.", self.logTag);
|
|
|
|
|
|
|
|
return TSYapDatabaseObject.dbReadWriteConnection;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (YapDatabaseConnection *)dbReadWriteConnection
|
|
|
|
{
|
|
|
|
OWSFail(@"%@ UserProfile should always use OWSProfileManager's database connection.", self.logTag);
|
|
|
|
|
|
|
|
return TSYapDatabaseObject.dbReadWriteConnection;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|