|
|
@ -87,18 +87,21 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId";
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - Update With... Methods
|
|
|
|
#pragma mark - Update With... Methods
|
|
|
|
|
|
|
|
|
|
|
|
- (void)finalizeWithCompletion:(nullable OWSUserProfileCompletion)externalCompletion didChange:(BOOL)didChange
|
|
|
|
- (void)finalizeWithCompletion:(nullable OWSUserProfileCompletion)externalCompletion
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
DDLogVerbose(@"%@, after: %@", self.logTag, self.debugDescription);
|
|
|
|
|
|
|
|
|
|
|
|
if (externalCompletion) {
|
|
|
|
if (externalCompletion) {
|
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), externalCompletion);
|
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), externalCompletion);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!didChange) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BOOL isLocalUserProfile = [self.recipientId isEqualToString:kLocalProfileUniqueId];
|
|
|
|
BOOL isLocalUserProfile = [self.recipientId isEqualToString:kLocalProfileUniqueId];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (isLocalUserProfile) {
|
|
|
|
|
|
|
|
// [DDLog flushLog];
|
|
|
|
|
|
|
|
// DDLogError(@"%@", self.logTag);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
if (isLocalUserProfile) {
|
|
|
|
if (isLocalUserProfile) {
|
|
|
|
// We populate an initial (empty) profile on launch of a new install, but until
|
|
|
|
// We populate an initial (empty) profile on launch of a new install, but until
|
|
|
@ -134,24 +137,34 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId";
|
|
|
|
dbConnection:(YapDatabaseConnection *)dbConnection
|
|
|
|
dbConnection:(YapDatabaseConnection *)dbConnection
|
|
|
|
completion:(nullable OWSUserProfileCompletion)completion
|
|
|
|
completion:(nullable OWSUserProfileCompletion)completion
|
|
|
|
{
|
|
|
|
{
|
|
|
|
__block BOOL didChange = NO;
|
|
|
|
DDLogVerbose(@"%@ %s, before: %@", self.logTag, __PRETTY_FUNCTION__, self.debugDescription);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (self.hasEverBeenSaved) {
|
|
|
|
|
|
|
|
BOOL didChange = NO;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
didChange |= [self didStringChange:self.profileName newValue:[profileName ows_stripped]];
|
|
|
|
|
|
|
|
didChange |= [self didStringChange:self.avatarUrlPath newValue:avatarUrlPath];
|
|
|
|
|
|
|
|
didChange |= [self didStringChange:self.avatarFileName newValue:avatarFileName];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!didChange) {
|
|
|
|
|
|
|
|
DDLogVerbose(@"%@ Ignoring update in %s: %@", self.logTag, __PRETTY_FUNCTION__, self.debugDescription);
|
|
|
|
|
|
|
|
if (completion) {
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), completion);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
[self applyChangeToSelfAndLatestCopy:transaction
|
|
|
|
[self applyChangeToSelfAndLatestCopy:transaction
|
|
|
|
changeBlock:^(OWSUserProfile *userProfile) {
|
|
|
|
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];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[userProfile setProfileName:[profileName ows_stripped]];
|
|
|
|
[userProfile setProfileName:[profileName ows_stripped]];
|
|
|
|
[userProfile setAvatarUrlPath:avatarUrlPath];
|
|
|
|
[userProfile setAvatarUrlPath:avatarUrlPath];
|
|
|
|
[userProfile setAvatarFileName:avatarFileName];
|
|
|
|
[userProfile setAvatarFileName:avatarFileName];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
saveIfMissing:YES];
|
|
|
|
saveIfMissing:YES];
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
[self finalizeWithCompletion:completion didChange:didChange];
|
|
|
|
[self finalizeWithCompletion:completion];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)updateWithProfileName:(nullable NSString *)profileName
|
|
|
|
- (void)updateWithProfileName:(nullable NSString *)profileName
|
|
|
@ -161,18 +174,29 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId";
|
|
|
|
dbConnection:(YapDatabaseConnection *)dbConnection
|
|
|
|
dbConnection:(YapDatabaseConnection *)dbConnection
|
|
|
|
completion:(nullable OWSUserProfileCompletion)completion
|
|
|
|
completion:(nullable OWSUserProfileCompletion)completion
|
|
|
|
{
|
|
|
|
{
|
|
|
|
__block BOOL didChange = NO;
|
|
|
|
DDLogVerbose(@"%@ %s, before: %@", self.logTag, __PRETTY_FUNCTION__, self.debugDescription);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (self.hasEverBeenSaved) {
|
|
|
|
|
|
|
|
BOOL didChange = NO;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
didChange |= [self didStringChange:self.profileName newValue:[profileName ows_stripped]];
|
|
|
|
|
|
|
|
didChange |= [self didStringChange:self.avatarUrlPath newValue:avatarUrlPath];
|
|
|
|
|
|
|
|
didChange |= [self didStringChange:self.avatarFileName newValue:avatarFileName];
|
|
|
|
|
|
|
|
didChange |= [self didDateChange:self.lastUpdateDate newValue:lastUpdateDate];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!didChange) {
|
|
|
|
|
|
|
|
DDLogVerbose(@"%@ Ignoring update in %s: %@", self.logTag, __PRETTY_FUNCTION__, self.debugDescription);
|
|
|
|
|
|
|
|
if (completion) {
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), completion);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
[self
|
|
|
|
[self
|
|
|
|
applyChangeToSelfAndLatestCopy:transaction
|
|
|
|
applyChangeToSelfAndLatestCopy:transaction
|
|
|
|
changeBlock:^(OWSUserProfile *userProfile) {
|
|
|
|
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 setProfileName:[profileName ows_stripped]];
|
|
|
|
[userProfile setAvatarUrlPath:avatarUrlPath];
|
|
|
|
[userProfile setAvatarUrlPath:avatarUrlPath];
|
|
|
|
[userProfile setAvatarFileName:avatarFileName];
|
|
|
|
[userProfile setAvatarFileName:avatarFileName];
|
|
|
@ -180,7 +204,7 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
saveIfMissing:YES];
|
|
|
|
saveIfMissing:YES];
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
[self finalizeWithCompletion:completion didChange:didChange];
|
|
|
|
[self finalizeWithCompletion:completion];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)updateWithProfileName:(nullable NSString *)profileName
|
|
|
|
- (void)updateWithProfileName:(nullable NSString *)profileName
|
|
|
@ -189,23 +213,35 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId";
|
|
|
|
dbConnection:(YapDatabaseConnection *)dbConnection
|
|
|
|
dbConnection:(YapDatabaseConnection *)dbConnection
|
|
|
|
completion:(nullable OWSUserProfileCompletion)completion
|
|
|
|
completion:(nullable OWSUserProfileCompletion)completion
|
|
|
|
{
|
|
|
|
{
|
|
|
|
__block BOOL didChange = NO;
|
|
|
|
DDLogVerbose(@"%@ %s, before: %@", self.logTag, __PRETTY_FUNCTION__, self.debugDescription);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (self.hasEverBeenSaved) {
|
|
|
|
|
|
|
|
BOOL didChange = NO;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
didChange |= [self didStringChange:self.profileName newValue:[profileName ows_stripped]];
|
|
|
|
|
|
|
|
didChange |= [self didStringChange:self.avatarUrlPath newValue:avatarUrlPath];
|
|
|
|
|
|
|
|
didChange |= [self didDateChange:self.lastUpdateDate newValue:lastUpdateDate];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!didChange) {
|
|
|
|
|
|
|
|
DDLogVerbose(@"%@ Ignoring update in %s: %@", self.logTag, __PRETTY_FUNCTION__, self.debugDescription);
|
|
|
|
|
|
|
|
if (completion) {
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), completion);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
[self
|
|
|
|
[self
|
|
|
|
applyChangeToSelfAndLatestCopy:transaction
|
|
|
|
applyChangeToSelfAndLatestCopy:transaction
|
|
|
|
changeBlock:^(OWSUserProfile *userProfile) {
|
|
|
|
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 setProfileName:[profileName ows_stripped]];
|
|
|
|
[userProfile setAvatarUrlPath:avatarUrlPath];
|
|
|
|
[userProfile setAvatarUrlPath:avatarUrlPath];
|
|
|
|
[userProfile setLastUpdateDate:lastUpdateDate];
|
|
|
|
[userProfile setLastUpdateDate:lastUpdateDate];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
saveIfMissing:YES];
|
|
|
|
saveIfMissing:YES];
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
[self finalizeWithCompletion:completion didChange:didChange];
|
|
|
|
[self finalizeWithCompletion:completion];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)updateWithProfileName:(nullable NSString *)profileName
|
|
|
|
- (void)updateWithProfileName:(nullable NSString *)profileName
|
|
|
@ -215,18 +251,28 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId";
|
|
|
|
dbConnection:(YapDatabaseConnection *)dbConnection
|
|
|
|
dbConnection:(YapDatabaseConnection *)dbConnection
|
|
|
|
completion:(nullable OWSUserProfileCompletion)completion
|
|
|
|
completion:(nullable OWSUserProfileCompletion)completion
|
|
|
|
{
|
|
|
|
{
|
|
|
|
__block BOOL didChange = NO;
|
|
|
|
DDLogVerbose(@"%@ %s, before: %@", self.logTag, __PRETTY_FUNCTION__, self.debugDescription);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (self.hasEverBeenSaved) {
|
|
|
|
|
|
|
|
BOOL didChange = NO;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
didChange |= [self didStringChange:self.profileName newValue:[profileName ows_stripped]];
|
|
|
|
|
|
|
|
didChange |= [self didKeyChange:self.profileKey newValue:profileKey];
|
|
|
|
|
|
|
|
didChange |= [self didStringChange:self.avatarUrlPath newValue:avatarUrlPath];
|
|
|
|
|
|
|
|
didChange |= [self didStringChange:self.avatarFileName newValue:avatarFileName];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!didChange) {
|
|
|
|
|
|
|
|
DDLogVerbose(@"%@ Ignoring update in %s: %@", self.logTag, __PRETTY_FUNCTION__, self.debugDescription);
|
|
|
|
|
|
|
|
if (completion) {
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), completion);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
[self applyChangeToSelfAndLatestCopy:transaction
|
|
|
|
[self applyChangeToSelfAndLatestCopy:transaction
|
|
|
|
changeBlock:^(OWSUserProfile *userProfile) {
|
|
|
|
changeBlock:^(OWSUserProfile *userProfile) {
|
|
|
|
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];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[userProfile setProfileName:[profileName ows_stripped]];
|
|
|
|
[userProfile setProfileName:[profileName ows_stripped]];
|
|
|
|
[userProfile setProfileKey:profileKey];
|
|
|
|
[userProfile setProfileKey:profileKey];
|
|
|
|
[userProfile setAvatarUrlPath:avatarUrlPath];
|
|
|
|
[userProfile setAvatarUrlPath:avatarUrlPath];
|
|
|
@ -234,7 +280,7 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
saveIfMissing:YES];
|
|
|
|
saveIfMissing:YES];
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
[self finalizeWithCompletion:completion didChange:didChange];
|
|
|
|
[self finalizeWithCompletion:completion];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)updateWithAvatarUrlPath:(nullable NSString *)avatarUrlPath
|
|
|
|
- (void)updateWithAvatarUrlPath:(nullable NSString *)avatarUrlPath
|
|
|
@ -242,75 +288,124 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId";
|
|
|
|
dbConnection:(YapDatabaseConnection *)dbConnection
|
|
|
|
dbConnection:(YapDatabaseConnection *)dbConnection
|
|
|
|
completion:(nullable OWSUserProfileCompletion)completion
|
|
|
|
completion:(nullable OWSUserProfileCompletion)completion
|
|
|
|
{
|
|
|
|
{
|
|
|
|
__block BOOL didChange = NO;
|
|
|
|
DDLogVerbose(@"%@ %s, before: %@", self.logTag, __PRETTY_FUNCTION__, self.debugDescription);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (self.hasEverBeenSaved) {
|
|
|
|
|
|
|
|
BOOL didChange = NO;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
didChange |= [self didStringChange:self.avatarUrlPath newValue:avatarUrlPath];
|
|
|
|
|
|
|
|
didChange |= [self didStringChange:self.avatarFileName newValue:avatarFileName];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!didChange) {
|
|
|
|
|
|
|
|
DDLogVerbose(@"%@ Ignoring update in %s: %@", self.logTag, __PRETTY_FUNCTION__, self.debugDescription);
|
|
|
|
|
|
|
|
if (completion) {
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), completion);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
[self applyChangeToSelfAndLatestCopy:transaction
|
|
|
|
[self applyChangeToSelfAndLatestCopy:transaction
|
|
|
|
changeBlock:^(OWSUserProfile *userProfile) {
|
|
|
|
changeBlock:^(OWSUserProfile *userProfile) {
|
|
|
|
didChange |=
|
|
|
|
|
|
|
|
[self didStringChange:userProfile.avatarUrlPath newValue:avatarUrlPath];
|
|
|
|
|
|
|
|
didChange |=
|
|
|
|
|
|
|
|
[self didStringChange:userProfile.avatarFileName newValue:avatarFileName];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[userProfile setAvatarUrlPath:avatarUrlPath];
|
|
|
|
[userProfile setAvatarUrlPath:avatarUrlPath];
|
|
|
|
[userProfile setAvatarFileName:avatarFileName];
|
|
|
|
[userProfile setAvatarFileName:avatarFileName];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
saveIfMissing:YES];
|
|
|
|
saveIfMissing:YES];
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
[self finalizeWithCompletion:completion didChange:didChange];
|
|
|
|
[self finalizeWithCompletion:completion];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)updateWithAvatarFileName:(nullable NSString *)avatarFileName
|
|
|
|
- (void)updateWithAvatarFileName:(nullable NSString *)avatarFileName
|
|
|
|
dbConnection:(YapDatabaseConnection *)dbConnection
|
|
|
|
dbConnection:(YapDatabaseConnection *)dbConnection
|
|
|
|
completion:(nullable OWSUserProfileCompletion)completion
|
|
|
|
completion:(nullable OWSUserProfileCompletion)completion
|
|
|
|
{
|
|
|
|
{
|
|
|
|
__block BOOL didChange = NO;
|
|
|
|
DDLogVerbose(@"%@ %s, before: %@", self.logTag, __PRETTY_FUNCTION__, self.debugDescription);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (self.hasEverBeenSaved) {
|
|
|
|
|
|
|
|
BOOL didChange = NO;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
didChange |= [self didStringChange:self.avatarFileName newValue:avatarFileName];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!didChange) {
|
|
|
|
|
|
|
|
DDLogVerbose(@"%@ Ignoring update in %s: %@", self.logTag, __PRETTY_FUNCTION__, self.debugDescription);
|
|
|
|
|
|
|
|
if (completion) {
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), completion);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
[self applyChangeToSelfAndLatestCopy:transaction
|
|
|
|
[self applyChangeToSelfAndLatestCopy:transaction
|
|
|
|
changeBlock:^(OWSUserProfile *userProfile) {
|
|
|
|
changeBlock:^(OWSUserProfile *userProfile) {
|
|
|
|
didChange |=
|
|
|
|
|
|
|
|
[self didStringChange:userProfile.avatarFileName newValue:avatarFileName];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[userProfile setAvatarFileName:avatarFileName];
|
|
|
|
[userProfile setAvatarFileName:avatarFileName];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
saveIfMissing:YES];
|
|
|
|
saveIfMissing:YES];
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
[self finalizeWithCompletion:completion didChange:didChange];
|
|
|
|
[self finalizeWithCompletion:completion];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)updateWithLastUpdateDate:(nullable NSDate *)lastUpdateDate
|
|
|
|
- (void)updateWithLastUpdateDate:(nullable NSDate *)lastUpdateDate
|
|
|
|
dbConnection:(YapDatabaseConnection *)dbConnection
|
|
|
|
dbConnection:(YapDatabaseConnection *)dbConnection
|
|
|
|
completion:(nullable OWSUserProfileCompletion)completion
|
|
|
|
completion:(nullable OWSUserProfileCompletion)completion
|
|
|
|
{
|
|
|
|
{
|
|
|
|
__block BOOL didChange = NO;
|
|
|
|
DDLogVerbose(@"%@ %s, before: %@", self.logTag, __PRETTY_FUNCTION__, self.debugDescription);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (self.hasEverBeenSaved) {
|
|
|
|
|
|
|
|
BOOL didChange = NO;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
didChange |= [self didDateChange:self.lastUpdateDate newValue:lastUpdateDate];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!didChange) {
|
|
|
|
|
|
|
|
DDLogVerbose(@"%@ Ignoring update in %s: %@", self.logTag, __PRETTY_FUNCTION__, self.debugDescription);
|
|
|
|
|
|
|
|
if (completion) {
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), completion);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
[self applyChangeToSelfAndLatestCopy:transaction
|
|
|
|
[self applyChangeToSelfAndLatestCopy:transaction
|
|
|
|
changeBlock:^(OWSUserProfile *userProfile) {
|
|
|
|
changeBlock:^(OWSUserProfile *userProfile) {
|
|
|
|
didChange |=
|
|
|
|
|
|
|
|
[self didDateChange:userProfile.lastUpdateDate newValue:lastUpdateDate];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[userProfile setLastUpdateDate:lastUpdateDate];
|
|
|
|
[userProfile setLastUpdateDate:lastUpdateDate];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
saveIfMissing:YES];
|
|
|
|
saveIfMissing:YES];
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
[self finalizeWithCompletion:completion didChange:didChange];
|
|
|
|
[self finalizeWithCompletion:completion];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)clearWithProfileKey:(OWSAES256Key *)profileKey
|
|
|
|
- (void)clearWithProfileKey:(OWSAES256Key *)profileKey
|
|
|
|
dbConnection:(YapDatabaseConnection *)dbConnection
|
|
|
|
dbConnection:(YapDatabaseConnection *)dbConnection
|
|
|
|
completion:(nullable OWSUserProfileCompletion)completion;
|
|
|
|
completion:(nullable OWSUserProfileCompletion)completion;
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
DDLogVerbose(@"%@ %s, before: %@", self.logTag, __PRETTY_FUNCTION__, self.debugDescription);
|
|
|
|
|
|
|
|
|
|
|
|
OWSAssert(profileKey);
|
|
|
|
OWSAssert(profileKey);
|
|
|
|
|
|
|
|
|
|
|
|
__block BOOL didChange = NO;
|
|
|
|
if (self.hasEverBeenSaved) {
|
|
|
|
|
|
|
|
BOOL didChange = NO;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
didChange |= [self didKeyChange:self.profileKey newValue:profileKey];
|
|
|
|
|
|
|
|
didChange |= [self didStringChange:self.profileName newValue:nil];
|
|
|
|
|
|
|
|
didChange |= [self didStringChange:self.avatarUrlPath newValue:nil];
|
|
|
|
|
|
|
|
didChange |= [self didStringChange:self.avatarFileName newValue:nil];
|
|
|
|
|
|
|
|
didChange |= [self didDateChange:self.lastUpdateDate newValue:nil];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!didChange) {
|
|
|
|
|
|
|
|
DDLogVerbose(@"%@ Ignoring update in %s: %@", self.logTag, __PRETTY_FUNCTION__, self.debugDescription);
|
|
|
|
|
|
|
|
if (completion) {
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), completion);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
[self applyChangeToSelfAndLatestCopy:transaction
|
|
|
|
[self applyChangeToSelfAndLatestCopy:transaction
|
|
|
|
changeBlock:^(OWSUserProfile *userProfile) {
|
|
|
|
changeBlock:^(OWSUserProfile *userProfile) {
|
|
|
|
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];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[userProfile setProfileKey:profileKey];
|
|
|
|
[userProfile setProfileKey:profileKey];
|
|
|
|
[userProfile setProfileName:nil];
|
|
|
|
[userProfile setProfileName:nil];
|
|
|
|
[userProfile setAvatarUrlPath:nil];
|
|
|
|
[userProfile setAvatarUrlPath:nil];
|
|
|
@ -319,28 +414,39 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
saveIfMissing:YES];
|
|
|
|
saveIfMissing:YES];
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
[self finalizeWithCompletion:completion didChange:didChange];
|
|
|
|
[self finalizeWithCompletion:completion];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)updateWithProfileKey:(OWSAES256Key *)profileKey
|
|
|
|
- (void)updateWithProfileKey:(OWSAES256Key *)profileKey
|
|
|
|
dbConnection:(YapDatabaseConnection *)dbConnection
|
|
|
|
dbConnection:(YapDatabaseConnection *)dbConnection
|
|
|
|
completion:(nullable OWSUserProfileCompletion)completion;
|
|
|
|
completion:(nullable OWSUserProfileCompletion)completion;
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
DDLogVerbose(@"%@ %s, before: %@", self.logTag, __PRETTY_FUNCTION__, self.debugDescription);
|
|
|
|
|
|
|
|
|
|
|
|
OWSAssert(profileKey);
|
|
|
|
OWSAssert(profileKey);
|
|
|
|
|
|
|
|
|
|
|
|
self.profileKey = profileKey;
|
|
|
|
if (self.hasEverBeenSaved) {
|
|
|
|
|
|
|
|
BOOL didChange = NO;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
didChange |= [self didKeyChange:self.profileKey newValue:profileKey];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!didChange) {
|
|
|
|
|
|
|
|
DDLogVerbose(@"%@ Ignoring update in %s: %@", self.logTag, __PRETTY_FUNCTION__, self.debugDescription);
|
|
|
|
|
|
|
|
if (completion) {
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), completion);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
__block BOOL didChange = NO;
|
|
|
|
|
|
|
|
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
[self applyChangeToSelfAndLatestCopy:transaction
|
|
|
|
[self applyChangeToSelfAndLatestCopy:transaction
|
|
|
|
changeBlock:^(OWSUserProfile *userProfile) {
|
|
|
|
changeBlock:^(OWSUserProfile *userProfile) {
|
|
|
|
didChange |= [self didKeyChange:userProfile.profileKey newValue:profileKey];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[userProfile setProfileKey:profileKey];
|
|
|
|
[userProfile setProfileKey:profileKey];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
saveIfMissing:YES];
|
|
|
|
saveIfMissing:YES];
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
[self finalizeWithCompletion:completion didChange:didChange];
|
|
|
|
[self finalizeWithCompletion:completion];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (BOOL)didStringChange:(NSString *_Nullable)oldValue newValue:(NSString *_Nullable)newValue
|
|
|
|
- (BOOL)didStringChange:(NSString *_Nullable)oldValue newValue:(NSString *_Nullable)newValue
|
|
|
@ -406,6 +512,19 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId";
|
|
|
|
return TSYapDatabaseObject.dbReadWriteConnection;
|
|
|
|
return TSYapDatabaseObject.dbReadWriteConnection;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (NSString *)debugDescription
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return [NSString stringWithFormat:@"%@ %p %@ %@ %@ %@ %@ %f",
|
|
|
|
|
|
|
|
self.logTag,
|
|
|
|
|
|
|
|
self,
|
|
|
|
|
|
|
|
self.recipientId,
|
|
|
|
|
|
|
|
self.profileKey.keyData.hexadecimalString,
|
|
|
|
|
|
|
|
self.profileName,
|
|
|
|
|
|
|
|
self.avatarUrlPath,
|
|
|
|
|
|
|
|
self.avatarFileName,
|
|
|
|
|
|
|
|
self.lastUpdateDate.timeIntervalSinceNow];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|
|
|
|
NS_ASSUME_NONNULL_END
|
|
|
|