session-ios/SignalUtilitiesKit/Utilities/ProtoUtils.m

70 lines
1.8 KiB
Mathematica
Raw Normal View History

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-11 00:58:56 +01:00
#import <SignalUtilitiesKit/SignalUtilitiesKit-Swift.h>
NS_ASSUME_NONNULL_BEGIN
@implementation ProtoUtils
#pragma mark - Dependencies
+ (id<ProfileManagerProtocol>)profileManager {
return SSKEnvironment.shared.profileManager;
}
+ (OWSAES256Key *)localProfileKey
{
return self.profileManager.localProfileKey;
}
#pragma mark -
+ (BOOL)shouldMessageHaveLocalProfileKey:(TSThread *)thread recipientId:(NSString *_Nullable)recipientId
{
OWSAssertDebug(thread);
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
dataMessageBuilder:(SSKProtoDataMessageBuilder *)dataMessageBuilder
{
OWSAssertDebug(thread);
OWSAssertDebug(dataMessageBuilder);
if ([self shouldMessageHaveLocalProfileKey:thread recipientId:recipientId]) {
[dataMessageBuilder setProfileKey:self.localProfileKey.keyData];
}
}
+ (void)addLocalProfileKeyToDataMessageBuilder:(SSKProtoDataMessageBuilder *)dataMessageBuilder
{
OWSAssertDebug(dataMessageBuilder);
[dataMessageBuilder setProfileKey:self.localProfileKey.keyData];
}
+ (void)addLocalProfileKeyIfNecessary:(TSThread *)thread
recipientId:(NSString *)recipientId
callMessageBuilder:(SSKProtoCallMessageBuilder *)callMessageBuilder
{
OWSAssertDebug(thread);
OWSAssertDebug(recipientId.length > 0);
OWSAssertDebug(callMessageBuilder);
if ([self shouldMessageHaveLocalProfileKey:thread recipientId:recipientId]) {
[callMessageBuilder setProfileKey:self.localProfileKey.keyData];
}
}
@end
NS_ASSUME_NONNULL_END