2017-08-24 21:42:21 +02:00
|
|
|
//
|
2019-01-14 17:00:24 +01:00
|
|
|
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
2017-08-24 21:42:21 +02:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "OWSProfileKeyMessage.h"
|
|
|
|
#import "ProfileManagerProtocol.h"
|
2018-08-02 19:29:24 +02:00
|
|
|
#import "ProtoUtils.h"
|
2018-08-31 19:12:40 +02:00
|
|
|
#import "SSKEnvironment.h"
|
2018-08-01 23:13:01 +02:00
|
|
|
#import <SignalServiceKit/SignalServiceKit-Swift.h>
|
2017-08-24 21:42:21 +02:00
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
@implementation OWSProfileKeyMessage
|
|
|
|
|
2018-02-07 18:44:09 +01:00
|
|
|
- (instancetype)initWithTimestamp:(uint64_t)timestamp inThread:(nullable TSThread *)thread
|
|
|
|
{
|
|
|
|
return [super initOutgoingMessageWithTimestamp:timestamp
|
|
|
|
inThread:thread
|
|
|
|
messageBody:nil
|
|
|
|
attachmentIds:[NSMutableArray new]
|
|
|
|
expiresInSeconds:0
|
|
|
|
expireStartedAt:0
|
|
|
|
isVoiceMessage:NO
|
2018-08-31 18:43:05 +02:00
|
|
|
groupMetaMessage:TSGroupMetaMessageUnspecified
|
2018-04-27 21:29:19 +02:00
|
|
|
quotedMessage:nil
|
2019-01-14 17:00:24 +01:00
|
|
|
contactShare:nil
|
|
|
|
linkPreview:nil];
|
2018-02-07 18:44:09 +01:00
|
|
|
}
|
|
|
|
|
2018-06-07 17:52:39 +02:00
|
|
|
- (nullable instancetype)initWithCoder:(NSCoder *)coder
|
|
|
|
{
|
|
|
|
return [super initWithCoder:coder];
|
|
|
|
}
|
|
|
|
|
2017-11-15 23:53:16 +01:00
|
|
|
- (BOOL)shouldBeSaved
|
2017-08-24 21:42:21 +02:00
|
|
|
{
|
2017-11-15 23:53:16 +01:00
|
|
|
return NO;
|
2017-08-24 21:42:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)shouldSyncTranscript
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2018-08-02 15:34:50 +02:00
|
|
|
- (nullable SSKProtoDataMessage *)buildDataMessage:(NSString *_Nullable)recipientId
|
2017-08-24 21:42:21 +02:00
|
|
|
{
|
2018-09-06 19:01:24 +02:00
|
|
|
OWSAssertDebug(self.thread);
|
2018-08-02 19:29:24 +02:00
|
|
|
|
|
|
|
SSKProtoDataMessageBuilder *_Nullable builder = [self dataMessageBuilder];
|
|
|
|
if (!builder) {
|
2018-08-27 18:51:32 +02:00
|
|
|
OWSFailDebug(@"could not build protobuf.");
|
2018-08-02 19:29:24 +02:00
|
|
|
return nil;
|
|
|
|
}
|
2018-01-31 20:30:34 +01:00
|
|
|
[builder setTimestamp:self.timestamp];
|
2018-08-02 19:29:24 +02:00
|
|
|
[ProtoUtils addLocalProfileKeyToDataMessageBuilder:builder];
|
2018-08-01 23:13:01 +02:00
|
|
|
[builder setFlags:SSKProtoDataMessageFlagsProfileKeyUpdate];
|
2017-08-24 21:42:21 +02:00
|
|
|
|
|
|
|
if (recipientId.length > 0) {
|
|
|
|
// Once we've shared our profile key with a user (perhaps due to being
|
|
|
|
// a member of a whitelisted group), make sure they're whitelisted.
|
2018-09-17 15:27:58 +02:00
|
|
|
id<ProfileManagerProtocol> profileManager = SSKEnvironment.shared.profileManager;
|
2017-09-25 05:51:58 +02:00
|
|
|
[profileManager addUserToProfileWhitelist:recipientId];
|
2017-08-24 21:42:21 +02:00
|
|
|
}
|
|
|
|
|
2018-08-02 15:34:50 +02:00
|
|
|
NSError *error;
|
|
|
|
SSKProtoDataMessage *_Nullable dataProto = [builder buildAndReturnError:&error];
|
|
|
|
if (error || !dataProto) {
|
2018-08-27 18:51:32 +02:00
|
|
|
OWSFailDebug(@"could not build protobuf: %@", error);
|
2018-08-02 15:34:50 +02:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
return dataProto;
|
2017-08-24 21:42:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|