Merge branch 'charlesmchen/removeObjcProtos'

pull/1/head
Matthew Chen 7 years ago
commit c94c33d612

@ -9,10 +9,9 @@ def shared_pods
pod 'SQLCipher', :git => 'https://github.com/sqlcipher/sqlcipher.git', :commit => 'd5c2bec' pod 'SQLCipher', :git => 'https://github.com/sqlcipher/sqlcipher.git', :commit => 'd5c2bec'
# pod 'YapDatabase/SQLCipher', path: '../YapDatabase' # pod 'YapDatabase/SQLCipher', path: '../YapDatabase'
pod 'YapDatabase/SQLCipher', :git => 'https://github.com/signalapp/YapDatabase.git', branch: 'signal-release' pod 'YapDatabase/SQLCipher', :git => 'https://github.com/signalapp/YapDatabase.git', branch: 'signal-release'
# pod 'AxolotlKit', path: '../SignalProtocolKit'
pod 'SignalServiceKit', path: '.'
pod 'AxolotlKit', git: 'https://github.com/signalapp/SignalProtocolKit.git' pod 'AxolotlKit', git: 'https://github.com/signalapp/SignalProtocolKit.git'
# pod 'AxolotlKit', path: '../SignalProtocolKit' # pod 'AxolotlKit', path: '../SignalProtocolKit'
pod 'SignalServiceKit', path: '.'
pod 'HKDFKit', git: 'https://github.com/signalapp/HKDFKit.git' pod 'HKDFKit', git: 'https://github.com/signalapp/HKDFKit.git'
# pod 'HKDFKit', path: '../HKDFKit' # pod 'HKDFKit', path: '../HKDFKit'
pod 'Curve25519Kit', git: 'https://github.com/signalapp/Curve25519Kit' pod 'Curve25519Kit', git: 'https://github.com/signalapp/Curve25519Kit'

@ -19,7 +19,7 @@ PODS:
- CocoaLumberjack - CocoaLumberjack
- Curve25519Kit (~> 2.1.0) - Curve25519Kit (~> 2.1.0)
- HKDFKit (~> 0.0.3) - HKDFKit (~> 0.0.3)
- ProtocolBuffers (~> 1.9.8) - SwiftProtobuf
- CocoaLumberjack (3.4.2): - CocoaLumberjack (3.4.2):
- CocoaLumberjack/Default (= 3.4.2) - CocoaLumberjack/Default (= 3.4.2)
- CocoaLumberjack/Extensions (= 3.4.2) - CocoaLumberjack/Extensions (= 3.4.2)
@ -44,7 +44,6 @@ PODS:
- PromiseKit/CorePromise - PromiseKit/CorePromise
- PromiseKit/UIKit (4.5.2): - PromiseKit/UIKit (4.5.2):
- PromiseKit/CorePromise - PromiseKit/CorePromise
- ProtocolBuffers (1.9.11)
- PureLayout (3.0.2) - PureLayout (3.0.2)
- Reachability (3.2) - Reachability (3.2)
- SAMKeychain (1.5.3) - SAMKeychain (1.5.3)
@ -161,7 +160,6 @@ SPEC REPOS:
- libPhoneNumber-iOS - libPhoneNumber-iOS
- Mantle - Mantle
- PromiseKit - PromiseKit
- ProtocolBuffers
- PureLayout - PureLayout
- Reachability - Reachability
- SAMKeychain - SAMKeychain
@ -192,7 +190,7 @@ EXTERNAL SOURCES:
CHECKOUT OPTIONS: CHECKOUT OPTIONS:
AxolotlKit: AxolotlKit:
:commit: 54d5f90558578bb96ebfa9688b3905093b489e31 :commit: 1fbdd114afe5ca981324892f22242d3a7a47794d
:git: https://github.com/signalapp/SignalProtocolKit.git :git: https://github.com/signalapp/SignalProtocolKit.git
Curve25519Kit: Curve25519Kit:
:commit: ced146699622ebd3d282bbfce3d492db4456e9aa :commit: ced146699622ebd3d282bbfce3d492db4456e9aa
@ -216,7 +214,7 @@ CHECKOUT OPTIONS:
SPEC CHECKSUMS: SPEC CHECKSUMS:
AFNetworking: b6f891fdfaed196b46c7a83cf209e09697b94057 AFNetworking: b6f891fdfaed196b46c7a83cf209e09697b94057
ATAppUpdater: a9f7027060959d47e58733d3b48f6b9a28cb8de1 ATAppUpdater: a9f7027060959d47e58733d3b48f6b9a28cb8de1
AxolotlKit: 7cfd2e71329b8dc398734e95b936450a2081fd60 AxolotlKit: 07bd978ea931d113939de88d3d2d354896680ceb
CocoaLumberjack: db7cc9e464771f12054c22ff6947c5a58d43a0fd CocoaLumberjack: db7cc9e464771f12054c22ff6947c5a58d43a0fd
Curve25519Kit: 76d0859ecb34704f7732847812363f83b23a6a59 Curve25519Kit: 76d0859ecb34704f7732847812363f83b23a6a59
GRKOpenSSLFramework: 8a3735ad41e7dc1daff460467bccd32ca5d6ae3e GRKOpenSSLFramework: 8a3735ad41e7dc1daff460467bccd32ca5d6ae3e
@ -224,7 +222,6 @@ SPEC CHECKSUMS:
libPhoneNumber-iOS: e444379ac18bbfbdefad571da735b2cd7e096caa libPhoneNumber-iOS: e444379ac18bbfbdefad571da735b2cd7e096caa
Mantle: 2fa750afa478cd625a94230fbf1c13462f29395b Mantle: 2fa750afa478cd625a94230fbf1c13462f29395b
PromiseKit: 743e497a5f505a470d3bbbf4ce0663c1268af0a4 PromiseKit: 743e497a5f505a470d3bbbf4ce0663c1268af0a4
ProtocolBuffers: d509225eb2ea43d9582a59e94348fcf86e2abd65
PureLayout: 4d550abe49a94f24c2808b9b95db9131685fe4cd PureLayout: 4d550abe49a94f24c2808b9b95db9131685fe4cd
Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96 Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96
SAMKeychain: 483e1c9f32984d50ca961e26818a534283b4cd5c SAMKeychain: 483e1c9f32984d50ca961e26818a534283b4cd5c
@ -236,6 +233,6 @@ SPEC CHECKSUMS:
YapDatabase: b418a4baa6906e8028748938f9159807fd039af4 YapDatabase: b418a4baa6906e8028748938f9159807fd039af4
YYImage: 1e1b62a9997399593e4b9c4ecfbbabbf1d3f3b54 YYImage: 1e1b62a9997399593e4b9c4ecfbbabbf1d3f3b54
PODFILE CHECKSUM: aa9ff0d7d6d50852127963f4b8aa60d8d1eff8d3 PODFILE CHECKSUM: 0c3d5978b54712391b5b90835b9554277b07fa23
COCOAPODS: 1.5.3 COCOAPODS: 1.5.3

@ -1 +1 @@
Subproject commit b9d00f47530c6c0c219b6c8cfe1802216f3093b9 Subproject commit 5da11dee08c2cc8864ea03b1489bd8898d28dd4e

@ -375,6 +375,11 @@ class MessageContext(BaseContext):
writer.push_context(self.proto_name, self.swift_name) writer.push_context(self.proto_name, self.swift_name)
if self.args.add_log_tag:
writer.add('fileprivate static let logTag = "%s"' % self.swift_name)
writer.add('fileprivate let logTag = "%s"' % self.swift_name)
writer.newline()
for child in self.enums: for child in self.enums:
child.generate(writer) child.generate(writer)
@ -606,6 +611,18 @@ public func serializedData() throws -> Data {
writer.pop_indent() writer.pop_indent()
writer.add('}') writer.add('}')
writer.newline() writer.newline()
# description
if self.args.add_description:
writer.add('@objc public override var description: String {')
writer.push_indent()
writer.add('var fields = [String]()')
for field in self.fields():
writer.add('fields.append("%s: \(proto.%s)")' % ( field.name_swift, field.name_swift, ) )
writer.add('return "[" + fields.joined(separator: ", ") + "]"')
writer.pop_indent()
writer.add('}')
writer.newline()
writer.pop_context() writer.pop_context()
@ -710,13 +727,25 @@ public func serializedData() throws -> Data {
writer.add('}') writer.add('}')
writer.newline() writer.newline()
# build() func # buildSerializedData() func
writer.add('@objc public func buildSerializedData() throws -> Data {') writer.add('@objc public func buildSerializedData() throws -> Data {')
writer.push_indent() writer.push_indent()
writer.add('return try %s.parseProto(proto).serializedData()' % self.swift_name) writer.add('return try %s.parseProto(proto).serializedData()' % self.swift_name)
writer.pop_indent() writer.pop_indent()
writer.add('}') writer.add('}')
writer.newline() writer.newline()
# description
if self.args.add_description:
writer.add('@objc public override var description: String {')
writer.push_indent()
writer.add('var fields = [String]()')
for field in self.fields():
writer.add('fields.append("%s: \(proto.%s)")' % ( field.name_swift, field.name_swift, ) )
writer.add('return "[" + fields.joined(separator: ", ") + "]"')
writer.pop_indent()
writer.add('}')
writer.newline()
writer.pop_context() writer.pop_context()
@ -1096,6 +1125,8 @@ if __name__ == "__main__":
parser.add_argument('--wrapper-prefix', help='name prefix for generated wrappers.') parser.add_argument('--wrapper-prefix', help='name prefix for generated wrappers.')
parser.add_argument('--proto-prefix', help='name prefix for proto bufs.') parser.add_argument('--proto-prefix', help='name prefix for proto bufs.')
parser.add_argument('--dst-dir', help='path to the destination directory.') parser.add_argument('--dst-dir', help='path to the destination directory.')
parser.add_argument('--add-log-tag', action='store_true', help='add log tag properties.')
parser.add_argument('--add-description', action='store_true', help='add log tag properties.')
parser.add_argument('--verbose', action='store_true', help='enables verbose logging') parser.add_argument('--verbose', action='store_true', help='enables verbose logging')
args = parser.parse_args() args = parser.parse_args()

@ -3015,7 +3015,6 @@
"${BUILT_PRODUCTS_DIR}/HKDFKit/HKDFKit.framework", "${BUILT_PRODUCTS_DIR}/HKDFKit/HKDFKit.framework",
"${BUILT_PRODUCTS_DIR}/Mantle/Mantle.framework", "${BUILT_PRODUCTS_DIR}/Mantle/Mantle.framework",
"${BUILT_PRODUCTS_DIR}/PromiseKit/PromiseKit.framework", "${BUILT_PRODUCTS_DIR}/PromiseKit/PromiseKit.framework",
"${BUILT_PRODUCTS_DIR}/ProtocolBuffers/ProtocolBuffers.framework",
"${BUILT_PRODUCTS_DIR}/PureLayout/PureLayout.framework", "${BUILT_PRODUCTS_DIR}/PureLayout/PureLayout.framework",
"${BUILT_PRODUCTS_DIR}/Reachability/Reachability.framework", "${BUILT_PRODUCTS_DIR}/Reachability/Reachability.framework",
"${BUILT_PRODUCTS_DIR}/SAMKeychain/SAMKeychain.framework", "${BUILT_PRODUCTS_DIR}/SAMKeychain/SAMKeychain.framework",
@ -3039,7 +3038,6 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/HKDFKit.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/HKDFKit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mantle.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mantle.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PromiseKit.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PromiseKit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ProtocolBuffers.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PureLayout.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PureLayout.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Reachability.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Reachability.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SAMKeychain.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SAMKeychain.framework",
@ -3090,7 +3088,6 @@
"${BUILT_PRODUCTS_DIR}/HKDFKit/HKDFKit.framework", "${BUILT_PRODUCTS_DIR}/HKDFKit/HKDFKit.framework",
"${BUILT_PRODUCTS_DIR}/Mantle/Mantle.framework", "${BUILT_PRODUCTS_DIR}/Mantle/Mantle.framework",
"${BUILT_PRODUCTS_DIR}/PromiseKit/PromiseKit.framework", "${BUILT_PRODUCTS_DIR}/PromiseKit/PromiseKit.framework",
"${BUILT_PRODUCTS_DIR}/ProtocolBuffers/ProtocolBuffers.framework",
"${BUILT_PRODUCTS_DIR}/PureLayout/PureLayout.framework", "${BUILT_PRODUCTS_DIR}/PureLayout/PureLayout.framework",
"${BUILT_PRODUCTS_DIR}/Reachability/Reachability.framework", "${BUILT_PRODUCTS_DIR}/Reachability/Reachability.framework",
"${BUILT_PRODUCTS_DIR}/SAMKeychain/SAMKeychain.framework", "${BUILT_PRODUCTS_DIR}/SAMKeychain/SAMKeychain.framework",
@ -3112,7 +3109,6 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/HKDFKit.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/HKDFKit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mantle.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mantle.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PromiseKit.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PromiseKit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ProtocolBuffers.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PureLayout.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PureLayout.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Reachability.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Reachability.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SAMKeychain.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SAMKeychain.framework",

@ -1,11 +1,6 @@
# See https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#runtime-suppressions # See https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#runtime-suppressions
# for details. # for details.
# protobuf lib
shift-base:CodedInputStream.m
# generated protos
bool:WhisperTextProtocol.pb.m
# YapDatabase # YapDatabase
bool:YapDatabaseAutoViewTransaction.m bool:YapDatabaseAutoViewTransaction.m

@ -64,9 +64,12 @@ class ConversationConfigurationSyncOperation: OWSOperation {
identityManager: self.identityManager, identityManager: self.identityManager,
profileManager: self.profileManager) profileManager: self.profileManager)
var dataSource: DataSource? = nil var dataSource: DataSource?
self.dbConnection.readWrite { transaction in self.dbConnection.readWrite { transaction in
let messageData: Data = syncMessage.buildPlainTextAttachmentData(with: transaction) guard let messageData: Data = syncMessage.buildPlainTextAttachmentData(with: transaction) else {
owsFail("\(self.logTag) could not serialize sync contacts data")
return
}
dataSource = DataSourceValue.dataSource(withSyncMessageData: messageData) dataSource = DataSourceValue.dataSource(withSyncMessageData: messageData)
} }
@ -85,9 +88,12 @@ class ConversationConfigurationSyncOperation: OWSOperation {
// What does Android do? // What does Android do?
let syncMessage: OWSSyncGroupsMessage = OWSSyncGroupsMessage() let syncMessage: OWSSyncGroupsMessage = OWSSyncGroupsMessage()
var dataSource: DataSource? = nil var dataSource: DataSource?
self.dbConnection.read { transaction in self.dbConnection.read { transaction in
let messageData: Data = syncMessage.buildPlainTextAttachmentData(with: transaction) guard let messageData: Data = syncMessage.buildPlainTextAttachmentData(with: transaction) else {
owsFail("\(self.logTag) could not serialize sync groups data")
return
}
dataSource = DataSourceValue.dataSource(withSyncMessageData: messageData) dataSource = DataSourceValue.dataSource(withSyncMessageData: messageData)
} }

@ -48,9 +48,13 @@ import SignalMessaging
identityManager: self.identityManager, identityManager: self.identityManager,
profileManager: self.profileManager) profileManager: self.profileManager)
var dataSource: DataSource? = nil var dataSource: DataSource?
self.editingDatabaseConnection.readWrite { transaction in self.editingDatabaseConnection.readWrite { transaction in
dataSource = DataSourceValue.dataSource(withSyncMessageData: syncContactsMessage.buildPlainTextAttachmentData(with: transaction)) guard let messageData: Data = syncContactsMessage.buildPlainTextAttachmentData(with: transaction) else {
owsFail("\(self.logTag) could not serialize sync contacts data")
return
}
dataSource = DataSourceValue.dataSource(withSyncMessageData: messageData)
} }
guard let attachmentDataSource = dataSource else { guard let attachmentDataSource = dataSource else {

@ -2,9 +2,95 @@
// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// //
#import <Curve25519Kit/Randomness.h>
#import <SignalServiceKit/ContactsManagerProtocol.h>
#import <SignalServiceKit/NSData+OWS.h>
#import <SignalServiceKit/OWSContactsOutputStream.h>
#import <SignalServiceKit/OWSGroupsOutputStream.h>
#import <SignalServiceKit/SignalAccount.h>
#import <SignalServiceKit/SignalServiceKit-Swift.h> #import <SignalServiceKit/SignalServiceKit-Swift.h>
#import <XCTest/XCTest.h> #import <XCTest/XCTest.h>
NS_ASSUME_NONNULL_BEGIN
@class CNContact;
@interface TestContactsManager : NSObject <ContactsManagerProtocol>
@end
#pragma mark -
@implementation TestContactsManager
- (NSString *)displayNameForPhoneIdentifier:(NSString *_Nullable)phoneNumber
{
return phoneNumber;
}
- (NSArray<SignalAccount *> *)signalAccounts
{
return @[];
}
- (BOOL)isSystemContact:(NSString *)recipientId
{
return YES;
}
- (BOOL)isSystemContactWithSignalAccount:(NSString *)recipientId
{
return YES;
}
- (NSComparisonResult)compareSignalAccount:(SignalAccount *)left withSignalAccount:(SignalAccount *)right
{
return NSOrderedSame;
}
- (nullable CNContact *)cnContactWithId:(nullable NSString *)contactId
{
return nil;
}
- (nullable NSData *)avatarDataForCNContactId:(nullable NSString *)contactId
{
return nil;
}
- (nullable UIImage *)avatarImageForCNContactId:(nullable NSString *)contactId
{
return nil;
}
@end
#pragma mark -
@interface FakeContact : NSObject
@property (nullable, nonatomic) NSString *firstName;
@property (nullable, nonatomic) NSString *lastName;
@property (nonatomic) NSString *fullName;
@property (nonatomic) NSString *comparableNameFirstLast;
@property (nonatomic) NSString *comparableNameLastFirst;
@property (nonatomic) NSArray<PhoneNumber *> *parsedPhoneNumbers;
@property (nonatomic) NSArray<NSString *> *userTextPhoneNumbers;
@property (nonatomic) NSArray<NSString *> *emails;
@property (nonatomic) NSString *uniqueId;
@property (nonatomic) BOOL isSignalContact;
@property (nonatomic) NSString *cnContactId;
@end
#pragma mark -
@implementation FakeContact
@end
#pragma mark -
@interface ProtoParsingTest : XCTestCase @interface ProtoParsingTest : XCTestCase
@end @end
@ -31,4 +117,58 @@
XCTAssertNotNil(error); XCTAssertNotNil(error);
} }
- (void)testProtoStreams
{
NSArray<SignalAccount *> *signalAccounts = @[
[[SignalAccount alloc] initWithRecipientId:@"+13213214321"],
[[SignalAccount alloc] initWithRecipientId:@"+13213214322"],
[[SignalAccount alloc] initWithRecipientId:@"+13213214323"],
];
NSData *_Nullable streamData = [self dataForSyncingContacts:signalAccounts];
XCTAssertNotNil(streamData);
XCTAssertEqualObjects(streamData.hexadecimalString,
@"1b0a0c2b31333231333231343332311209416c69636520426f6240001b0a0c2b31333231333231343332321209416c69636520426f624"
@"0001b0a0c2b31333231333231343332331209416c69636520426f624000");
}
- (nullable NSData *)dataForSyncingContacts:(NSArray<SignalAccount *> *)signalAccounts
{
TestContactsManager *contactsManager = [TestContactsManager new];
NSOutputStream *dataOutputStream = [NSOutputStream outputStreamToMemory];
[dataOutputStream open];
OWSContactsOutputStream *contactsOutputStream =
[[OWSContactsOutputStream alloc] initWithOutputStream:dataOutputStream];
for (SignalAccount *signalAccount in signalAccounts) {
OWSRecipientIdentity *_Nullable recipientIdentity = nil;
// NSData *_Nullable profileKeyData = [Randomness generateRandomBytes:32];
NSData *_Nullable profileKeyData = nil;
OWSDisappearingMessagesConfiguration *_Nullable disappearingMessagesConfiguration = nil;
NSString *_Nullable conversationColorName = @"fake color name";
FakeContact *fakeContact = [FakeContact new];
fakeContact.cnContactId = @"123";
fakeContact.fullName = @"Alice Bob";
signalAccount.contact = (Contact *)fakeContact;
[contactsOutputStream writeSignalAccount:signalAccount
recipientIdentity:recipientIdentity
profileKeyData:profileKeyData
contactsManager:contactsManager
conversationColorName:conversationColorName
disappearingMessagesConfiguration:disappearingMessagesConfiguration];
}
[dataOutputStream close];
if (contactsOutputStream.hasError) {
return nil;
}
return [dataOutputStream propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
}
@end @end
NS_ASSUME_NONNULL_END

@ -124,14 +124,19 @@ NSString *const kOWSPrimaryStorageOWSContactsSyncingLastMessageKey
identityManager:self.identityManager identityManager:self.identityManager
profileManager:self.profileManager]; profileManager:self.profileManager];
__block NSData *messageData; __block NSData *_Nullable messageData;
__block NSData *lastMessageData; __block NSData *_Nullable lastMessageData;
[self.editingDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { [self.editingDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
messageData = [syncContactsMessage buildPlainTextAttachmentDataWithTransaction:transaction]; messageData = [syncContactsMessage buildPlainTextAttachmentDataWithTransaction:transaction];
lastMessageData = [transaction objectForKey:kOWSPrimaryStorageOWSContactsSyncingLastMessageKey lastMessageData = [transaction objectForKey:kOWSPrimaryStorageOWSContactsSyncingLastMessageKey
inCollection:kOWSPrimaryStorageOWSContactsSyncingCollection]; inCollection:kOWSPrimaryStorageOWSContactsSyncingCollection];
}]; }];
if (!messageData) {
OWSFail(@"%@ Failed to serialize contacts sync message.", self.logTag);
return;
}
if (lastMessageData && [lastMessageData isEqual:messageData]) { if (lastMessageData && [lastMessageData isEqual:messageData]) {
// Ignore redundant contacts sync message. // Ignore redundant contacts sync message.
return; return;

@ -1,15 +1,21 @@
// Copyright © 2016 Open Whisper Systems. All rights reserved. //
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@class PBCodedOutputStream;
@interface OWSChunkedOutputStream : NSObject @interface OWSChunkedOutputStream : NSObject
@property (nonatomic, readonly) PBCodedOutputStream *delegateStream; // Indicates whether any write failed.
@property (nonatomic, readonly) BOOL hasError;
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithOutputStream:(NSOutputStream *)outputStream;
+ (instancetype)streamWithOutputStream:(NSOutputStream *)output; // Returns NO on error.
- (void)flush; - (BOOL)writeData:(NSData *)data;
- (BOOL)writeVariableLengthUInt32:(UInt32)value;
@end @end

@ -1,35 +1,82 @@
// Copyright © 2016 Open Whisper Systems. All rights reserved. //
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSChunkedOutputStream.h" #import "OWSChunkedOutputStream.h"
#import <ProtocolBuffers/CodedOutputStream.h> #import "NSData+OWS.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface OWSChunkedOutputStream ()
@property (nonatomic, readonly) NSOutputStream *outputStream;
@property (nonatomic) BOOL hasError;
@end
#pragma mark -
@implementation OWSChunkedOutputStream @implementation OWSChunkedOutputStream
+ (instancetype)streamWithOutputStream:(NSOutputStream *)output - (instancetype)initWithOutputStream:(NSOutputStream *)outputStream
{ {
return [[self alloc] initWithOutputStream:output]; if (self = [super init]) {
OWSAssert(outputStream);
_outputStream = outputStream;
}
return self;
} }
- (instancetype)initWithOutputStream:(NSOutputStream *)outputStream - (BOOL)writeByte:(uint8_t)value
{ {
self = [super init]; NSInteger written = [self.outputStream write:&value maxLength:sizeof(value)];
if (!self) { if (written != sizeof(value)) {
return self; OWSFail(@"%@ could not write to output stream.", self.logTag);
self.hasError = YES;
return NO;
} }
return YES;
}
_delegateStream = [PBCodedOutputStream streamWithOutputStream:outputStream]; - (BOOL)writeData:(NSData *)data
{
OWSAssert(data);
return self; if (data.length < 1) {
return YES;
}
while (YES) {
NSInteger written = [self.outputStream write:data.bytes maxLength:data.length];
if (written < 1) {
OWSFail(@"%@ could not write to output stream.", self.logTag);
self.hasError = YES;
return NO;
}
if (written < data.length) {
data = [data subdataWithRange:NSMakeRange(written, data.length - written)];
} else {
return YES;
}
}
return YES;
} }
- (void)flush - (BOOL)writeVariableLengthUInt32:(UInt32)value
{ {
[self.delegateStream flush]; while (YES) {
if (value <= 0x7F) {
return [self writeByte:value];
} else {
if (![self writeByte:((value & 0x7F) | 0x80)]) {
return NO;
}
value >>= 7;
}
}
} }
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -7,13 +7,13 @@
#import "ContactsManagerProtocol.h" #import "ContactsManagerProtocol.h"
#import "Cryptography.h" #import "Cryptography.h"
#import "MIMETypeUtil.h" #import "MIMETypeUtil.h"
#import "NSData+OWS.h"
#import "NSData+keyVersionByte.h" #import "NSData+keyVersionByte.h"
#import "OWSBlockingManager.h" #import "OWSBlockingManager.h"
#import "OWSDisappearingMessagesConfiguration.h" #import "OWSDisappearingMessagesConfiguration.h"
#import "OWSRecipientIdentity.h" #import "OWSRecipientIdentity.h"
#import "SignalAccount.h" #import "SignalAccount.h"
#import "TSContactThread.h" #import "TSContactThread.h"
#import <ProtocolBuffers/CodedOutputStream.h>
#import <SignalServiceKit/SignalServiceKit-Swift.h> #import <SignalServiceKit/SignalServiceKit-Swift.h>
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@ -96,11 +96,11 @@ disappearingMessagesConfiguration:(nullable OWSDisappearingMessagesConfiguration
} }
uint32_t contactDataLength = (uint32_t)contactData.length; uint32_t contactDataLength = (uint32_t)contactData.length;
[self.delegateStream writeRawVarint32:contactDataLength]; [self writeVariableLengthUInt32:contactDataLength];
[self.delegateStream writeRawData:contactData]; [self writeData:contactData];
if (avatarPng) { if (avatarPng) {
[self.delegateStream writeRawData:avatarPng]; [self writeData:avatarPng];
} }
} }

@ -7,7 +7,6 @@
#import "OWSDisappearingMessagesConfiguration.h" #import "OWSDisappearingMessagesConfiguration.h"
#import "TSGroupModel.h" #import "TSGroupModel.h"
#import "TSGroupThread.h" #import "TSGroupThread.h"
#import <ProtocolBuffers/CodedOutputStream.h>
#import <SignalServiceKit/SignalServiceKit-Swift.h> #import <SignalServiceKit/SignalServiceKit-Swift.h>
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@ -69,11 +68,11 @@ NS_ASSUME_NONNULL_BEGIN
uint32_t groupDataLength = (uint32_t)groupData.length; uint32_t groupDataLength = (uint32_t)groupData.length;
[self.delegateStream writeRawVarint32:groupDataLength]; [self writeVariableLengthUInt32:groupDataLength];
[self.delegateStream writeRawData:groupData]; [self writeData:groupData];
if (avatarPng) { if (avatarPng) {
[self.delegateStream writeRawData:avatarPng]; [self writeData:avatarPng];
} }
} }

@ -21,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER; - (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
- (NSData *)buildPlainTextAttachmentDataWithTransaction:(YapDatabaseReadTransaction *)transaction; - (nullable NSData *)buildPlainTextAttachmentDataWithTransaction:(YapDatabaseReadTransaction *)transaction;
@end @end

@ -79,7 +79,7 @@ NS_ASSUME_NONNULL_BEGIN
return syncMessageBuilder; return syncMessageBuilder;
} }
- (NSData *)buildPlainTextAttachmentDataWithTransaction:(YapDatabaseReadTransaction *)transaction - (nullable NSData *)buildPlainTextAttachmentDataWithTransaction:(YapDatabaseReadTransaction *)transaction
{ {
id<ContactsManagerProtocol> contactsManager = TextSecureKitEnv.sharedEnv.contactsManager; id<ContactsManagerProtocol> contactsManager = TextSecureKitEnv.sharedEnv.contactsManager;
@ -88,7 +88,8 @@ NS_ASSUME_NONNULL_BEGIN
// and uploading with streams). // and uploading with streams).
NSOutputStream *dataOutputStream = [NSOutputStream outputStreamToMemory]; NSOutputStream *dataOutputStream = [NSOutputStream outputStreamToMemory];
[dataOutputStream open]; [dataOutputStream open];
OWSContactsOutputStream *contactsOutputStream = [OWSContactsOutputStream streamWithOutputStream:dataOutputStream]; OWSContactsOutputStream *contactsOutputStream =
[[OWSContactsOutputStream alloc] initWithOutputStream:dataOutputStream];
for (SignalAccount *signalAccount in self.signalAccounts) { for (SignalAccount *signalAccount in self.signalAccounts) {
OWSRecipientIdentity *_Nullable recipientIdentity = OWSRecipientIdentity *_Nullable recipientIdentity =
@ -115,9 +116,13 @@ NS_ASSUME_NONNULL_BEGIN
disappearingMessagesConfiguration:disappearingMessagesConfiguration]; disappearingMessagesConfiguration:disappearingMessagesConfiguration];
} }
[contactsOutputStream flush];
[dataOutputStream close]; [dataOutputStream close];
if (contactsOutputStream.hasError) {
OWSFail(@"%@ Could not write contacts sync stream.", self.logTag);
return nil;
}
return [dataOutputStream propertyForKey:NSStreamDataWrittenToMemoryStreamKey]; return [dataOutputStream propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
} }

@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)init NS_DESIGNATED_INITIALIZER; - (instancetype)init NS_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER; - (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
- (NSData *)buildPlainTextAttachmentDataWithTransaction:(YapDatabaseReadTransaction *)transaction; - (nullable NSData *)buildPlainTextAttachmentDataWithTransaction:(YapDatabaseReadTransaction *)transaction;
@end @end

@ -57,14 +57,14 @@ NS_ASSUME_NONNULL_BEGIN
return syncMessageBuilder; return syncMessageBuilder;
} }
- (NSData *)buildPlainTextAttachmentDataWithTransaction:(YapDatabaseReadTransaction *)transaction - (nullable NSData *)buildPlainTextAttachmentDataWithTransaction:(YapDatabaseReadTransaction *)transaction
{ {
// TODO use temp file stream to avoid loading everything into memory at once // TODO use temp file stream to avoid loading everything into memory at once
// First though, we need to re-engineer our attachment process to accept streams (encrypting with stream, // First though, we need to re-engineer our attachment process to accept streams (encrypting with stream,
// and uploading with streams). // and uploading with streams).
NSOutputStream *dataOutputStream = [NSOutputStream outputStreamToMemory]; NSOutputStream *dataOutputStream = [NSOutputStream outputStreamToMemory];
[dataOutputStream open]; [dataOutputStream open];
OWSGroupsOutputStream *groupsOutputStream = [OWSGroupsOutputStream streamWithOutputStream:dataOutputStream]; OWSGroupsOutputStream *groupsOutputStream = [[OWSGroupsOutputStream alloc] initWithOutputStream:dataOutputStream];
[TSGroupThread [TSGroupThread
enumerateCollectionObjectsWithTransaction:transaction enumerateCollectionObjectsWithTransaction:transaction
@ -80,9 +80,13 @@ NS_ASSUME_NONNULL_BEGIN
[groupsOutputStream writeGroup:groupThread transaction:transaction]; [groupsOutputStream writeGroup:groupThread transaction:transaction];
}]; }];
[groupsOutputStream flush];
[dataOutputStream close]; [dataOutputStream close];
if (groupsOutputStream.hasError) {
OWSFail(@"%@ Could not write groups sync stream.", self.logTag);
return nil;
}
return [dataOutputStream propertyForKey:NSStreamDataWrittenToMemoryStreamKey]; return [dataOutputStream propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
} }

@ -661,9 +661,15 @@ NS_ASSUME_NONNULL_BEGIN
[[OWSSyncContactsMessage alloc] initWithSignalAccounts:self.contactsManager.signalAccounts [[OWSSyncContactsMessage alloc] initWithSignalAccounts:self.contactsManager.signalAccounts
identityManager:self.identityManager identityManager:self.identityManager
profileManager:self.profileManager]; profileManager:self.profileManager];
DataSource *dataSource = [DataSourceValue __block NSData *_Nullable syncData;
dataSourceWithSyncMessageData:[syncContactsMessage [self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
buildPlainTextAttachmentDataWithTransaction:transaction]]; syncData = [syncContactsMessage buildPlainTextAttachmentDataWithTransaction:transaction];
}];
if (!syncData) {
OWSFail(@"%@ Failed to serialize contacts sync message.", self.logTag);
return;
}
DataSource *dataSource = [DataSourceValue dataSourceWithSyncMessageData:syncData];
[self.messageSender enqueueTemporaryAttachment:dataSource [self.messageSender enqueueTemporaryAttachment:dataSource
contentType:OWSMimeTypeApplicationOctetStream contentType:OWSMimeTypeApplicationOctetStream
inMessage:syncContactsMessage inMessage:syncContactsMessage
@ -677,9 +683,12 @@ NS_ASSUME_NONNULL_BEGIN
}); });
} else if (syncMessage.request.type == SSKProtoSyncMessageRequestTypeGroups) { } else if (syncMessage.request.type == SSKProtoSyncMessageRequestTypeGroups) {
OWSSyncGroupsMessage *syncGroupsMessage = [[OWSSyncGroupsMessage alloc] init]; OWSSyncGroupsMessage *syncGroupsMessage = [[OWSSyncGroupsMessage alloc] init];
DataSource *dataSource = [DataSourceValue NSData *_Nullable syncData = [syncGroupsMessage buildPlainTextAttachmentDataWithTransaction:transaction];
dataSourceWithSyncMessageData:[syncGroupsMessage if (!syncData) {
buildPlainTextAttachmentDataWithTransaction:transaction]]; OWSFail(@"%@ Failed to serialize groups sync message.", self.logTag);
return;
}
DataSource *dataSource = [DataSourceValue dataSourceWithSyncMessageData:syncData];
[self.messageSender enqueueTemporaryAttachment:dataSource [self.messageSender enqueueTemporaryAttachment:dataSource
contentType:OWSMimeTypeApplicationOctetStream contentType:OWSMimeTypeApplicationOctetStream
inMessage:syncGroupsMessage inMessage:syncGroupsMessage

@ -315,27 +315,27 @@ public enum SSKProtoError: Error {
} }
fileprivate class func parseProto(_ proto: SignalServiceProtos_Content) throws -> SSKProtoContent { fileprivate class func parseProto(_ proto: SignalServiceProtos_Content) throws -> SSKProtoContent {
var dataMessage: SSKProtoDataMessage? = nil var dataMessage: SSKProtoDataMessage?
if proto.hasDataMessage { if proto.hasDataMessage {
dataMessage = try SSKProtoDataMessage.parseProto(proto.dataMessage) dataMessage = try SSKProtoDataMessage.parseProto(proto.dataMessage)
} }
var syncMessage: SSKProtoSyncMessage? = nil var syncMessage: SSKProtoSyncMessage?
if proto.hasSyncMessage { if proto.hasSyncMessage {
syncMessage = try SSKProtoSyncMessage.parseProto(proto.syncMessage) syncMessage = try SSKProtoSyncMessage.parseProto(proto.syncMessage)
} }
var callMessage: SSKProtoCallMessage? = nil var callMessage: SSKProtoCallMessage?
if proto.hasCallMessage { if proto.hasCallMessage {
callMessage = try SSKProtoCallMessage.parseProto(proto.callMessage) callMessage = try SSKProtoCallMessage.parseProto(proto.callMessage)
} }
var nullMessage: SSKProtoNullMessage? = nil var nullMessage: SSKProtoNullMessage?
if proto.hasNullMessage { if proto.hasNullMessage {
nullMessage = try SSKProtoNullMessage.parseProto(proto.nullMessage) nullMessage = try SSKProtoNullMessage.parseProto(proto.nullMessage)
} }
var receiptMessage: SSKProtoReceiptMessage? = nil var receiptMessage: SSKProtoReceiptMessage?
if proto.hasReceiptMessage { if proto.hasReceiptMessage {
receiptMessage = try SSKProtoReceiptMessage.parseProto(proto.receiptMessage) receiptMessage = try SSKProtoReceiptMessage.parseProto(proto.receiptMessage)
} }
@ -947,12 +947,12 @@ public enum SSKProtoError: Error {
} }
fileprivate class func parseProto(_ proto: SignalServiceProtos_CallMessage) throws -> SSKProtoCallMessage { fileprivate class func parseProto(_ proto: SignalServiceProtos_CallMessage) throws -> SSKProtoCallMessage {
var offer: SSKProtoCallMessageOffer? = nil var offer: SSKProtoCallMessageOffer?
if proto.hasOffer { if proto.hasOffer {
offer = try SSKProtoCallMessageOffer.parseProto(proto.offer) offer = try SSKProtoCallMessageOffer.parseProto(proto.offer)
} }
var answer: SSKProtoCallMessageAnswer? = nil var answer: SSKProtoCallMessageAnswer?
if proto.hasAnswer { if proto.hasAnswer {
answer = try SSKProtoCallMessageAnswer.parseProto(proto.answer) answer = try SSKProtoCallMessageAnswer.parseProto(proto.answer)
} }
@ -960,12 +960,12 @@ public enum SSKProtoError: Error {
var iceUpdate: [SSKProtoCallMessageIceUpdate] = [] var iceUpdate: [SSKProtoCallMessageIceUpdate] = []
iceUpdate = try proto.iceUpdate.map { try SSKProtoCallMessageIceUpdate.parseProto($0) } iceUpdate = try proto.iceUpdate.map { try SSKProtoCallMessageIceUpdate.parseProto($0) }
var hangup: SSKProtoCallMessageHangup? = nil var hangup: SSKProtoCallMessageHangup?
if proto.hasHangup { if proto.hasHangup {
hangup = try SSKProtoCallMessageHangup.parseProto(proto.hangup) hangup = try SSKProtoCallMessageHangup.parseProto(proto.hangup)
} }
var busy: SSKProtoCallMessageBusy? = nil var busy: SSKProtoCallMessageBusy?
if proto.hasBusy { if proto.hasBusy {
busy = try SSKProtoCallMessageBusy.parseProto(proto.busy) busy = try SSKProtoCallMessageBusy.parseProto(proto.busy)
} }
@ -1108,7 +1108,7 @@ public enum SSKProtoError: Error {
} }
fileprivate class func parseProto(_ proto: SignalServiceProtos_DataMessage.Quote.QuotedAttachment) throws -> SSKProtoDataMessageQuoteQuotedAttachment { fileprivate class func parseProto(_ proto: SignalServiceProtos_DataMessage.Quote.QuotedAttachment) throws -> SSKProtoDataMessageQuoteQuotedAttachment {
var thumbnail: SSKProtoAttachmentPointer? = nil var thumbnail: SSKProtoAttachmentPointer?
if proto.hasThumbnail { if proto.hasThumbnail {
thumbnail = try SSKProtoAttachmentPointer.parseProto(proto.thumbnail) thumbnail = try SSKProtoAttachmentPointer.parseProto(proto.thumbnail)
} }
@ -1949,7 +1949,7 @@ public enum SSKProtoError: Error {
} }
fileprivate class func parseProto(_ proto: SignalServiceProtos_DataMessage.Contact.Avatar) throws -> SSKProtoDataMessageContactAvatar { fileprivate class func parseProto(_ proto: SignalServiceProtos_DataMessage.Contact.Avatar) throws -> SSKProtoDataMessageContactAvatar {
var avatar: SSKProtoAttachmentPointer? = nil var avatar: SSKProtoAttachmentPointer?
if proto.hasAvatar { if proto.hasAvatar {
avatar = try SSKProtoAttachmentPointer.parseProto(proto.avatar) avatar = try SSKProtoAttachmentPointer.parseProto(proto.avatar)
} }
@ -2098,7 +2098,7 @@ public enum SSKProtoError: Error {
} }
fileprivate class func parseProto(_ proto: SignalServiceProtos_DataMessage.Contact) throws -> SSKProtoDataMessageContact { fileprivate class func parseProto(_ proto: SignalServiceProtos_DataMessage.Contact) throws -> SSKProtoDataMessageContact {
var name: SSKProtoDataMessageContactName? = nil var name: SSKProtoDataMessageContactName?
if proto.hasName { if proto.hasName {
name = try SSKProtoDataMessageContactName.parseProto(proto.name) name = try SSKProtoDataMessageContactName.parseProto(proto.name)
} }
@ -2112,7 +2112,7 @@ public enum SSKProtoError: Error {
var address: [SSKProtoDataMessageContactPostalAddress] = [] var address: [SSKProtoDataMessageContactPostalAddress] = []
address = try proto.address.map { try SSKProtoDataMessageContactPostalAddress.parseProto($0) } address = try proto.address.map { try SSKProtoDataMessageContactPostalAddress.parseProto($0) }
var avatar: SSKProtoDataMessageContactAvatar? = nil var avatar: SSKProtoDataMessageContactAvatar?
if proto.hasAvatar { if proto.hasAvatar {
avatar = try SSKProtoDataMessageContactAvatar.parseProto(proto.avatar) avatar = try SSKProtoDataMessageContactAvatar.parseProto(proto.avatar)
} }
@ -2325,12 +2325,12 @@ public enum SSKProtoError: Error {
var attachments: [SSKProtoAttachmentPointer] = [] var attachments: [SSKProtoAttachmentPointer] = []
attachments = try proto.attachments.map { try SSKProtoAttachmentPointer.parseProto($0) } attachments = try proto.attachments.map { try SSKProtoAttachmentPointer.parseProto($0) }
var group: SSKProtoGroupContext? = nil var group: SSKProtoGroupContext?
if proto.hasGroup { if proto.hasGroup {
group = try SSKProtoGroupContext.parseProto(proto.group) group = try SSKProtoGroupContext.parseProto(proto.group)
} }
var quote: SSKProtoDataMessageQuote? = nil var quote: SSKProtoDataMessageQuote?
if proto.hasQuote { if proto.hasQuote {
quote = try SSKProtoDataMessageQuote.parseProto(proto.quote) quote = try SSKProtoDataMessageQuote.parseProto(proto.quote)
} }
@ -2789,7 +2789,7 @@ public enum SSKProtoError: Error {
} }
fileprivate class func parseProto(_ proto: SignalServiceProtos_SyncMessage.Sent) throws -> SSKProtoSyncMessageSent { fileprivate class func parseProto(_ proto: SignalServiceProtos_SyncMessage.Sent) throws -> SSKProtoSyncMessageSent {
var message: SSKProtoDataMessage? = nil var message: SSKProtoDataMessage?
if proto.hasMessage { if proto.hasMessage {
message = try SSKProtoDataMessage.parseProto(proto.message) message = try SSKProtoDataMessage.parseProto(proto.message)
} }
@ -2961,7 +2961,7 @@ public enum SSKProtoError: Error {
} }
fileprivate class func parseProto(_ proto: SignalServiceProtos_SyncMessage.Groups) throws -> SSKProtoSyncMessageGroups { fileprivate class func parseProto(_ proto: SignalServiceProtos_SyncMessage.Groups) throws -> SSKProtoSyncMessageGroups {
var blob: SSKProtoAttachmentPointer? = nil var blob: SSKProtoAttachmentPointer?
if proto.hasBlob { if proto.hasBlob {
blob = try SSKProtoAttachmentPointer.parseProto(proto.blob) blob = try SSKProtoAttachmentPointer.parseProto(proto.blob)
} }
@ -3494,22 +3494,22 @@ public enum SSKProtoError: Error {
} }
fileprivate class func parseProto(_ proto: SignalServiceProtos_SyncMessage) throws -> SSKProtoSyncMessage { fileprivate class func parseProto(_ proto: SignalServiceProtos_SyncMessage) throws -> SSKProtoSyncMessage {
var sent: SSKProtoSyncMessageSent? = nil var sent: SSKProtoSyncMessageSent?
if proto.hasSent { if proto.hasSent {
sent = try SSKProtoSyncMessageSent.parseProto(proto.sent) sent = try SSKProtoSyncMessageSent.parseProto(proto.sent)
} }
var contacts: SSKProtoSyncMessageContacts? = nil var contacts: SSKProtoSyncMessageContacts?
if proto.hasContacts { if proto.hasContacts {
contacts = try SSKProtoSyncMessageContacts.parseProto(proto.contacts) contacts = try SSKProtoSyncMessageContacts.parseProto(proto.contacts)
} }
var groups: SSKProtoSyncMessageGroups? = nil var groups: SSKProtoSyncMessageGroups?
if proto.hasGroups { if proto.hasGroups {
groups = try SSKProtoSyncMessageGroups.parseProto(proto.groups) groups = try SSKProtoSyncMessageGroups.parseProto(proto.groups)
} }
var request: SSKProtoSyncMessageRequest? = nil var request: SSKProtoSyncMessageRequest?
if proto.hasRequest { if proto.hasRequest {
request = try SSKProtoSyncMessageRequest.parseProto(proto.request) request = try SSKProtoSyncMessageRequest.parseProto(proto.request)
} }
@ -3517,17 +3517,17 @@ public enum SSKProtoError: Error {
var read: [SSKProtoSyncMessageRead] = [] var read: [SSKProtoSyncMessageRead] = []
read = try proto.read.map { try SSKProtoSyncMessageRead.parseProto($0) } read = try proto.read.map { try SSKProtoSyncMessageRead.parseProto($0) }
var blocked: SSKProtoSyncMessageBlocked? = nil var blocked: SSKProtoSyncMessageBlocked?
if proto.hasBlocked { if proto.hasBlocked {
blocked = try SSKProtoSyncMessageBlocked.parseProto(proto.blocked) blocked = try SSKProtoSyncMessageBlocked.parseProto(proto.blocked)
} }
var verified: SSKProtoVerified? = nil var verified: SSKProtoVerified?
if proto.hasVerified { if proto.hasVerified {
verified = try SSKProtoVerified.parseProto(proto.verified) verified = try SSKProtoVerified.parseProto(proto.verified)
} }
var configuration: SSKProtoSyncMessageConfiguration? = nil var configuration: SSKProtoSyncMessageConfiguration?
if proto.hasConfiguration { if proto.hasConfiguration {
configuration = try SSKProtoSyncMessageConfiguration.parseProto(proto.configuration) configuration = try SSKProtoSyncMessageConfiguration.parseProto(proto.configuration)
} }
@ -3911,7 +3911,7 @@ public enum SSKProtoError: Error {
} }
let type = SSKProtoGroupContextTypeWrap(proto.type) let type = SSKProtoGroupContextTypeWrap(proto.type)
var avatar: SSKProtoAttachmentPointer? = nil var avatar: SSKProtoAttachmentPointer?
if proto.hasAvatar { if proto.hasAvatar {
avatar = try SSKProtoAttachmentPointer.parseProto(proto.avatar) avatar = try SSKProtoAttachmentPointer.parseProto(proto.avatar)
} }
@ -4173,12 +4173,12 @@ public enum SSKProtoError: Error {
} }
let number = proto.number let number = proto.number
var avatar: SSKProtoContactDetailsAvatar? = nil var avatar: SSKProtoContactDetailsAvatar?
if proto.hasAvatar { if proto.hasAvatar {
avatar = try SSKProtoContactDetailsAvatar.parseProto(proto.avatar) avatar = try SSKProtoContactDetailsAvatar.parseProto(proto.avatar)
} }
var verified: SSKProtoVerified? = nil var verified: SSKProtoVerified?
if proto.hasVerified { if proto.hasVerified {
verified = try SSKProtoVerified.parseProto(proto.verified) verified = try SSKProtoVerified.parseProto(proto.verified)
} }
@ -4429,7 +4429,7 @@ public enum SSKProtoError: Error {
} }
let id = proto.id let id = proto.id
var avatar: SSKProtoGroupDetailsAvatar? = nil var avatar: SSKProtoGroupDetailsAvatar?
if proto.hasAvatar { if proto.hasAvatar {
avatar = try SSKProtoGroupDetailsAvatar.parseProto(proto.avatar) avatar = try SSKProtoGroupDetailsAvatar.parseProto(proto.avatar)
} }

@ -396,12 +396,12 @@ public enum WebSocketProtoError: Error {
} }
let type = WebSocketProtoWebSocketMessageTypeWrap(proto.type) let type = WebSocketProtoWebSocketMessageTypeWrap(proto.type)
var request: WebSocketProtoWebSocketRequestMessage? = nil var request: WebSocketProtoWebSocketRequestMessage?
if proto.hasRequest { if proto.hasRequest {
request = try WebSocketProtoWebSocketRequestMessage.parseProto(proto.request) request = try WebSocketProtoWebSocketRequestMessage.parseProto(proto.request)
} }
var response: WebSocketProtoWebSocketResponseMessage? = nil var response: WebSocketProtoWebSocketResponseMessage?
if proto.hasResponse { if proto.hasResponse {
response = try WebSocketProtoWebSocketResponseMessage.parseProto(proto.response) response = try WebSocketProtoWebSocketResponseMessage.parseProto(proto.response)
} }

Loading…
Cancel
Save