mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
76 lines
2.3 KiB
Objective-C
76 lines
2.3 KiB
Objective-C
//
|
|
// 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
|
|
groupMetaMessage:TSGroupMetaMessageUnspecified
|
|
quotedMessage:nil
|
|
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.
|
|
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
|