2017-06-09 04:23:18 +02:00
|
|
|
//
|
2018-03-02 05:30:28 +01:00
|
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
2017-06-09 04:23:18 +02:00
|
|
|
//
|
2016-08-23 22:38:05 +02:00
|
|
|
|
|
|
|
#import "OWSOutgoingSyncMessage.h"
|
2017-06-22 19:05:28 +02:00
|
|
|
#import "Cryptography.h"
|
2018-03-02 05:30:28 +01:00
|
|
|
#import "NSDate+OWS.h"
|
2017-08-01 19:53:51 +02:00
|
|
|
#import "OWSSignalServiceProtos.pb.h"
|
2017-08-04 15:33:56 +02:00
|
|
|
#import "ProtoBuf+OWS.h"
|
2016-08-23 22:38:05 +02:00
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
@implementation OWSOutgoingSyncMessage
|
|
|
|
|
2018-03-02 05:30:28 +01:00
|
|
|
- (instancetype)init
|
|
|
|
{
|
2018-02-07 18:44:09 +01:00
|
|
|
self = [super initOutgoingMessageWithTimestamp:[NSDate ows_millisecondTimeStamp]
|
|
|
|
inThread:nil
|
|
|
|
messageBody:nil
|
|
|
|
attachmentIds:[NSMutableArray new]
|
|
|
|
expiresInSeconds:0
|
|
|
|
expireStartedAt:0
|
|
|
|
isVoiceMessage:NO
|
2018-04-19 17:25:11 +02:00
|
|
|
groupMetaMessage:TSGroupMessageUnspecified
|
2018-04-27 21:29:19 +02:00
|
|
|
quotedMessage:nil
|
2018-05-01 17:26:01 +02:00
|
|
|
contactShare:nil];
|
2018-02-07 18:44:09 +01:00
|
|
|
|
2018-03-02 05:30:28 +01:00
|
|
|
if (!self) {
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2017-11-15 23:53:16 +01:00
|
|
|
- (BOOL)shouldBeSaved
|
2016-09-01 21:42:51 +02:00
|
|
|
{
|
2017-11-15 23:53:16 +01:00
|
|
|
return NO;
|
2016-09-01 21:42:51 +02:00
|
|
|
}
|
|
|
|
|
2016-08-23 22:38:05 +02:00
|
|
|
- (BOOL)shouldSyncTranscript
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2017-06-22 19:05:28 +02:00
|
|
|
// This method should not be overridden, since we want to add random padding to *every* sync message
|
2016-08-26 01:01:35 +02:00
|
|
|
- (OWSSignalServiceProtosSyncMessage *)buildSyncMessage
|
|
|
|
{
|
2017-06-22 19:05:28 +02:00
|
|
|
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];
|
2017-08-04 15:33:56 +02:00
|
|
|
|
2017-06-22 19:05:28 +02:00
|
|
|
return [builder build];
|
|
|
|
}
|
2016-08-26 01:01:35 +02:00
|
|
|
|
2017-06-22 19:05:28 +02:00
|
|
|
- (OWSSignalServiceProtosSyncMessageBuilder *)syncMessageBuilder
|
|
|
|
{
|
|
|
|
OWSFail(@"Abstract method should be overridden in subclass.");
|
|
|
|
return [OWSSignalServiceProtosSyncMessageBuilder new];
|
2016-08-26 01:01:35 +02:00
|
|
|
}
|
|
|
|
|
2017-08-01 23:01:07 +02:00
|
|
|
- (NSData *)buildPlainTextData:(SignalRecipient *)recipient
|
2016-08-26 01:01:35 +02:00
|
|
|
{
|
|
|
|
OWSSignalServiceProtosContentBuilder *contentBuilder = [OWSSignalServiceProtosContentBuilder new];
|
2017-06-22 19:56:38 +02:00
|
|
|
[contentBuilder setSyncMessage:[self buildSyncMessage]];
|
2016-08-26 01:01:35 +02:00
|
|
|
return [[contentBuilder build] data];
|
|
|
|
}
|
|
|
|
|
2016-08-23 22:38:05 +02:00
|
|
|
@end
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|