diff --git a/SignalServiceKit/src/Profiles/OWSProfilesManager.h b/SignalServiceKit/src/Profiles/OWSProfilesManager.h index bddbcae48..95c115d5a 100644 --- a/SignalServiceKit/src/Profiles/OWSProfilesManager.h +++ b/SignalServiceKit/src/Profiles/OWSProfilesManager.h @@ -13,6 +13,8 @@ extern NSString *const kNSNotificationName_LocalProfileDidChange; + (instancetype)sharedManager; +#pragma mark - Local Profile + @property (atomic, nullable, readonly) NSString *localProfileName; @property (atomic, nullable, readonly) UIImage *localProfileAvatarImage; @@ -26,6 +28,18 @@ extern NSString *const kNSNotificationName_LocalProfileDidChange; - (void)appLaunchDidBegin; +#pragma mark - Profile Whitelist + +- (void)addUserToProfileWhitelist:(NSString *)recipientId; + +- (BOOL)isUserInProfileWhitelist:(NSString *)recipientId; + +#pragma mark - Known Profile Keys + +- (void)setProfileKey:(NSData *)profileKey forRecipientId:(NSString *)recipientId; + +- (nullable NSData *)profileKeyForRecipientId:(NSString *)recipientId; + @end NS_ASSUME_NONNULL_END diff --git a/SignalServiceKit/src/Profiles/OWSProfilesManager.m b/SignalServiceKit/src/Profiles/OWSProfilesManager.m index 61b7284e8..5b08e4196 100644 --- a/SignalServiceKit/src/Profiles/OWSProfilesManager.m +++ b/SignalServiceKit/src/Profiles/OWSProfilesManager.m @@ -82,6 +82,10 @@ NSString *const kOWSProfilesManager_LocalProfileNameKey = @"kOWSProfilesManager_ NSString *const kOWSProfilesManager_LocalProfileAvatarMetadataKey = @"kOWSProfilesManager_LocalProfileAvatarMetadataKey"; +NSString *const kOWSProfilesManager_WhitelistCollection = @"kOWSProfilesManager_WhitelistCollection"; + +NSString *const kOWSProfilesManager_KnownProfileKeysCollection = @"kOWSProfilesManager_KnownProfileKeysCollection"; + // TODO: static const NSInteger kProfileKeyLength = 16; @@ -403,6 +407,46 @@ static const NSInteger kProfileKeyLength = 16; }); } +#pragma mark - Profile Whitelist + +- (void)addUserToProfileWhitelist:(NSString *)recipientId +{ + OWSAssert(recipientId.length > 0); + + [self.dbConnection setObject:@(1) forKey:recipientId inCollection:kOWSProfilesManager_WhitelistCollection]; +} + +- (BOOL)isUserInProfileWhitelist:(NSString *)recipientId +{ + OWSAssert(recipientId.length > 0); + + return (nil != [self.dbConnection objectForKey:recipientId inCollection:kOWSProfilesManager_WhitelistCollection]); +} + +#pragma mark - Known Profile Keys + +- (void)setProfileKey:(NSData *)profileKey forRecipientId:(NSString *)recipientId +{ + OWSAssert(profileKey.length == kProfileKeyLength); + OWSAssert(recipientId.length > 0); + + [self.dbConnection setObject:profileKey + forKey:recipientId + inCollection:kOWSProfilesManager_KnownProfileKeysCollection]; +} + +- (nullable NSData *)profileKeyForRecipientId:(NSString *)recipientId +{ + OWSAssert(recipientId.length > 0); + + NSData *_Nullable profileKey = + [self.dbConnection objectForKey:recipientId inCollection:kOWSProfilesManager_KnownProfileKeysCollection]; + if (profileKey) { + OWSAssert(profileKey.length == kProfileKeyLength); + } + return profileKey; +} + #pragma mark - Avatar Disk Cache - (nullable UIImage *)loadProfileAvatarWithFilename:(NSString *)fileName