Persist profile whitelist and known profile keys.

// FREEBIE
pull/1/head
Matthew Chen 7 years ago
parent ec6283face
commit 202724cdcc

@ -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

@ -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

Loading…
Cancel
Save