// // Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "OWSProfileKeyMessage.h" #import "ProfileManagerProtocol.h" #import "ProtoBuf+OWS.h" #import "TextSecureKitEnv.h" #import NS_ASSUME_NONNULL_BEGIN @implementation OWSProfileKeyMessage - (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 groupMetaMessage:TSGroupMessageUnspecified quotedMessage:nil contactShare:nil]; } - (nullable instancetype)initWithCoder:(NSCoder *)coder { return [super initWithCoder:coder]; } - (BOOL)shouldBeSaved { return NO; } - (BOOL)shouldSyncTranscript { return NO; } - (nullable SSKProtoDataMessage *)buildDataMessage:(NSString *_Nullable)recipientId { OWSAssert(self.thread); SSKProtoDataMessageBuilder *builder = [self dataMessageBuilder]; [builder setTimestamp:self.timestamp]; [builder addLocalProfileKey]; [builder setFlags:SSKProtoDataMessageFlagsProfileKeyUpdate]; 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. id profileManager = [TextSecureKitEnv sharedEnv].profileManager; [profileManager addUserToProfileWhitelist:recipientId]; } NSError *error; SSKProtoDataMessage *_Nullable dataProto = [builder buildAndReturnError:&error]; if (error || !dataProto) { OWSFail(@"%@ could not build protobuf: %@", self.logTag, error); return nil; } return dataProto; } @end NS_ASSUME_NONNULL_END