mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
73 lines
2 KiB
Objective-C
73 lines
2 KiB
Objective-C
//
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
|
//
|
|
|
|
#import "OWSOutgoingSyncMessage.h"
|
|
#import "Cryptography.h"
|
|
#import "NSDate+OWS.h"
|
|
#import "OWSSignalServiceProtos.pb.h"
|
|
#import "ProtoBuf+OWS.h"
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
@implementation OWSOutgoingSyncMessage
|
|
|
|
- (instancetype)init
|
|
{
|
|
self = [super initOutgoingMessageWithTimestamp:[NSDate ows_millisecondTimeStamp]
|
|
inThread:nil
|
|
messageBody:nil
|
|
attachmentIds:[NSMutableArray new]
|
|
expiresInSeconds:0
|
|
expireStartedAt:0
|
|
isVoiceMessage:NO
|
|
groupMetaMessage:TSGroupMessageUnspecified
|
|
quotedMessage:nil
|
|
contactShare:nil];
|
|
|
|
if (!self) {
|
|
return self;
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
- (BOOL)shouldBeSaved
|
|
{
|
|
return NO;
|
|
}
|
|
|
|
- (BOOL)shouldSyncTranscript
|
|
{
|
|
return NO;
|
|
}
|
|
|
|
// This method should not be overridden, since we want to add random padding to *every* sync message
|
|
- (OWSSignalServiceProtosSyncMessage *)buildSyncMessage
|
|
{
|
|
OWSSignalServiceProtosSyncMessageBuilder *builder = [self syncMessageBuilder];
|
|
|
|
// Add a random 1-512 bytes to obscure sync message type
|
|
size_t paddingBytesLength = arc4random_uniform(512) + 1;
|
|
builder.padding = [Cryptography generateRandomBytes:paddingBytesLength];
|
|
|
|
return [builder build];
|
|
}
|
|
|
|
- (OWSSignalServiceProtosSyncMessageBuilder *)syncMessageBuilder
|
|
{
|
|
OWSFail(@"Abstract method should be overridden in subclass.");
|
|
return [OWSSignalServiceProtosSyncMessageBuilder new];
|
|
}
|
|
|
|
- (NSData *)buildPlainTextData:(SignalRecipient *)recipient
|
|
{
|
|
OWSSignalServiceProtosContentBuilder *contentBuilder = [OWSSignalServiceProtosContentBuilder new];
|
|
[contentBuilder setSyncMessage:[self buildSyncMessage]];
|
|
return [[contentBuilder build] data];
|
|
}
|
|
|
|
@end
|
|
|
|
NS_ASSUME_NONNULL_END
|