session-ios/SignalServiceKit/src/Messages/OWSProfileKeyMessage.m

77 lines
2.3 KiB
Mathematica
Raw Normal View History

//
2019-01-14 17:00:24 +01:00
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
//
#import "OWSProfileKeyMessage.h"
#import "ProfileManagerProtocol.h"
#import "ProtoUtils.h"
#import "SSKEnvironment.h"
#import <SignalServiceKit/SignalServiceKit-Swift.h>
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
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];
}
- (nullable instancetype)initWithCoder:(NSCoder *)coder
{
return [super initWithCoder:coder];
}
- (BOOL)shouldBeSaved
{
return NO;
}
- (BOOL)shouldSyncTranscript
{
return NO;
}
- (nullable SSKProtoDataMessage *)buildDataMessage:(NSString *_Nullable)recipientId
{
OWSAssertDebug(self.thread);
SSKProtoDataMessageBuilder *_Nullable builder = [self dataMessageBuilder];
if (!builder) {
OWSFailDebug(@"could not build protobuf.");
return nil;
}
[builder setTimestamp:self.timestamp];
[ProtoUtils addLocalProfileKeyToDataMessageBuilder:builder];
[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.
2018-09-17 15:27:58 +02:00
id<ProfileManagerProtocol> profileManager = SSKEnvironment.shared.profileManager;
[profileManager addUserToProfileWhitelist:recipientId];
}
NSError *error;
SSKProtoDataMessage *_Nullable dataProto = [builder buildAndReturnError:&error];
if (error || !dataProto) {
OWSFailDebug(@"could not build protobuf: %@", error);
return nil;
}
return dataProto;
}
@end
NS_ASSUME_NONNULL_END