2017-07-31 20:48:43 +02:00
|
|
|
//
|
2018-02-20 23:37:14 +01:00
|
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
2017-07-31 20:48:43 +02:00
|
|
|
//
|
|
|
|
|
2017-08-02 19:12:26 +02:00
|
|
|
#import <SignalServiceKit/ProfileManagerProtocol.h>
|
|
|
|
|
2017-07-31 20:48:43 +02:00
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
2017-08-17 00:09:47 +02:00
|
|
|
extern NSString *const kNSNotificationName_ProfileWhitelistDidChange;
|
2018-10-12 17:51:17 +02:00
|
|
|
extern NSString *const kNSNotificationName_ProfileKeyDidChange;
|
2017-08-01 19:53:51 +02:00
|
|
|
|
2017-09-01 20:52:17 +02:00
|
|
|
extern const NSUInteger kOWSProfileManager_NameDataLength;
|
2017-09-01 22:49:03 +02:00
|
|
|
extern const NSUInteger kOWSProfileManager_MaxAvatarDiameter;
|
2017-08-15 17:37:12 +02:00
|
|
|
|
2017-08-21 17:21:23 +02:00
|
|
|
@class OWSAES256Key;
|
2017-08-28 22:45:24 +02:00
|
|
|
@class OWSMessageSender;
|
2018-09-17 15:27:58 +02:00
|
|
|
@class OWSPrimaryStorage;
|
|
|
|
@class TSNetworkManager;
|
2017-09-25 18:38:35 +02:00
|
|
|
@class TSThread;
|
2019-05-28 05:04:32 +02:00
|
|
|
@class YapDatabaseReadWriteTransaction;
|
2017-08-03 18:05:53 +02:00
|
|
|
|
2017-07-31 20:48:43 +02:00
|
|
|
// This class can be safely accessed and used from any thread.
|
2017-08-02 19:12:26 +02:00
|
|
|
@interface OWSProfileManager : NSObject <ProfileManagerProtocol>
|
2017-07-31 20:48:43 +02:00
|
|
|
|
|
|
|
- (instancetype)init NS_UNAVAILABLE;
|
|
|
|
|
2018-10-10 14:55:20 +02:00
|
|
|
- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage;
|
2018-09-17 15:27:58 +02:00
|
|
|
|
2017-07-31 20:48:43 +02:00
|
|
|
+ (instancetype)sharedManager;
|
|
|
|
|
2017-08-01 18:52:15 +02:00
|
|
|
#pragma mark - Local Profile
|
|
|
|
|
2017-08-02 16:36:54 +02:00
|
|
|
// These two methods should only be called from the main thread.
|
2017-08-21 17:21:23 +02:00
|
|
|
- (OWSAES256Key *)localProfileKey;
|
2017-12-08 20:43:11 +01:00
|
|
|
// localUserProfileExists is true if there is _ANY_ local profile.
|
|
|
|
- (BOOL)localProfileExists;
|
2017-12-11 18:37:47 +01:00
|
|
|
// hasLocalProfile is true if there is a local profile with a name or avatar.
|
2017-08-03 23:43:21 +02:00
|
|
|
- (BOOL)hasLocalProfile;
|
2017-08-02 18:03:06 +02:00
|
|
|
- (nullable NSString *)localProfileName;
|
|
|
|
- (nullable UIImage *)localProfileAvatarImage;
|
2018-11-28 18:55:01 +01:00
|
|
|
- (nullable NSData *)localProfileAvatarData;
|
2017-09-07 16:28:19 +02:00
|
|
|
- (void)ensureLocalProfileCached;
|
2017-07-31 23:49:52 +02:00
|
|
|
|
2017-08-01 16:51:01 +02:00
|
|
|
// This method is used to update the "local profile" state on the client
|
|
|
|
// and the service. Client state is only updated if service state is
|
|
|
|
// successfully updated.
|
2017-08-02 16:36:54 +02:00
|
|
|
//
|
|
|
|
// This method should only be called from the main thread.
|
|
|
|
- (void)updateLocalProfileName:(nullable NSString *)profileName
|
|
|
|
avatarImage:(nullable UIImage *)avatarImage
|
2017-11-08 20:04:51 +01:00
|
|
|
success:(void (^)(void))successBlock
|
|
|
|
failure:(void (^)(void))failureBlock;
|
2017-08-01 16:51:01 +02:00
|
|
|
|
2017-08-25 00:02:33 +02:00
|
|
|
- (BOOL)isProfileNameTooLong:(nullable NSString *)profileName;
|
|
|
|
|
2018-11-28 16:02:48 +01:00
|
|
|
- (void)fetchLocalUsersProfile;
|
|
|
|
|
2017-08-01 18:52:15 +02:00
|
|
|
#pragma mark - Profile Whitelist
|
|
|
|
|
2017-08-16 21:32:56 +02:00
|
|
|
// These methods are for debugging.
|
|
|
|
- (void)clearProfileWhitelist;
|
|
|
|
- (void)logProfileWhitelist;
|
2017-08-24 17:27:36 +02:00
|
|
|
- (void)regenerateLocalProfile;
|
2017-08-16 21:32:56 +02:00
|
|
|
|
2017-08-03 23:43:21 +02:00
|
|
|
- (void)addThreadToProfileWhitelist:(TSThread *)thread;
|
2017-08-01 18:52:15 +02:00
|
|
|
|
2017-08-01 19:53:51 +02:00
|
|
|
- (void)setContactRecipientIds:(NSArray<NSString *> *)contactRecipientIds;
|
|
|
|
|
2017-08-02 15:27:29 +02:00
|
|
|
#pragma mark - Other User's Profiles
|
2017-08-01 18:52:15 +02:00
|
|
|
|
2017-09-07 21:33:12 +02:00
|
|
|
// This method is for debugging.
|
|
|
|
- (void)logUserProfiles;
|
|
|
|
|
2017-08-21 17:21:23 +02:00
|
|
|
- (nullable OWSAES256Key *)profileKeyForRecipientId:(NSString *)recipientId;
|
2017-08-01 18:52:15 +02:00
|
|
|
|
2017-08-02 15:27:29 +02:00
|
|
|
- (nullable NSString *)profileNameForRecipientId:(NSString *)recipientId;
|
|
|
|
|
|
|
|
- (nullable UIImage *)profileAvatarForRecipientId:(NSString *)recipientId;
|
2018-05-10 03:10:23 +02:00
|
|
|
- (nullable NSData *)profileAvatarDataForRecipientId:(NSString *)recipientId;
|
2017-08-02 15:27:29 +02:00
|
|
|
|
2017-08-03 17:13:40 +02:00
|
|
|
- (void)updateProfileForRecipientId:(NSString *)recipientId
|
2017-08-14 17:31:43 +02:00
|
|
|
profileNameEncrypted:(nullable NSData *)profileNameEncrypted
|
2017-08-14 20:51:51 +02:00
|
|
|
avatarUrlPath:(nullable NSString *)avatarUrlPath;
|
2017-08-03 17:13:40 +02:00
|
|
|
|
2019-05-28 05:04:32 +02:00
|
|
|
- (void)setDisplayNameForContactWithID:(NSString *)contactID to:(NSString *)displayName with:(YapDatabaseReadWriteTransaction *)transaction;
|
|
|
|
|
2017-08-28 22:45:24 +02:00
|
|
|
#pragma mark - User Interface
|
|
|
|
|
|
|
|
- (void)presentAddThreadToProfileWhitelist:(TSThread *)thread
|
|
|
|
fromViewController:(UIViewController *)fromViewController
|
2017-11-08 20:04:51 +01:00
|
|
|
success:(void (^)(void))successHandler;
|
2017-08-28 22:45:24 +02:00
|
|
|
|
2017-07-31 20:48:43 +02:00
|
|
|
@end
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|