Merge branch 'charlesmchen/profileManagerConcurrency'
This commit is contained in:
commit
fc26c3fdb1
@ -107,6 +107,8 @@
|
||||
3478506A1FD9B78A007B8332 /* AppSetup.h in Headers */ = {isa = PBXBuildFile; fileRef = 347850661FD9B789007B8332 /* AppSetup.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
3478506B1FD9B78A007B8332 /* NoopCallMessageHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347850671FD9B78A007B8332 /* NoopCallMessageHandler.swift */; };
|
||||
3478506C1FD9B78A007B8332 /* NoopNotificationsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347850681FD9B78A007B8332 /* NoopNotificationsManager.swift */; };
|
||||
347850711FDAEB17007B8332 /* OWSUserProfile.m in Sources */ = {isa = PBXBuildFile; fileRef = 3478506F1FDAEB16007B8332 /* OWSUserProfile.m */; };
|
||||
347850721FDAEB17007B8332 /* OWSUserProfile.h in Headers */ = {isa = PBXBuildFile; fileRef = 347850701FDAEB16007B8332 /* OWSUserProfile.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
3497DBEC1ECE257500DB2605 /* OWSCountryMetadata.m in Sources */ = {isa = PBXBuildFile; fileRef = 3497DBEB1ECE257500DB2605 /* OWSCountryMetadata.m */; };
|
||||
3497DBEF1ECE2E4700DB2605 /* DomainFrontingCountryViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3497DBEE1ECE2E4700DB2605 /* DomainFrontingCountryViewController.m */; };
|
||||
34B0796D1FCF46B100E248C2 /* MainAppContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B0796B1FCF46B000E248C2 /* MainAppContext.m */; };
|
||||
@ -584,6 +586,8 @@
|
||||
347850661FD9B789007B8332 /* AppSetup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppSetup.h; sourceTree = "<group>"; };
|
||||
347850671FD9B78A007B8332 /* NoopCallMessageHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NoopCallMessageHandler.swift; sourceTree = "<group>"; };
|
||||
347850681FD9B78A007B8332 /* NoopNotificationsManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NoopNotificationsManager.swift; sourceTree = "<group>"; };
|
||||
3478506F1FDAEB16007B8332 /* OWSUserProfile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSUserProfile.m; sourceTree = "<group>"; };
|
||||
347850701FDAEB16007B8332 /* OWSUserProfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSUserProfile.h; sourceTree = "<group>"; };
|
||||
348F2EAD1F0D21BC00D4ECE0 /* DeviceSleepManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeviceSleepManager.swift; sourceTree = "<group>"; };
|
||||
3495BC911F1426B800B478F5 /* ar */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ar; path = translations/ar.lproj/Localizable.strings; sourceTree = "<group>"; };
|
||||
3497DBEA1ECE257500DB2605 /* OWSCountryMetadata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSCountryMetadata.h; sourceTree = "<group>"; };
|
||||
@ -1225,6 +1229,8 @@
|
||||
children = (
|
||||
346129B11FD1F7E800532771 /* OWSProfileManager.h */,
|
||||
346129B21FD1F7E800532771 /* OWSProfileManager.m */,
|
||||
347850701FDAEB16007B8332 /* OWSUserProfile.h */,
|
||||
3478506F1FDAEB16007B8332 /* OWSUserProfile.m */,
|
||||
346129B31FD1F7E800532771 /* ProfileFetcherJob.swift */,
|
||||
);
|
||||
path = profiles;
|
||||
@ -2041,6 +2047,7 @@
|
||||
3461295A1FD1D74C00532771 /* Environment.h in Headers */,
|
||||
34480B631FD0A98800BC14EF /* UIView+OWS.h in Headers */,
|
||||
451F8A4B1FD715E1005CB9DA /* OWSGroupAvatarBuilder.h in Headers */,
|
||||
347850721FDAEB17007B8332 /* OWSUserProfile.h in Headers */,
|
||||
451F8A371FD71179005CB9DA /* OWSViewController.h in Headers */,
|
||||
454A965D1FD602B1008D2A0E /* OWSAudioAttachmentPlayer.h in Headers */,
|
||||
451F8A3E1FD713D2005CB9DA /* ThreadViewHelper.h in Headers */,
|
||||
@ -2730,6 +2737,7 @@
|
||||
346129F71FD5F31400532771 /* OWS105AttachmentFilePaths.m in Sources */,
|
||||
45194F931FD7215C00333B2C /* OWSContactOffersInteraction.m in Sources */,
|
||||
450998681FD8C0FF00D89EB3 /* AttachmentSharing.m in Sources */,
|
||||
347850711FDAEB17007B8332 /* OWSUserProfile.m in Sources */,
|
||||
346129761FD1E0B500532771 /* WeakTimer.swift in Sources */,
|
||||
346129F81FD5F31400532771 /* OWS100RemoveTSRecipientsMigration.m in Sources */,
|
||||
45E547201FD755E700DFC09E /* AttachmentApprovalViewController.swift in Sources */,
|
||||
|
||||
@ -356,7 +356,6 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
||||
DDLogWarn(@"%@ applicationDidBecomeActive.", self.logTag);
|
||||
|
||||
|
||||
@ -130,7 +130,9 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
CropScaleImageViewController *vc = [[CropScaleImageViewController alloc]
|
||||
initWithSrcImage:rawAvatar
|
||||
successCompletion:^(UIImage *_Nonnull dstImage) {
|
||||
[self.delegate avatarDidChange:dstImage];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.delegate avatarDidChange:dstImage];
|
||||
});
|
||||
}];
|
||||
[self.delegate.fromViewController
|
||||
presentViewController:vc
|
||||
|
||||
@ -64,6 +64,7 @@
|
||||
#import <MobileCoreServices/UTCoreTypes.h>
|
||||
#import <SignalMessaging/OWSContactOffersInteraction.h>
|
||||
#import <SignalMessaging/OWSFormat.h>
|
||||
#import <SignalMessaging/OWSUserProfile.h>
|
||||
#import <SignalMessaging/TSUnreadIndicatorInteraction.h>
|
||||
#import <SignalMessaging/ThreadUtil.h>
|
||||
#import <SignalMessaging/UIUtil.h>
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#import "Signal-Swift.h"
|
||||
#import "ViewControllerUtils.h"
|
||||
#import <SignalMessaging/OWSFormat.h>
|
||||
#import <SignalMessaging/OWSUserProfile.h>
|
||||
#import <SignalServiceKit/OWSMessageManager.h>
|
||||
#import <SignalServiceKit/TSContactThread.h>
|
||||
#import <SignalServiceKit/TSGroupThread.h>
|
||||
|
||||
@ -619,6 +619,7 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68;
|
||||
|
||||
- (void)avatarDidChange:(UIImage *)image
|
||||
{
|
||||
OWSAssert([NSThread isMainThread]);
|
||||
OWSAssert(image);
|
||||
|
||||
self.groupAvatar = image;
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
#import <Curve25519Kit/Curve25519.h>
|
||||
#import <SignalMessaging/OWSAvatarBuilder.h>
|
||||
#import <SignalMessaging/OWSProfileManager.h>
|
||||
#import <SignalMessaging/OWSUserProfile.h>
|
||||
#import <SignalMessaging/UIUtil.h>
|
||||
#import <SignalServiceKit/NSDate+OWS.h>
|
||||
#import <SignalServiceKit/OWSDisappearingConfigurationUpdateInfoMessage.h>
|
||||
|
||||
@ -577,6 +577,7 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
|
||||
|
||||
- (void)avatarDidChange:(UIImage *)image
|
||||
{
|
||||
OWSAssert([NSThread isMainThread]);
|
||||
OWSAssert(image);
|
||||
|
||||
self.avatar = [image resizedImageToFillPixelSize:CGSizeMake(kOWSProfileManager_MaxAvatarDiameter,
|
||||
|
||||
@ -496,6 +496,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (void)avatarDidChange:(UIImage *)image
|
||||
{
|
||||
OWSAssert([NSThread isMainThread]);
|
||||
OWSAssert(image);
|
||||
|
||||
self.groupAvatar = image;
|
||||
|
||||
@ -30,6 +30,7 @@ FOUNDATION_EXPORT const unsigned char SignalMessagingVersionString[];
|
||||
#import <SignalMessaging/OWSMath.h>
|
||||
#import <SignalMessaging/OWSProfileManager.h>
|
||||
#import <SignalMessaging/OWSTableViewController.h>
|
||||
#import <SignalMessaging/OWSUserProfile.h>
|
||||
#import <SignalMessaging/Release.h>
|
||||
#import <SignalMessaging/SharingThreadPickerViewController.h>
|
||||
#import <SignalMessaging/SignalKeyingStorage.h>
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#import "Environment.h"
|
||||
#import "OWSContactAvatarBuilder.h"
|
||||
#import "OWSContactsManager.h"
|
||||
#import "OWSUserProfile.h"
|
||||
#import "UIFont+OWS.h"
|
||||
#import "UIUtil.h"
|
||||
#import "UIView+OWS.h"
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#import "Environment.h"
|
||||
#import "OWSFormat.h"
|
||||
#import "OWSProfileManager.h"
|
||||
#import "OWSUserProfile.h"
|
||||
#import "ViewControllerUtils.h"
|
||||
#import <SignalMessaging/SignalMessaging-Swift.h>
|
||||
#import <SignalMessaging/UIColor+OWS.h>
|
||||
|
||||
@ -6,12 +6,7 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
extern NSString *const kNSNotificationName_LocalProfileDidChange;
|
||||
extern NSString *const kNSNotificationName_OtherUsersProfileWillChange;
|
||||
extern NSString *const kNSNotificationName_OtherUsersProfileDidChange;
|
||||
extern NSString *const kNSNotificationName_ProfileWhitelistDidChange;
|
||||
extern NSString *const kNSNotificationKey_ProfileRecipientId;
|
||||
extern NSString *const kNSNotificationKey_ProfileGroupId;
|
||||
|
||||
extern const NSUInteger kOWSProfileManager_NameDataLength;
|
||||
extern const NSUInteger kOWSProfileManager_MaxAvatarDiameter;
|
||||
@ -35,6 +30,9 @@ extern const NSUInteger kOWSProfileManager_MaxAvatarDiameter;
|
||||
|
||||
// These two methods should only be called from the main thread.
|
||||
- (OWSAES256Key *)localProfileKey;
|
||||
// localUserProfileExists is true if there is _ANY_ local profile.
|
||||
- (BOOL)localProfileExists;
|
||||
// hasLocalProfile is true if there is a local profile with a name or avatar.
|
||||
- (BOOL)hasLocalProfile;
|
||||
- (nullable NSString *)localProfileName;
|
||||
- (nullable UIImage *)localProfileAvatarImage;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
95
SignalMessaging/profiles/OWSUserProfile.h
Normal file
95
SignalMessaging/profiles/OWSUserProfile.h
Normal file
@ -0,0 +1,95 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import <SignalServiceKit/TSYapDatabaseObject.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
typedef void (^OWSUserProfileCompletion)(void);
|
||||
|
||||
@class OWSAES256Key;
|
||||
|
||||
extern NSString *const kNSNotificationName_LocalProfileDidChange;
|
||||
extern NSString *const kNSNotificationName_OtherUsersProfileWillChange;
|
||||
extern NSString *const kNSNotificationName_OtherUsersProfileDidChange;
|
||||
|
||||
extern NSString *const kNSNotificationKey_ProfileRecipientId;
|
||||
extern NSString *const kNSNotificationKey_ProfileGroupId;
|
||||
|
||||
extern NSString *const kLocalProfileUniqueId;
|
||||
|
||||
// This class should be completely thread-safe.
|
||||
//
|
||||
// It is critical for coherency that all DB operations for this
|
||||
// class should be done on OWSProfileManager's dbConnection.
|
||||
@interface OWSUserProfile : TSYapDatabaseObject
|
||||
|
||||
@property (atomic, readonly) NSString *recipientId;
|
||||
@property (atomic, readonly, nullable) OWSAES256Key *profileKey;
|
||||
@property (atomic, readonly, nullable) NSString *profileName;
|
||||
@property (atomic, readonly, nullable) NSString *avatarUrlPath;
|
||||
// This filename is relative to OWSProfileManager.profileAvatarsDirPath.
|
||||
@property (atomic, readonly, nullable) NSString *avatarFileName;
|
||||
|
||||
// This should reflect when either:
|
||||
//
|
||||
// * The last successful update finished.
|
||||
// * The current in-flight update began.
|
||||
@property (atomic, readonly, nullable) NSDate *lastUpdateDate;
|
||||
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
|
||||
+ (OWSUserProfile *)getOrBuildUserProfileForRecipientId:(NSString *)recipientId
|
||||
dbConnection:(YapDatabaseConnection *)dbConnection;
|
||||
|
||||
+ (BOOL)localUserProfileExists:(YapDatabaseConnection *)dbConnection;
|
||||
|
||||
#pragma mark - Update With... Methods
|
||||
|
||||
- (void)updateWithProfileName:(nullable NSString *)profileName
|
||||
profileKey:(OWSAES256Key *)profileKey
|
||||
avatarUrlPath:(nullable NSString *)avatarUrlPath
|
||||
avatarFileName:(nullable NSString *)avatarFileName
|
||||
dbConnection:(YapDatabaseConnection *)dbConnection
|
||||
completion:(nullable OWSUserProfileCompletion)completion;
|
||||
|
||||
- (void)updateWithProfileName:(nullable NSString *)profileName
|
||||
avatarUrlPath:(nullable NSString *)avatarUrlPath
|
||||
avatarFileName:(nullable NSString *)avatarFileName
|
||||
dbConnection:(YapDatabaseConnection *)dbConnection
|
||||
completion:(nullable OWSUserProfileCompletion)completion;
|
||||
|
||||
- (void)updateWithProfileName:(nullable NSString *)profileName
|
||||
avatarUrlPath:(nullable NSString *)avatarUrlPath
|
||||
avatarFileName:(nullable NSString *)avatarFileName
|
||||
lastUpdateDate:(nullable NSDate *)lastUpdateDate
|
||||
dbConnection:(YapDatabaseConnection *)dbConnection
|
||||
completion:(nullable OWSUserProfileCompletion)completion;
|
||||
|
||||
- (void)updateWithProfileName:(nullable NSString *)profileName
|
||||
avatarUrlPath:(nullable NSString *)avatarUrlPath
|
||||
lastUpdateDate:(nullable NSDate *)lastUpdateDate
|
||||
dbConnection:(YapDatabaseConnection *)dbConnection
|
||||
completion:(nullable OWSUserProfileCompletion)completion;
|
||||
|
||||
- (void)updateWithAvatarUrlPath:(nullable NSString *)avatarUrlPath
|
||||
avatarFileName:(nullable NSString *)avatarFileName
|
||||
dbConnection:(YapDatabaseConnection *)dbConnection
|
||||
completion:(nullable OWSUserProfileCompletion)completion;
|
||||
|
||||
- (void)updateWithAvatarFileName:(nullable NSString *)avatarFileName
|
||||
dbConnection:(YapDatabaseConnection *)dbConnection
|
||||
completion:(nullable OWSUserProfileCompletion)completion;
|
||||
|
||||
- (void)updateWithLastUpdateDate:(nullable NSDate *)lastUpdateDate
|
||||
dbConnection:(YapDatabaseConnection *)dbConnection
|
||||
completion:(nullable OWSUserProfileCompletion)completion;
|
||||
|
||||
- (void)clearWithProfileKey:(OWSAES256Key *)profileKey
|
||||
dbConnection:(YapDatabaseConnection *)dbConnection
|
||||
completion:(nullable OWSUserProfileCompletion)completion;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
354
SignalMessaging/profiles/OWSUserProfile.m
Normal file
354
SignalMessaging/profiles/OWSUserProfile.m
Normal file
@ -0,0 +1,354 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "OWSUserProfile.h"
|
||||
#import "NSString+OWS.h"
|
||||
#import <SignalServiceKit/AppContext.h>
|
||||
#import <SignalServiceKit/Cryptography.h>
|
||||
#import <SignalServiceKit/NSData+hexString.h>
|
||||
#import <SignalServiceKit/NSNotificationCenter+OWS.h>
|
||||
#import <SignalServiceKit/TSAccountManager.h>
|
||||
#import <YapDatabase/YapDatabaseConnection.h>
|
||||
#import <YapDatabase/YapDatabaseTransaction.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
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";
|
||||
|
||||
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
|
||||
|
||||
+ (NSString *)collection
|
||||
{
|
||||
// Legacy class name.
|
||||
return @"UserProfile";
|
||||
}
|
||||
|
||||
+ (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]) {
|
||||
[userProfile updateWithProfileKey:[OWSAES256Key generateRandomKey]
|
||||
dbConnection:dbConnection
|
||||
completion:nil];
|
||||
}
|
||||
}
|
||||
|
||||
OWSAssert(userProfile);
|
||||
|
||||
return userProfile;
|
||||
}
|
||||
|
||||
+ (BOOL)localUserProfileExists:(YapDatabaseConnection *)dbConnection
|
||||
{
|
||||
__block BOOL result = NO;
|
||||
[dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
||||
result = [OWSUserProfile fetchObjectWithUniqueID:kLocalProfileUniqueId transaction:transaction] != nil;
|
||||
}];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
- (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
|
||||
|
||||
// Similar in spirit to [TSYapDatabaseObject applyChangeToSelfAndLatestCopy],
|
||||
// but with significant differences.
|
||||
//
|
||||
// * We save if this entity is not in the database.
|
||||
// * We skip redundant saves by diffing.
|
||||
// * We kick off multi-device synchronization.
|
||||
// * We fire "did change" notifications.
|
||||
- (void)applyChanges:(void (^)(id))changeBlock
|
||||
functionName:(const char *)functionName
|
||||
dbConnection:(YapDatabaseConnection *)dbConnection
|
||||
completion:(nullable OWSUserProfileCompletion)completion
|
||||
{
|
||||
id beforeSnapshot = self.dictionaryValue;
|
||||
|
||||
changeBlock(self);
|
||||
|
||||
__block BOOL didChange = YES;
|
||||
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
NSString *collection = [[self class] collection];
|
||||
OWSUserProfile *latestInstance = [transaction objectForKey:self.uniqueId inCollection:collection];
|
||||
if (latestInstance) {
|
||||
changeBlock(latestInstance);
|
||||
|
||||
id afterSnapshot = latestInstance.dictionaryValue;
|
||||
if ([beforeSnapshot isEqual:afterSnapshot]) {
|
||||
DDLogVerbose(
|
||||
@"%@ Ignoring redundant update in %s: %@", self.logTag, functionName, self.debugDescription);
|
||||
didChange = NO;
|
||||
} else {
|
||||
[latestInstance saveWithTransaction:transaction];
|
||||
}
|
||||
} else {
|
||||
[self saveWithTransaction:transaction];
|
||||
}
|
||||
}];
|
||||
|
||||
if (completion) {
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), completion);
|
||||
}
|
||||
|
||||
if (!didChange) {
|
||||
return;
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
[[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,
|
||||
}];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)updateWithProfileName:(nullable NSString *)profileName
|
||||
avatarUrlPath:(nullable NSString *)avatarUrlPath
|
||||
avatarFileName:(nullable NSString *)avatarFileName
|
||||
dbConnection:(YapDatabaseConnection *)dbConnection
|
||||
completion:(nullable OWSUserProfileCompletion)completion
|
||||
{
|
||||
[self applyChanges:^(OWSUserProfile *userProfile) {
|
||||
[userProfile setProfileName:[profileName ows_stripped]];
|
||||
[userProfile setAvatarUrlPath:avatarUrlPath];
|
||||
[userProfile setAvatarFileName:avatarFileName];
|
||||
}
|
||||
functionName:__PRETTY_FUNCTION__
|
||||
dbConnection:dbConnection
|
||||
completion:completion];
|
||||
}
|
||||
|
||||
- (void)updateWithProfileName:(nullable NSString *)profileName
|
||||
avatarUrlPath:(nullable NSString *)avatarUrlPath
|
||||
avatarFileName:(nullable NSString *)avatarFileName
|
||||
lastUpdateDate:(nullable NSDate *)lastUpdateDate
|
||||
dbConnection:(YapDatabaseConnection *)dbConnection
|
||||
completion:(nullable OWSUserProfileCompletion)completion
|
||||
{
|
||||
[self applyChanges:^(OWSUserProfile *userProfile) {
|
||||
[userProfile setProfileName:[profileName ows_stripped]];
|
||||
[userProfile setAvatarUrlPath:avatarUrlPath];
|
||||
[userProfile setAvatarFileName:avatarFileName];
|
||||
[userProfile setLastUpdateDate:lastUpdateDate];
|
||||
}
|
||||
functionName:__PRETTY_FUNCTION__
|
||||
dbConnection:dbConnection
|
||||
completion:completion];
|
||||
}
|
||||
|
||||
- (void)updateWithProfileName:(nullable NSString *)profileName
|
||||
avatarUrlPath:(nullable NSString *)avatarUrlPath
|
||||
lastUpdateDate:(nullable NSDate *)lastUpdateDate
|
||||
dbConnection:(YapDatabaseConnection *)dbConnection
|
||||
completion:(nullable OWSUserProfileCompletion)completion
|
||||
{
|
||||
[self applyChanges:^(OWSUserProfile *userProfile) {
|
||||
[userProfile setProfileName:[profileName ows_stripped]];
|
||||
[userProfile setAvatarUrlPath:avatarUrlPath];
|
||||
[userProfile setLastUpdateDate:lastUpdateDate];
|
||||
}
|
||||
functionName:__PRETTY_FUNCTION__
|
||||
dbConnection:dbConnection
|
||||
completion:completion];
|
||||
}
|
||||
|
||||
- (void)updateWithProfileName:(nullable NSString *)profileName
|
||||
profileKey:(OWSAES256Key *)profileKey
|
||||
avatarUrlPath:(nullable NSString *)avatarUrlPath
|
||||
avatarFileName:(nullable NSString *)avatarFileName
|
||||
dbConnection:(YapDatabaseConnection *)dbConnection
|
||||
completion:(nullable OWSUserProfileCompletion)completion
|
||||
{
|
||||
[self applyChanges:^(OWSUserProfile *userProfile) {
|
||||
[userProfile setProfileName:[profileName ows_stripped]];
|
||||
[userProfile setProfileKey:profileKey];
|
||||
[userProfile setAvatarUrlPath:avatarUrlPath];
|
||||
[userProfile setAvatarFileName:avatarFileName];
|
||||
}
|
||||
functionName:__PRETTY_FUNCTION__
|
||||
dbConnection:dbConnection
|
||||
completion:completion];
|
||||
}
|
||||
|
||||
- (void)updateWithAvatarUrlPath:(nullable NSString *)avatarUrlPath
|
||||
avatarFileName:(nullable NSString *)avatarFileName
|
||||
dbConnection:(YapDatabaseConnection *)dbConnection
|
||||
completion:(nullable OWSUserProfileCompletion)completion
|
||||
{
|
||||
[self applyChanges:^(OWSUserProfile *userProfile) {
|
||||
[userProfile setAvatarUrlPath:avatarUrlPath];
|
||||
[userProfile setAvatarFileName:avatarFileName];
|
||||
}
|
||||
functionName:__PRETTY_FUNCTION__
|
||||
dbConnection:dbConnection
|
||||
completion:completion];
|
||||
}
|
||||
|
||||
- (void)updateWithAvatarFileName:(nullable NSString *)avatarFileName
|
||||
dbConnection:(YapDatabaseConnection *)dbConnection
|
||||
completion:(nullable OWSUserProfileCompletion)completion
|
||||
{
|
||||
[self applyChanges:^(OWSUserProfile *userProfile) {
|
||||
[userProfile setAvatarFileName:avatarFileName];
|
||||
}
|
||||
functionName:__PRETTY_FUNCTION__
|
||||
dbConnection:dbConnection
|
||||
completion:completion];
|
||||
}
|
||||
|
||||
- (void)updateWithLastUpdateDate:(nullable NSDate *)lastUpdateDate
|
||||
dbConnection:(YapDatabaseConnection *)dbConnection
|
||||
completion:(nullable OWSUserProfileCompletion)completion
|
||||
{
|
||||
[self applyChanges:^(OWSUserProfile *userProfile) {
|
||||
[userProfile setLastUpdateDate:lastUpdateDate];
|
||||
}
|
||||
functionName:__PRETTY_FUNCTION__
|
||||
dbConnection:dbConnection
|
||||
completion:completion];
|
||||
}
|
||||
|
||||
- (void)clearWithProfileKey:(OWSAES256Key *)profileKey
|
||||
dbConnection:(YapDatabaseConnection *)dbConnection
|
||||
completion:(nullable OWSUserProfileCompletion)completion;
|
||||
{
|
||||
[self applyChanges:^(OWSUserProfile *userProfile) {
|
||||
[userProfile setProfileKey:profileKey];
|
||||
[userProfile setProfileName:nil];
|
||||
[userProfile setAvatarUrlPath:nil];
|
||||
[userProfile setAvatarFileName:nil];
|
||||
[userProfile setLastUpdateDate:nil];
|
||||
}
|
||||
functionName:__PRETTY_FUNCTION__
|
||||
dbConnection:dbConnection
|
||||
completion:completion];
|
||||
}
|
||||
|
||||
- (void)updateWithProfileKey:(OWSAES256Key *)profileKey
|
||||
dbConnection:(YapDatabaseConnection *)dbConnection
|
||||
completion:(nullable OWSUserProfileCompletion)completion;
|
||||
{
|
||||
OWSAssert(profileKey);
|
||||
|
||||
[self applyChanges:^(OWSUserProfile *userProfile) {
|
||||
[userProfile setProfileKey:profileKey];
|
||||
}
|
||||
functionName:__PRETTY_FUNCTION__
|
||||
dbConnection:dbConnection
|
||||
completion:completion];
|
||||
}
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
// This should only be used in verbose, developer-only logs.
|
||||
- (NSString *)debugDescription
|
||||
{
|
||||
return [NSString stringWithFormat:@"%@ %p %@ %zd %@ %@ %@ %f",
|
||||
self.logTag,
|
||||
self,
|
||||
self.recipientId,
|
||||
self.profileKey.keyData.length,
|
||||
self.profileName,
|
||||
self.avatarUrlPath,
|
||||
self.avatarFileName,
|
||||
self.lastUpdateDate.timeIntervalSinceNow];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@ -29,7 +29,12 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (nullable instancetype)initWithCoder:(NSCoder *)coder
|
||||
{
|
||||
return [super initWithCoder:coder];
|
||||
self = [super initWithCoder:coder];
|
||||
if (!self) {
|
||||
return self;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)saveWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
@ -200,8 +205,6 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
#pragma mark Update With...
|
||||
|
||||
// This method does the work for the "updateWith..." methods. Please see
|
||||
// the header for a discussion of those methods.
|
||||
- (void)applyChangeToSelfAndLatestCopy:(YapDatabaseReadWriteTransaction *)transaction
|
||||
changeBlock:(void (^)(id))changeBlock
|
||||
{
|
||||
|
||||
@ -232,10 +232,14 @@ public class ShareViewController: UINavigationController, ShareViewDelegate, SAE
|
||||
|
||||
Logger.info("Presenting initial root view controller")
|
||||
|
||||
if TSAccountManager.isRegistered() {
|
||||
presentConversationPicker()
|
||||
} else {
|
||||
if !TSAccountManager.isRegistered() {
|
||||
showNotRegisteredView()
|
||||
} else if !OWSProfileManager.shared().localProfileExists() {
|
||||
// This is a rare edge case, but we want to ensure that the user
|
||||
// is has already saved their local profile key in the main app.
|
||||
showNotReadyView()
|
||||
} else {
|
||||
presentConversationPicker()
|
||||
}
|
||||
|
||||
// We don't use the AppUpdateNag in the SAE.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user