mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.1 KiB
Objective-C
89 lines
2.1 KiB
Objective-C
//
|
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
|
//
|
|
|
|
#import "ProfileManagerProtocol.h"
|
|
#import "ProtoBuf+OWS.h"
|
|
#import "SignalRecipient.h"
|
|
#import "TSThread.h"
|
|
#import "TextSecureKitEnv.h"
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
@implementation PBGeneratedMessageBuilder (OWS)
|
|
|
|
- (BOOL)shouldMessageHaveLocalProfileKey:(TSThread *)thread recipientId:(NSString *)recipientId
|
|
// recipient:(SignalRecipient *)recipient
|
|
{
|
|
OWSAssert(thread);
|
|
OWSAssert(recipientId.length > 0);
|
|
|
|
id<ProfileManagerProtocol> profileManager = [TextSecureKitEnv sharedEnv].profileManager;
|
|
|
|
// For 1:1 threads, we want to include the profile key IFF the
|
|
// contact is in the whitelist.
|
|
//
|
|
// For Group threads, we want to include the profile key IFF the
|
|
// recipient OR the group is in the whitelist.
|
|
if ([profileManager isUserInProfileWhitelist:recipientId]) {
|
|
return YES;
|
|
} else if ([profileManager isThreadInProfileWhitelist:thread]) {
|
|
return YES;
|
|
}
|
|
|
|
return NO;
|
|
}
|
|
|
|
- (NSData *)localProfileKey
|
|
{
|
|
id<ProfileManagerProtocol> profileManager = [TextSecureKitEnv sharedEnv].profileManager;
|
|
return profileManager.localProfileKey;
|
|
}
|
|
|
|
@end
|
|
|
|
#pragma mark -
|
|
|
|
@implementation OWSSignalServiceProtosDataMessageBuilder (OWS)
|
|
|
|
- (void)addLocalProfileKeyIfNecessary:(TSThread *)thread recipientId:(NSString *)recipientId
|
|
{
|
|
OWSAssert(thread);
|
|
OWSAssert(recipientId.length > 0);
|
|
|
|
if ([self shouldMessageHaveLocalProfileKey:thread recipientId:recipientId]) {
|
|
[self setProfileKey:self.localProfileKey];
|
|
}
|
|
}
|
|
|
|
@end
|
|
|
|
#pragma mark -
|
|
|
|
@implementation OWSSignalServiceProtosCallMessageBuilder (OWS)
|
|
|
|
- (void)addLocalProfileKeyIfNecessary:(TSThread *)thread recipientId:(NSString *)recipientId
|
|
{
|
|
OWSAssert(thread);
|
|
OWSAssert(recipientId.length > 0);
|
|
|
|
if ([self shouldMessageHaveLocalProfileKey:thread recipientId:recipientId]) {
|
|
[self setProfileKey:self.localProfileKey];
|
|
}
|
|
}
|
|
|
|
@end
|
|
|
|
#pragma mark -
|
|
|
|
@implementation OWSSignalServiceProtosSyncMessageBuilder (OWS)
|
|
|
|
- (void)addLocalProfileKey
|
|
{
|
|
[self setProfileKey:self.localProfileKey];
|
|
}
|
|
|
|
@end
|
|
|
|
NS_ASSUME_NONNULL_END
|