diff --git a/Signal/src/Jobs/MessageFetcherJob.swift b/Signal/src/Jobs/MessageFetcherJob.swift index 52ae389d3..37c68eba0 100644 --- a/Signal/src/Jobs/MessageFetcherJob.swift +++ b/Signal/src/Jobs/MessageFetcherJob.swift @@ -127,10 +127,6 @@ public class MessageFetcherJob: NSObject { } builder.setType(type) - if let relay = messageDict["relay"] as? String { - builder.setRelay(relay) - } - guard let timestamp = messageDict["timestamp"] as? UInt64 else { Logger.error("\(self.logTag) message body didn't have timestamp") return nil diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 8a1f71ab0..c3e8f4eda 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -74,7 +74,6 @@ #import #import #import -#import #import #import #import diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m index 9a1ded442..2241d9d2d 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m @@ -3729,7 +3729,6 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac digest:nil byteCount:filesize contentType:@"audio/mp3" - relay:@"" sourceFilename:@"test.mp3" attachmentType:TSAttachmentTypeDefault]; pointer.state = TSAttachmentPointerStateFailed; @@ -4596,7 +4595,6 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac digest:nil byteCount:filesize contentType:fakeAssetLoader.mimeType - relay:@"" sourceFilename:fakeAssetLoader.filename attachmentType:TSAttachmentTypeDefault]; attachmentPointer.state = TSAttachmentPointerStateFailed; diff --git a/SignalMessaging/environment/Release.m b/SignalMessaging/environment/Release.m index 210408b6b..0824d0428 100644 --- a/SignalMessaging/environment/Release.m +++ b/SignalMessaging/environment/Release.m @@ -24,8 +24,7 @@ ContactsUpdater *contactsUpdater = [ContactsUpdater sharedUpdater]; OWSMessageSender *messageSender = [[OWSMessageSender alloc] initWithNetworkManager:networkManager primaryStorage:primaryStorage - contactsManager:contactsManager - contactsUpdater:contactsUpdater]; + contactsManager:contactsManager]; instance = [[Environment alloc] initWithContactsManager:contactsManager contactsUpdater:contactsUpdater diff --git a/SignalServiceKit/src/Contacts/ContactsUpdater.h b/SignalServiceKit/src/Contacts/ContactsUpdater.h index 8ede7a494..a686db178 100644 --- a/SignalServiceKit/src/Contacts/ContactsUpdater.h +++ b/SignalServiceKit/src/Contacts/ContactsUpdater.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "SignalRecipient.h" @@ -12,8 +12,6 @@ NS_ASSUME_NONNULL_BEGIN + (instancetype)sharedUpdater; -- (nullable SignalRecipient *)synchronousLookup:(NSString *)identifier error:(NSError **)error; - // This asynchronously tries to verify whether or not a contact id // corresponds to a service account. // diff --git a/SignalServiceKit/src/Contacts/ContactsUpdater.m b/SignalServiceKit/src/Contacts/ContactsUpdater.m index 8d972f7c0..6c0e9cc63 100644 --- a/SignalServiceKit/src/Contacts/ContactsUpdater.m +++ b/SignalServiceKit/src/Contacts/ContactsUpdater.m @@ -38,38 +38,6 @@ NS_ASSUME_NONNULL_BEGIN return self; } -- (nullable SignalRecipient *)synchronousLookup:(NSString *)identifier error:(NSError **)error -{ - OWSAssert(error); - - DDLogInfo(@"%@ %s %@", self.logTag, __PRETTY_FUNCTION__, identifier); - - dispatch_semaphore_t sema = dispatch_semaphore_create(0); - - __block SignalRecipient *recipient; - - // Assigning to a pointer parameter within the block is not preventing the referenced error from being dealloc - // Instead, we avoid ambiguity in ownership by assigning to a local __block variable ensuring the error will be - // retained until our error parameter can take ownership. - __block NSError *retainedError; - [self lookupIdentifier:identifier - success:^(SignalRecipient *fetchedRecipient) { - recipient = fetchedRecipient; - dispatch_semaphore_signal(sema); - } - failure:^(NSError *lookupError) { - DDLogError( - @"%@ Could not find recipient for recipientId: %@, error: %@.", self.logTag, identifier, lookupError); - - retainedError = lookupError; - dispatch_semaphore_signal(sema); - }]; - - dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER); - *error = retainedError; - return recipient; -} - - (void)lookupIdentifier:(NSString *)identifier success:(void (^)(SignalRecipient *recipient))success failure:(void (^)(NSError *error))failure @@ -173,7 +141,7 @@ NS_ASSUME_NONNULL_BEGIN TSRequest *request = [OWSRequestFactory contactsIntersectionRequestWithHashesArray:hashes]; [[TSNetworkManager sharedManager] makeRequest:request success:^(NSURLSessionDataTask *tsTask, id responseDict) { - NSMutableDictionary *attributesForIdentifier = [NSMutableDictionary dictionary]; + NSMutableSet *identifiers = [NSMutableSet new]; NSArray *contactsArray = [(NSDictionary *)responseDict objectForKey:@"contacts"]; // Map attributes to phone numbers @@ -182,34 +150,26 @@ NS_ASSUME_NONNULL_BEGIN NSString *hash = [dict objectForKey:@"token"]; NSString *identifier = [phoneNumbersByHashes objectForKey:hash]; - if (!identifier) { + if (identifier.length < 1) { DDLogWarn(@"%@ An interesecting hash wasn't found in the mapping.", self.logTag); - break; + continue; } - [attributesForIdentifier setObject:dict forKey:identifier]; + [identifiers addObject:identifier]; } } // Insert or update contact attributes + // + // TODO: Do we need to _eagerly_ ensure a SignalRecipient instance exists? [OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { - for (NSString *identifier in attributesForIdentifier) { - SignalRecipient *recipient = [SignalRecipient recipientWithTextSecureIdentifier:identifier - withTransaction:transaction]; - if (!recipient) { - recipient = [[SignalRecipient alloc] initWithTextSecureIdentifier:identifier relay:nil]; - } - - NSDictionary *attributes = [attributesForIdentifier objectForKey:identifier]; - - recipient.relay = attributes[@"relay"]; - - [recipient saveWithTransaction:transaction]; + for (NSString *identifier in identifiers) { + [SignalRecipient ensureRecipientExistsWithRecipientId:identifier transaction:transaction]; } }]; - success([NSSet setWithArray:attributesForIdentifier.allKeys]); + success([identifiers copy]); } failure:^(NSURLSessionDataTask *task, NSError *error) { if (!IsNSErrorNetworkFailure(error)) { diff --git a/SignalServiceKit/src/Contacts/SignalAccount.h b/SignalServiceKit/src/Contacts/SignalAccount.h index 7f61c7b30..e2345c515 100644 --- a/SignalServiceKit/src/Contacts/SignalAccount.h +++ b/SignalServiceKit/src/Contacts/SignalAccount.h @@ -15,7 +15,6 @@ NS_ASSUME_NONNULL_BEGIN // * Contacts with multiple signal accounts will correspond to // multiple instances of SignalAccount. // * For non-contacts, the contact property will be nil. -// @interface SignalAccount : TSYapDatabaseObject // An E164 value identifying the signal account. diff --git a/SignalServiceKit/src/Contacts/SignalRecipient.h b/SignalServiceKit/src/Contacts/SignalRecipient.h index d9e6aa9a2..8e9896b7e 100644 --- a/SignalServiceKit/src/Contacts/SignalRecipient.h +++ b/SignalServiceKit/src/Contacts/SignalRecipient.h @@ -6,32 +6,36 @@ NS_ASSUME_NONNULL_BEGIN +// This class serves two purposes: +// +// * We only _persist_ SignalRecipient instances when we know +// that it corresponds to an account on the Signal service. +// So SignalRecipient serves as a defacto cache of "known +// Signal users." +// * We hang the "known device list" for signal accounts on +// this entity. @interface SignalRecipient : TSYapDatabaseObject -- (instancetype)initWithTextSecureIdentifier:(NSString *)textSecureIdentifier - relay:(nullable NSString *)relay; +@property (readonly) NSOrderedSet *devices; + +- (instancetype)init NS_UNAVAILABLE; + (instancetype)selfRecipient; ++ (SignalRecipient *)ensureRecipientExistsWithRecipientId:(NSString *)recipientId + transaction:(YapDatabaseReadWriteTransaction *)transaction; + + (void)ensureRecipientExistsWithRecipientId:(NSString *)recipientId deviceId:(UInt32)deviceId - relay:(NSString *)relay transaction:(YapDatabaseReadWriteTransaction *)transaction; + (nullable instancetype)recipientWithTextSecureIdentifier:(NSString *)textSecureIdentifier; + (nullable instancetype)recipientWithTextSecureIdentifier:(NSString *)textSecureIdentifier withTransaction:(YapDatabaseReadTransaction *)transaction; -@property (readonly) NSOrderedSet *devices; - (void)addDevices:(NSSet *)set; - (void)removeDevices:(NSSet *)set; -@property (nonatomic, nullable) NSString *relay; - -- (BOOL)supportsVoice; -// This property indicates support for both WebRTC audio and video calls. -- (BOOL)supportsWebRTC; - - (NSString *)recipientId; - (NSComparisonResult)compare:(SignalRecipient *)other; diff --git a/SignalServiceKit/src/Contacts/SignalRecipient.m b/SignalServiceKit/src/Contacts/SignalRecipient.m index 55d8003f2..351e74f9e 100644 --- a/SignalServiceKit/src/Contacts/SignalRecipient.m +++ b/SignalServiceKit/src/Contacts/SignalRecipient.m @@ -3,7 +3,6 @@ // #import "SignalRecipient.h" -#import "OWSIdentityManager.h" #import "TSAccountManager.h" #import @@ -15,24 +14,44 @@ NS_ASSUME_NONNULL_BEGIN @end +#pragma mark - + @implementation SignalRecipient + (NSString *)collection { return @"SignalRecipient"; } ++ (SignalRecipient *)ensureRecipientExistsWithRecipientId:(NSString *)recipientId + transaction:(YapDatabaseReadWriteTransaction *)transaction +{ + SignalRecipient *_Nullable recipient = + [self recipientWithTextSecureIdentifier:recipientId withTransaction:transaction]; + if (recipient) { + return recipient; + } + + DDLogDebug(@"%@ creating recipient: %@", self.logTag, recipientId); + + recipient = [[self alloc] initWithTextSecureIdentifier:recipientId]; + [recipient saveWithTransaction:transaction]; + return recipient; +} + + (void)ensureRecipientExistsWithRecipientId:(NSString *)recipientId deviceId:(UInt32)deviceId - relay:(NSString *)relay transaction:(YapDatabaseReadWriteTransaction *)transaction { SignalRecipient *_Nullable existingRecipient = [self recipientWithTextSecureIdentifier:recipientId withTransaction:transaction]; if (!existingRecipient) { - DDLogDebug( - @"%@ in %s creating recipient with deviceId: %u", self.logTag, __PRETTY_FUNCTION__, (unsigned int)deviceId); + DDLogDebug(@"%@ in %s creating recipient: %@, with deviceId: %u", + self.logTag, + __PRETTY_FUNCTION__, + recipientId, + (unsigned int)deviceId); - SignalRecipient *newRecipient = [[self alloc] initWithTextSecureIdentifier:recipientId relay:relay]; + SignalRecipient *newRecipient = [[self alloc] initWithTextSecureIdentifier:recipientId]; [newRecipient addDevices:[NSSet setWithObject:@(deviceId)]]; [newRecipient saveWithTransaction:transaction]; @@ -51,7 +70,6 @@ NS_ASSUME_NONNULL_BEGIN } - (instancetype)initWithTextSecureIdentifier:(NSString *)textSecureIdentifier - relay:(nullable NSString *)relay { self = [super initWithUniqueId:textSecureIdentifier]; if (!self) { @@ -75,8 +93,6 @@ NS_ASSUME_NONNULL_BEGIN _devices = [NSOrderedSet orderedSetWithObject:@(1)]; } - _relay = [relay isEqualToString:@""] ? nil : relay; - return self; } @@ -118,7 +134,7 @@ NS_ASSUME_NONNULL_BEGIN { SignalRecipient *myself = [self recipientWithTextSecureIdentifier:[TSAccountManager localNumber]]; if (!myself) { - myself = [[self alloc] initWithTextSecureIdentifier:[TSAccountManager localNumber] relay:nil]; + myself = [[self alloc] initWithTextSecureIdentifier:[TSAccountManager localNumber]]; } return myself; } @@ -144,16 +160,6 @@ NS_ASSUME_NONNULL_BEGIN self.devices = [updatedDevices copy]; } -- (BOOL)supportsVoice -{ - return YES; -} - -- (BOOL)supportsWebRTC -{ - return YES; -} - - (NSString *)recipientId { return self.uniqueId; diff --git a/SignalServiceKit/src/Contacts/Threads/TSContactThread.h b/SignalServiceKit/src/Contacts/Threads/TSContactThread.h index 0c28b19b2..c0ac5c256 100644 --- a/SignalServiceKit/src/Contacts/Threads/TSContactThread.h +++ b/SignalServiceKit/src/Contacts/Threads/TSContactThread.h @@ -15,10 +15,6 @@ NS_ASSUME_NONNULL_BEGIN + (instancetype)getOrCreateThreadWithContactId:(NSString *)contactId transaction:(YapDatabaseReadWriteTransaction *)transaction; -+ (instancetype)getOrCreateThreadWithContactId:(NSString *)contactId - transaction:(YapDatabaseReadWriteTransaction *)transaction - relay:(nullable NSString *)relay; - // Unlike getOrCreateThreadWithContactId, this will _NOT_ create a thread if one does not already exist. + (nullable instancetype)getThreadWithContactId:(NSString *)contactId transaction:(YapDatabaseReadTransaction *)transaction; diff --git a/SignalServiceKit/src/Contacts/Threads/TSContactThread.m b/SignalServiceKit/src/Contacts/Threads/TSContactThread.m index 1fbf3dc36..d6bd281a6 100644 --- a/SignalServiceKit/src/Contacts/Threads/TSContactThread.m +++ b/SignalServiceKit/src/Contacts/Threads/TSContactThread.m @@ -27,35 +27,6 @@ NS_ASSUME_NONNULL_BEGIN return self; } -+ (instancetype)getOrCreateThreadWithContactId:(NSString *)contactId - transaction:(YapDatabaseReadWriteTransaction *)transaction - relay:(nullable NSString *)relay -{ - OWSAssert(contactId.length > 0); - - SignalRecipient *recipient = - [SignalRecipient recipientWithTextSecureIdentifier:contactId withTransaction:transaction]; - - if (!recipient) { - // If no recipient record exists for that contactId, create an empty record - // for immediate use, then ask ContactsUpdater to try to update it async. - recipient = - [[SignalRecipient alloc] initWithTextSecureIdentifier:contactId - relay:relay]; - [recipient saveWithTransaction:transaction]; - - // Update recipient with Server record async. - [[ContactsUpdater sharedUpdater] lookupIdentifier:contactId - success:^(SignalRecipient *recipient) { - } - failure:^(NSError *error) { - DDLogWarn(@"Failed to lookup contact with error:%@", error); - }]; - } - - return [self getOrCreateThreadWithContactId:contactId transaction:transaction]; -} - + (instancetype)getOrCreateThreadWithContactId:(NSString *)contactId transaction:(YapDatabaseReadWriteTransaction *)transaction { OWSAssert(contactId.length > 0); @@ -68,6 +39,9 @@ NS_ASSUME_NONNULL_BEGIN [thread saveWithTransaction:transaction]; } + // TODO: Do we need to _eagerly_ ensure a SignalRecipient instance exists? + [SignalRecipient ensureRecipientExistsWithRecipientId:contactId transaction:transaction]; + return thread; } diff --git a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m index be7f09200..13341b9cd 100644 --- a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m +++ b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m @@ -4,7 +4,6 @@ #import "TSGroupThread.h" #import "NSData+Base64.h" -#import "SignalRecipient.h" #import "TSAttachmentStream.h" #import #import diff --git a/SignalServiceKit/src/Devices/OWSRecordTranscriptJob.m b/SignalServiceKit/src/Devices/OWSRecordTranscriptJob.m index 64f20b1b4..4dc206bac 100644 --- a/SignalServiceKit/src/Devices/OWSRecordTranscriptJob.m +++ b/SignalServiceKit/src/Devices/OWSRecordTranscriptJob.m @@ -80,7 +80,6 @@ NS_ASSUME_NONNULL_BEGIN OWSAttachmentsProcessor *attachmentsProcessor = [[OWSAttachmentsProcessor alloc] initWithAttachmentProtos:transcript.attachmentPointerProtos - relay:transcript.relay networkManager:self.networkManager transaction:transaction]; diff --git a/SignalServiceKit/src/Messages/Attachments/OWSAttachmentsProcessor.h b/SignalServiceKit/src/Messages/Attachments/OWSAttachmentsProcessor.h index b1a8b19c5..361aa9676 100644 --- a/SignalServiceKit/src/Messages/Attachments/OWSAttachmentsProcessor.h +++ b/SignalServiceKit/src/Messages/Attachments/OWSAttachmentsProcessor.h @@ -30,7 +30,6 @@ extern NSString *const kAttachmentDownloadAttachmentIDKey; - (instancetype)init NS_UNAVAILABLE; - (instancetype)initWithAttachmentProtos:(NSArray *)attachmentProtos - relay:(nullable NSString *)relay networkManager:(TSNetworkManager *)networkManager transaction:(YapDatabaseReadWriteTransaction *)transaction NS_DESIGNATED_INITIALIZER; diff --git a/SignalServiceKit/src/Messages/Attachments/OWSAttachmentsProcessor.m b/SignalServiceKit/src/Messages/Attachments/OWSAttachmentsProcessor.m index 0e1132786..980fc5635 100644 --- a/SignalServiceKit/src/Messages/Attachments/OWSAttachmentsProcessor.m +++ b/SignalServiceKit/src/Messages/Attachments/OWSAttachmentsProcessor.m @@ -57,7 +57,6 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f; } - (instancetype)initWithAttachmentProtos:(NSArray *)attachmentProtos - relay:(nullable NSString *)relay networkManager:(TSNetworkManager *)networkManager transaction:(YapDatabaseReadWriteTransaction *)transaction { @@ -72,7 +71,7 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f; NSMutableArray *attachmentPointers = [NSMutableArray new]; for (OWSSignalServiceProtosAttachmentPointer *attachmentProto in attachmentProtos) { - TSAttachmentPointer *pointer = [TSAttachmentPointer attachmentPointerFromProto:attachmentProto relay:relay]; + TSAttachmentPointer *pointer = [TSAttachmentPointer attachmentPointerFromProto:attachmentProto]; [attachmentIds addObject:pointer.uniqueId]; [pointer saveWithTransaction:transaction]; @@ -152,8 +151,7 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f; if (attachment.serverId < 100) { DDLogError(@"%@ Suspicious attachment id: %llu", self.logTag, (unsigned long long)attachment.serverId); } - TSRequest *request = - [OWSRequestFactory attachmentRequestWithAttachmentId:attachment.serverId relay:attachment.relay]; + TSRequest *request = [OWSRequestFactory attachmentRequestWithAttachmentId:attachment.serverId]; [self.networkManager makeRequest:request success:^(NSURLSessionDataTask *task, id responseObject) { diff --git a/SignalServiceKit/src/Messages/Attachments/TSAttachmentPointer.h b/SignalServiceKit/src/Messages/Attachments/TSAttachmentPointer.h index ddd96cad7..9920d6813 100644 --- a/SignalServiceKit/src/Messages/Attachments/TSAttachmentPointer.h +++ b/SignalServiceKit/src/Messages/Attachments/TSAttachmentPointer.h @@ -25,14 +25,11 @@ typedef NS_ENUM(NSUInteger, TSAttachmentPointerState) { digest:(nullable NSData *)digest byteCount:(UInt32)byteCount contentType:(NSString *)contentType - relay:(NSString *)relay sourceFilename:(nullable NSString *)sourceFilename attachmentType:(TSAttachmentType)attachmentType NS_DESIGNATED_INITIALIZER; -+ (TSAttachmentPointer *)attachmentPointerFromProto:(OWSSignalServiceProtosAttachmentPointer *)attachmentProto - relay:(NSString *_Nullable)relay; ++ (TSAttachmentPointer *)attachmentPointerFromProto:(OWSSignalServiceProtosAttachmentPointer *)attachmentProto; -@property (nonatomic, readonly) NSString *relay; @property (atomic) TSAttachmentPointerState state; @property (nullable, atomic) NSString *mostRecentFailureLocalizedText; diff --git a/SignalServiceKit/src/Messages/Attachments/TSAttachmentPointer.m b/SignalServiceKit/src/Messages/Attachments/TSAttachmentPointer.m index b1fbcead2..00a61c68d 100644 --- a/SignalServiceKit/src/Messages/Attachments/TSAttachmentPointer.m +++ b/SignalServiceKit/src/Messages/Attachments/TSAttachmentPointer.m @@ -30,7 +30,6 @@ NS_ASSUME_NONNULL_BEGIN digest:(nullable NSData *)digest byteCount:(UInt32)byteCount contentType:(NSString *)contentType - relay:(NSString *)relay sourceFilename:(nullable NSString *)sourceFilename attachmentType:(TSAttachmentType)attachmentType { @@ -45,7 +44,6 @@ NS_ASSUME_NONNULL_BEGIN _digest = digest; _state = TSAttachmentPointerStateEnqueued; - _relay = relay; self.attachmentType = attachmentType; return self; @@ -53,7 +51,6 @@ NS_ASSUME_NONNULL_BEGIN + (TSAttachmentPointer *)attachmentPointerFromProto:(OWSSignalServiceProtosAttachmentPointer *)attachmentProto - relay:(NSString *_Nullable)relay { OWSAssert(attachmentProto.id != 0); OWSAssert(attachmentProto.key != nil); @@ -75,7 +72,6 @@ NS_ASSUME_NONNULL_BEGIN digest:digest byteCount:attachmentProto.size contentType:attachmentProto.contentType - relay:relay sourceFilename:attachmentProto.fileName attachmentType:attachmentType]; return pointer; diff --git a/SignalServiceKit/src/Messages/DeviceSyncing/OWSIncomingSentMessageTranscript.h b/SignalServiceKit/src/Messages/DeviceSyncing/OWSIncomingSentMessageTranscript.h index 93e3b4317..a6b9d3737 100644 --- a/SignalServiceKit/src/Messages/DeviceSyncing/OWSIncomingSentMessageTranscript.h +++ b/SignalServiceKit/src/Messages/DeviceSyncing/OWSIncomingSentMessageTranscript.h @@ -19,10 +19,8 @@ NS_ASSUME_NONNULL_BEGIN @interface OWSIncomingSentMessageTranscript : NSObject - (instancetype)initWithProto:(OWSSignalServiceProtosSyncMessageSent *)sentProto - relay:(nullable NSString *)relay transaction:(YapDatabaseReadWriteTransaction *)transaction; -@property (nonatomic, readonly) NSString *relay; @property (nonatomic, readonly) OWSSignalServiceProtosDataMessage *dataMessage; @property (nonatomic, readonly) NSString *recipientId; @property (nonatomic, readonly) uint64_t timestamp; diff --git a/SignalServiceKit/src/Messages/DeviceSyncing/OWSIncomingSentMessageTranscript.m b/SignalServiceKit/src/Messages/DeviceSyncing/OWSIncomingSentMessageTranscript.m index 01490fc49..333fd0dad 100644 --- a/SignalServiceKit/src/Messages/DeviceSyncing/OWSIncomingSentMessageTranscript.m +++ b/SignalServiceKit/src/Messages/DeviceSyncing/OWSIncomingSentMessageTranscript.m @@ -19,7 +19,6 @@ NS_ASSUME_NONNULL_BEGIN @implementation OWSIncomingSentMessageTranscript - (instancetype)initWithProto:(OWSSignalServiceProtosSyncMessageSent *)sentProto - relay:(nullable NSString *)relay transaction:(YapDatabaseReadWriteTransaction *)transaction { self = [super init]; @@ -27,7 +26,6 @@ NS_ASSUME_NONNULL_BEGIN return self; } - _relay = relay; _dataMessage = sentProto.message; _recipientId = sentProto.destination; _timestamp = sentProto.timestamp; @@ -45,9 +43,8 @@ NS_ASSUME_NONNULL_BEGIN _thread = [TSContactThread getOrCreateThreadWithContactId:_recipientId transaction:transaction]; } - _quotedMessage = - [TSQuotedMessage quotedMessageForDataMessage:_dataMessage thread:_thread relay:relay transaction:transaction]; - _contact = [OWSContacts contactForDataMessage:_dataMessage relay:relay transaction:transaction]; + _quotedMessage = [TSQuotedMessage quotedMessageForDataMessage:_dataMessage thread:_thread transaction:transaction]; + _contact = [OWSContacts contactForDataMessage:_dataMessage transaction:transaction]; return self; } diff --git a/SignalServiceKit/src/Messages/Interactions/OWSContact.h b/SignalServiceKit/src/Messages/Interactions/OWSContact.h index 7dfc2ed86..254436f39 100644 --- a/SignalServiceKit/src/Messages/Interactions/OWSContact.h +++ b/SignalServiceKit/src/Messages/Interactions/OWSContact.h @@ -10,7 +10,6 @@ NS_ASSUME_NONNULL_BEGIN @class CNContact; @class OWSAttachmentInfo; @class OWSSignalServiceProtosDataMessage; -@class OWSSignalServiceProtosDataMessage; @class OWSSignalServiceProtosDataMessageContact; @class TSAttachment; @class TSAttachmentStream; @@ -177,7 +176,6 @@ NSString *NSStringForContactAddressType(OWSContactAddressType value); + (nullable OWSSignalServiceProtosDataMessageContact *)protoForContact:(OWSContact *)contact; + (nullable OWSContact *)contactForDataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage - relay:(nullable NSString *)relay transaction:(YapDatabaseReadWriteTransaction *)transaction; @end diff --git a/SignalServiceKit/src/Messages/Interactions/OWSContact.m b/SignalServiceKit/src/Messages/Interactions/OWSContact.m index a05c514b8..b105602f1 100644 --- a/SignalServiceKit/src/Messages/Interactions/OWSContact.m +++ b/SignalServiceKit/src/Messages/Interactions/OWSContact.m @@ -893,7 +893,6 @@ NSString *NSStringForContactAddressType(OWSContactAddressType value) } + (nullable OWSContact *)contactForDataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage - relay:(nullable NSString *)relay transaction:(YapDatabaseReadWriteTransaction *)transaction { OWSAssert(dataMessage); @@ -968,8 +967,7 @@ NSString *NSStringForContactAddressType(OWSContactAddressType value) if (avatarInfo.hasAvatar) { OWSSignalServiceProtosAttachmentPointer *avatarAttachment = avatarInfo.avatar; - TSAttachmentPointer *attachmentPointer = - [TSAttachmentPointer attachmentPointerFromProto:avatarAttachment relay:relay]; + TSAttachmentPointer *attachmentPointer = [TSAttachmentPointer attachmentPointerFromProto:avatarAttachment]; [attachmentPointer saveWithTransaction:transaction]; contact.avatarAttachmentId = attachmentPointer.uniqueId; diff --git a/SignalServiceKit/src/Messages/Interactions/TSQuotedMessage.h b/SignalServiceKit/src/Messages/Interactions/TSQuotedMessage.h index 202f8f1ec..49d973fec 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSQuotedMessage.h +++ b/SignalServiceKit/src/Messages/Interactions/TSQuotedMessage.h @@ -92,7 +92,6 @@ NS_ASSUME_NONNULL_BEGIN + (nullable instancetype)quotedMessageForDataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage thread:(TSThread *)thread - relay:(nullable NSString *)relay transaction:(YapDatabaseReadWriteTransaction *)transaction; @end diff --git a/SignalServiceKit/src/Messages/Interactions/TSQuotedMessage.m b/SignalServiceKit/src/Messages/Interactions/TSQuotedMessage.m index a846b5e6a..4dc7881e0 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSQuotedMessage.m +++ b/SignalServiceKit/src/Messages/Interactions/TSQuotedMessage.m @@ -105,7 +105,6 @@ NS_ASSUME_NONNULL_BEGIN + (TSQuotedMessage *_Nullable)quotedMessageForDataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage thread:(TSThread *)thread - relay:(nullable NSString *)relay transaction:(YapDatabaseReadWriteTransaction *)transaction { OWSAssert(dataMessage); @@ -169,7 +168,7 @@ NS_ASSUME_NONNULL_BEGIN OWSSignalServiceProtosAttachmentPointer *thumbnailAttachmentProto = quotedAttachment.thumbnail; TSAttachmentPointer *thumbnailPointer = - [TSAttachmentPointer attachmentPointerFromProto:thumbnailAttachmentProto relay:relay]; + [TSAttachmentPointer attachmentPointerFromProto:thumbnailAttachmentProto]; [thumbnailPointer saveWithTransaction:transaction]; attachmentInfo.thumbnailAttachmentPointerId = thumbnailPointer.uniqueId; diff --git a/SignalServiceKit/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeySendingErrorMessage.m b/SignalServiceKit/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeySendingErrorMessage.m index c1cdd2983..4dd0a1764 100644 --- a/SignalServiceKit/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeySendingErrorMessage.m +++ b/SignalServiceKit/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeySendingErrorMessage.m @@ -8,7 +8,6 @@ #import "OWSPrimaryStorage+SessionStore.h" #import "OWSPrimaryStorage.h" #import "PreKeyBundle+jsonDict.h" -#import "SignalRecipient.h" #import "TSContactThread.h" #import "TSErrorMessage_privateConstructor.h" #import "TSOutgoingMessage.h" diff --git a/SignalServiceKit/src/Messages/OWSMessageDecrypter.m b/SignalServiceKit/src/Messages/OWSMessageDecrypter.m index 001b3aa4c..fca8303ea 100644 --- a/SignalServiceKit/src/Messages/OWSMessageDecrypter.m +++ b/SignalServiceKit/src/Messages/OWSMessageDecrypter.m @@ -112,7 +112,6 @@ NS_ASSUME_NONNULL_BEGIN = ^(NSData *_Nullable plaintextData, YapDatabaseReadWriteTransaction *transaction) { [SignalRecipient ensureRecipientExistsWithRecipientId:envelope.source deviceId:envelope.sourceDevice - relay:envelope.relay transaction:transaction]; successBlockParameter(plaintextData, transaction); diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index 74f49f420..47989a9cd 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -516,7 +516,6 @@ NS_ASSUME_NONNULL_BEGIN OWSAssert(groupThread); OWSAttachmentsProcessor *attachmentsProcessor = [[OWSAttachmentsProcessor alloc] initWithAttachmentProtos:@[ dataMessage.group.avatar ] - relay:envelope.relay networkManager:self.networkManager transaction:transaction]; @@ -553,7 +552,6 @@ NS_ASSUME_NONNULL_BEGIN OWSAttachmentsProcessor *attachmentsProcessor = [[OWSAttachmentsProcessor alloc] initWithAttachmentProtos:dataMessage.attachments - relay:envelope.relay networkManager:self.networkManager transaction:transaction]; if (!attachmentsProcessor.hasSupportedAttachments) { @@ -605,7 +603,6 @@ NS_ASSUME_NONNULL_BEGIN if (syncMessage.hasSent) { OWSIncomingSentMessageTranscript *transcript = [[OWSIncomingSentMessageTranscript alloc] initWithProto:syncMessage.sent - relay:envelope.relay transaction:transaction]; OWSRecordTranscriptJob *recordJob = @@ -916,8 +913,7 @@ NS_ASSUME_NONNULL_BEGIN uint64_t timestamp = envelope.timestamp; NSString *body = dataMessage.body; NSData *groupId = dataMessage.hasGroup ? dataMessage.group.id : nil; - OWSContact *_Nullable contact = - [OWSContacts contactForDataMessage:dataMessage relay:envelope.relay transaction:transaction]; + OWSContact *_Nullable contact = [OWSContacts contactForDataMessage:dataMessage transaction:transaction]; if (dataMessage.group.type == OWSSignalServiceProtosGroupContextTypeRequestInfo) { [self handleGroupInfoRequest:envelope dataMessage:dataMessage transaction:transaction]; @@ -1016,7 +1012,6 @@ NS_ASSUME_NONNULL_BEGIN TSQuotedMessage *_Nullable quotedMessage = [TSQuotedMessage quotedMessageForDataMessage:dataMessage thread:oldGroupThread - relay:envelope.relay transaction:transaction]; DDLogDebug(@"%@ incoming message from: %@ for group: %@ with timestamp: %lu", @@ -1060,13 +1055,11 @@ NS_ASSUME_NONNULL_BEGIN self.logTag, envelopeAddress(envelope), (unsigned long)timestamp); - TSContactThread *thread = [TSContactThread getOrCreateThreadWithContactId:envelope.source - transaction:transaction - relay:envelope.relay]; + TSContactThread *thread = + [TSContactThread getOrCreateThreadWithContactId:envelope.source transaction:transaction]; TSQuotedMessage *_Nullable quotedMessage = [TSQuotedMessage quotedMessageForDataMessage:dataMessage thread:thread - relay:envelope.relay transaction:transaction]; TSIncomingMessage *incomingMessage = diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.h b/SignalServiceKit/src/Messages/OWSMessageSender.h index 6b65f8f9b..95c488969 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.h +++ b/SignalServiceKit/src/Messages/OWSMessageSender.h @@ -8,11 +8,9 @@ NS_ASSUME_NONNULL_BEGIN extern const NSUInteger kOversizeTextMessageSizeThreshold; -@class ContactsUpdater; @class OWSBlockingManager; @class OWSPrimaryStorage; @class OWSUploadingService; -@class SignalRecipient; @class TSInvalidIdentityKeySendingErrorMessage; @class TSNetworkManager; @class TSOutgoingMessage; @@ -42,15 +40,13 @@ NS_SWIFT_NAME(MessageSender) // For subclassing in tests OWSUploadingService *_uploadingService; - ContactsUpdater *_contactsUpdater; } - (instancetype)init NS_UNAVAILABLE; - (instancetype)initWithNetworkManager:(TSNetworkManager *)networkManager primaryStorage:(OWSPrimaryStorage *)primaryStorage - contactsManager:(id)contactsManager - contactsUpdater:(ContactsUpdater *)contactsUpdater; + contactsManager:(id)contactsManager; - (void)setBlockingManager:(OWSBlockingManager *)blockingManager; diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index 4b8c46580..ea2f506e4 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -4,7 +4,6 @@ #import "OWSMessageSender.h" #import "AppContext.h" -#import "ContactsUpdater.h" #import "NSData+keyVersionByte.h" #import "NSData+messagePadding.h" #import "NSDate+OWS.h" @@ -216,7 +215,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; @property (nonatomic, readonly) OWSBlockingManager *blockingManager; @property (nonatomic, readonly) YapDatabaseConnection *dbConnection; @property (nonatomic, readonly) id contactsManager; -@property (nonatomic, readonly) ContactsUpdater *contactsUpdater; @property (atomic, readonly) NSMutableDictionary *sendingQueueMap; @end @@ -226,7 +224,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; - (instancetype)initWithNetworkManager:(TSNetworkManager *)networkManager primaryStorage:(OWSPrimaryStorage *)primaryStorage contactsManager:(id)contactsManager - contactsUpdater:(ContactsUpdater *)contactsUpdater { self = [super init]; if (!self) { @@ -236,7 +233,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; _networkManager = networkManager; _primaryStorage = primaryStorage; _contactsManager = contactsManager; - _contactsUpdater = contactsUpdater; _sendingQueueMap = [NSMutableDictionary new]; _dbConnection = primaryStorage.newDatabaseConnection; @@ -451,42 +447,19 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; - (NSArray *)signalRecipientsForRecipientIds:(NSArray *)recipientIds message:(TSOutgoingMessage *)message - error:(NSError **)error { OWSAssert(recipientIds); OWSAssert(message); - OWSAssert(error); - - *error = nil; NSMutableArray *recipients = [NSMutableArray new]; - - for (NSString *recipientId in recipientIds) { - SignalRecipient *existingRecipient = [SignalRecipient recipientWithTextSecureIdentifier:recipientId]; - - if (existingRecipient) { - [recipients addObject:existingRecipient]; - } else { - SignalRecipient *newRecipient = [self.contactsUpdater synchronousLookup:recipientId error:error]; - if (newRecipient) { - [recipients addObject:newRecipient]; - } else { - DDLogWarn(@"%@ No SignalRecipient for recipientId: %@", self.logTag, recipientId); - [self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { - // Mark this recipient as "skipped". - [message updateWithSkippedRecipient:recipientId transaction:transaction]; - }]; - } + [self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { + for (NSString *recipientId in recipientIds) { + SignalRecipient *recipient = + [SignalRecipient ensureRecipientExistsWithRecipientId:recipientId transaction:transaction]; + [recipients addObject:recipient]; } - } - - if (recipients.count == 0 && !*error) { - // error should be set in contactsUpater, but just in case. - OWSProdError([OWSAnalyticsEvents messageSenderErrorCouldNotFindContacts1]); - *error = OWSErrorMakeFailedToSendOutgoingMessageError(); - } - - return [recipients copy]; + }]; + return recipients; } - (void)sendMessageToService:(TSOutgoingMessage *)message @@ -553,20 +526,9 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; return; } - NSError *error; NSArray *recipients = - [self signalRecipientsForRecipientIds:sendingRecipientIds.allObjects message:message error:&error]; - - if (recipients.count == 0) { - if (!error) { - OWSProdError([OWSAnalyticsEvents messageSenderErrorCouldNotFindContacts2]); - error = OWSErrorMakeFailedToSendOutgoingMessageError(); - } - // If no recipients were found, there's no reason to retry. It will just fail again. - [error setIsRetryable:NO]; - failureHandler(error); - return; - } + [self signalRecipientsForRecipientIds:sendingRecipientIds.allObjects message:message]; + OWSAssert(recipients.count == sendingRecipientIds.count); [self groupSend:recipients message:message thread:gThread success:successHandler failure:failureHandler]; @@ -593,26 +555,11 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; return; } - SignalRecipient *recipient = [SignalRecipient recipientWithTextSecureIdentifier:recipientContactId]; - if (!recipient) { - NSError *error; - // possibly returns nil. - recipient = [self.contactsUpdater synchronousLookup:recipientContactId error:&error]; - - if (error) { - if (error.code == OWSErrorCodeNoSuchSignalRecipient) { - DDLogWarn(@"%@ recipient contact not found", self.logTag); - [self unregisteredRecipient:recipient message:message thread:thread]; - } - - OWSProdError([OWSAnalyticsEvents messageSenderErrorCouldNotFindContacts3]); - // No need to repeat trying to find a failure. Apart from repeatedly failing, it would also cause us - // to print redundant error messages. - [error setIsRetryable:NO]; - failureHandler(error); - return; - } - } + __block SignalRecipient *recipient; + [self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { + recipient = + [SignalRecipient ensureRecipientExistsWithRecipientId:recipientContactId transaction:transaction]; + }]; if (!recipient) { NSError *error = OWSErrorMakeFailedToSendOutgoingMessageError(); @@ -977,7 +924,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; TSRequest *request = [OWSRequestFactory submitMessageRequestWithRecipient:recipient.uniqueId messages:deviceMessages - relay:recipient.relay timeStamp:message.timestamp]; if (useWebsocketIfAvailable && TSSocketManager.canMakeRequests) { [TSSocketManager.sharedManager makeRequest:request diff --git a/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.h b/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.h index d73be79c1..9ea9864c1 100644 --- a/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.h +++ b/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.h @@ -37,7 +37,7 @@ typedef NS_ENUM(NSUInteger, TSVerificationTransport) { TSVerificationTransportVo + (TSRequest *)allocAttachmentRequest; -+ (TSRequest *)attachmentRequestWithAttachmentId:(UInt64)attachmentId relay:(nullable NSString *)relay; ++ (TSRequest *)attachmentRequestWithAttachmentId:(UInt64)attachmentId; + (TSRequest *)availablePreKeysCountRequest; @@ -60,7 +60,6 @@ typedef NS_ENUM(NSUInteger, TSVerificationTransport) { TSVerificationTransportVo + (TSRequest *)submitMessageRequestWithRecipient:(NSString *)recipientId messages:(NSArray *)messages - relay:(nullable NSString *)relay timeStamp:(uint64_t)timeStamp; + (TSRequest *)registerSignedPrekeyRequestWithSignedPreKeyRecord:(SignedPreKeyRecord *)signedPreKey; diff --git a/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.m b/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.m index 1b38b7ea5..334252fc0 100644 --- a/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.m +++ b/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.m @@ -101,17 +101,12 @@ NS_ASSUME_NONNULL_BEGIN return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"GET" parameters:@{}]; } -+ (TSRequest *)attachmentRequestWithAttachmentId:(UInt64)attachmentId relay:(nullable NSString *)relay ++ (TSRequest *)attachmentRequestWithAttachmentId:(UInt64)attachmentId { OWSAssert(attachmentId > 0); NSString *path = [NSString stringWithFormat:@"%@/%llu", textSecureAttachmentsAPI, attachmentId]; - // TODO: Should this be in the parameters? - if (relay.length > 0) { - path = [path stringByAppendingFormat:@"?relay=%@", relay]; - } - return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"GET" parameters:@{}]; } @@ -211,7 +206,6 @@ NS_ASSUME_NONNULL_BEGIN + (TSRequest *)submitMessageRequestWithRecipient:(NSString *)recipientId messages:(NSArray *)messages - relay:(nullable NSString *)relay timeStamp:(uint64_t)timeStamp { // NOTE: messages may be empty; See comments in OWSDeviceManager. @@ -219,14 +213,11 @@ NS_ASSUME_NONNULL_BEGIN OWSAssert(timeStamp > 0); NSString *path = [textSecureMessagesAPI stringByAppendingString:recipientId]; - NSMutableDictionary *parameters = [@{ + NSDictionary *parameters = @{ @"messages" : messages, @"timestamp" : @(timeStamp), - } mutableCopy]; + }; - if (relay) { - parameters[@"relay"] = relay; - } return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"PUT" parameters:parameters]; } diff --git a/SignalServiceKit/src/Network/API/TSNetworkManager.m b/SignalServiceKit/src/Network/API/TSNetworkManager.m index d0414d70f..9ac53d739 100644 --- a/SignalServiceKit/src/Network/API/TSNetworkManager.m +++ b/SignalServiceKit/src/Network/API/TSNetworkManager.m @@ -222,6 +222,7 @@ typedef void (^failureBlock)(NSURLSessionDataTask *task, NSError *error); break; } case 417: { + // TODO: Is this response code obsolete? DDLogWarn(@"The number is already registered on a relay. Please unregister there first: %@", request); failureBlock(task, [self errorWithHTTPCode:statusCode diff --git a/SignalServiceKit/src/Protocols/ProtoBuf+OWS.m b/SignalServiceKit/src/Protocols/ProtoBuf+OWS.m index 00e207d9c..ae6c0bdb8 100644 --- a/SignalServiceKit/src/Protocols/ProtoBuf+OWS.m +++ b/SignalServiceKit/src/Protocols/ProtoBuf+OWS.m @@ -1,13 +1,12 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // +#import "Cryptography.h" #import "ProfileManagerProtocol.h" #import "ProtoBuf+OWS.h" -#import "SignalRecipient.h" #import "TSThread.h" #import "TextSecureKitEnv.h" -#import "Cryptography.h" NS_ASSUME_NONNULL_BEGIN