2020-11-11 00:58:56 +01:00
|
|
|
//
|
|
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "ProtoUtils.h"
|
|
|
|
#import "ProfileManagerProtocol.h"
|
|
|
|
#import "SSKEnvironment.h"
|
|
|
|
#import "TSThread.h"
|
2020-11-12 00:41:45 +01:00
|
|
|
#import <SignalCoreKit/Cryptography.h>
|
2020-11-25 06:15:16 +01:00
|
|
|
#import <SessionMessagingKit/SessionMessagingKit-Swift.h>
|
2020-11-11 00:58:56 +01:00
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
@implementation ProtoUtils
|
|
|
|
|
|
|
|
#pragma mark - Dependencies
|
|
|
|
|
|
|
|
+ (id<ProfileManagerProtocol>)profileManager {
|
|
|
|
return SSKEnvironment.shared.profileManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (OWSAES256Key *)localProfileKey
|
|
|
|
{
|
2021-07-22 06:52:10 +02:00
|
|
|
return [[LKStorage.shared getUser] profileEncryptionKey];
|
2020-11-11 00:58:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
+ (BOOL)shouldMessageHaveLocalProfileKey:(TSThread *)thread recipientId:(NSString *_Nullable)recipientId
|
|
|
|
{
|
2020-11-16 00:34:47 +01:00
|
|
|
return YES;
|
2020-11-11 00:58:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (void)addLocalProfileKeyIfNecessary:(TSThread *)thread
|
|
|
|
recipientId:(NSString *_Nullable)recipientId
|
2020-11-17 06:23:13 +01:00
|
|
|
dataMessageBuilder:(SNProtoDataMessageBuilder *)dataMessageBuilder
|
2020-11-11 00:58:56 +01:00
|
|
|
{
|
|
|
|
if ([self shouldMessageHaveLocalProfileKey:thread recipientId:recipientId]) {
|
|
|
|
[dataMessageBuilder setProfileKey:self.localProfileKey.keyData];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-17 06:23:13 +01:00
|
|
|
+ (void)addLocalProfileKeyToDataMessageBuilder:(SNProtoDataMessageBuilder *)dataMessageBuilder
|
2020-11-11 00:58:56 +01:00
|
|
|
{
|
|
|
|
[dataMessageBuilder setProfileKey:self.localProfileKey.keyData];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|