Streamline SignalRecipient.

pull/1/head
Matthew Chen 7 years ago
parent 601f1ffe75
commit d14f764b50

@ -127,10 +127,6 @@ public class MessageFetcherJob: NSObject {
} }
builder.setType(type) builder.setType(type)
if let relay = messageDict["relay"] as? String {
builder.setRelay(relay)
}
guard let timestamp = messageDict["timestamp"] as? UInt64 else { guard let timestamp = messageDict["timestamp"] as? UInt64 else {
Logger.error("\(self.logTag) message body didn't have timestamp") Logger.error("\(self.logTag) message body didn't have timestamp")
return nil return nil

@ -74,7 +74,6 @@
#import <SignalServiceKit/OWSPrimaryStorage.h> #import <SignalServiceKit/OWSPrimaryStorage.h>
#import <SignalServiceKit/OWSReadReceiptManager.h> #import <SignalServiceKit/OWSReadReceiptManager.h>
#import <SignalServiceKit/OWSVerificationStateChangeMessage.h> #import <SignalServiceKit/OWSVerificationStateChangeMessage.h>
#import <SignalServiceKit/SignalRecipient.h>
#import <SignalServiceKit/TSAccountManager.h> #import <SignalServiceKit/TSAccountManager.h>
#import <SignalServiceKit/TSGroupModel.h> #import <SignalServiceKit/TSGroupModel.h>
#import <SignalServiceKit/TSInvalidIdentityKeyReceivingErrorMessage.h> #import <SignalServiceKit/TSInvalidIdentityKeyReceivingErrorMessage.h>

@ -3729,7 +3729,6 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
digest:nil digest:nil
byteCount:filesize byteCount:filesize
contentType:@"audio/mp3" contentType:@"audio/mp3"
relay:@""
sourceFilename:@"test.mp3" sourceFilename:@"test.mp3"
attachmentType:TSAttachmentTypeDefault]; attachmentType:TSAttachmentTypeDefault];
pointer.state = TSAttachmentPointerStateFailed; pointer.state = TSAttachmentPointerStateFailed;
@ -4596,7 +4595,6 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
digest:nil digest:nil
byteCount:filesize byteCount:filesize
contentType:fakeAssetLoader.mimeType contentType:fakeAssetLoader.mimeType
relay:@""
sourceFilename:fakeAssetLoader.filename sourceFilename:fakeAssetLoader.filename
attachmentType:TSAttachmentTypeDefault]; attachmentType:TSAttachmentTypeDefault];
attachmentPointer.state = TSAttachmentPointerStateFailed; attachmentPointer.state = TSAttachmentPointerStateFailed;

@ -24,8 +24,7 @@
ContactsUpdater *contactsUpdater = [ContactsUpdater sharedUpdater]; ContactsUpdater *contactsUpdater = [ContactsUpdater sharedUpdater];
OWSMessageSender *messageSender = [[OWSMessageSender alloc] initWithNetworkManager:networkManager OWSMessageSender *messageSender = [[OWSMessageSender alloc] initWithNetworkManager:networkManager
primaryStorage:primaryStorage primaryStorage:primaryStorage
contactsManager:contactsManager contactsManager:contactsManager];
contactsUpdater:contactsUpdater];
instance = [[Environment alloc] initWithContactsManager:contactsManager instance = [[Environment alloc] initWithContactsManager:contactsManager
contactsUpdater:contactsUpdater contactsUpdater:contactsUpdater

@ -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" #import "SignalRecipient.h"
@ -12,8 +12,6 @@ NS_ASSUME_NONNULL_BEGIN
+ (instancetype)sharedUpdater; + (instancetype)sharedUpdater;
- (nullable SignalRecipient *)synchronousLookup:(NSString *)identifier error:(NSError **)error;
// This asynchronously tries to verify whether or not a contact id // This asynchronously tries to verify whether or not a contact id
// corresponds to a service account. // corresponds to a service account.
// //

@ -38,38 +38,6 @@ NS_ASSUME_NONNULL_BEGIN
return self; 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 - (void)lookupIdentifier:(NSString *)identifier
success:(void (^)(SignalRecipient *recipient))success success:(void (^)(SignalRecipient *recipient))success
failure:(void (^)(NSError *error))failure failure:(void (^)(NSError *error))failure
@ -173,7 +141,7 @@ NS_ASSUME_NONNULL_BEGIN
TSRequest *request = [OWSRequestFactory contactsIntersectionRequestWithHashesArray:hashes]; TSRequest *request = [OWSRequestFactory contactsIntersectionRequestWithHashesArray:hashes];
[[TSNetworkManager sharedManager] makeRequest:request [[TSNetworkManager sharedManager] makeRequest:request
success:^(NSURLSessionDataTask *tsTask, id responseDict) { success:^(NSURLSessionDataTask *tsTask, id responseDict) {
NSMutableDictionary *attributesForIdentifier = [NSMutableDictionary dictionary]; NSMutableSet *identifiers = [NSMutableSet new];
NSArray *contactsArray = [(NSDictionary *)responseDict objectForKey:@"contacts"]; NSArray *contactsArray = [(NSDictionary *)responseDict objectForKey:@"contacts"];
// Map attributes to phone numbers // Map attributes to phone numbers
@ -182,34 +150,26 @@ NS_ASSUME_NONNULL_BEGIN
NSString *hash = [dict objectForKey:@"token"]; NSString *hash = [dict objectForKey:@"token"];
NSString *identifier = [phoneNumbersByHashes objectForKey:hash]; NSString *identifier = [phoneNumbersByHashes objectForKey:hash];
if (!identifier) { if (identifier.length < 1) {
DDLogWarn(@"%@ An interesecting hash wasn't found in the mapping.", self.logTag); 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 // Insert or update contact attributes
//
// TODO: Do we need to _eagerly_ ensure a SignalRecipient instance exists?
[OWSPrimaryStorage.dbReadWriteConnection [OWSPrimaryStorage.dbReadWriteConnection
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
for (NSString *identifier in attributesForIdentifier) { for (NSString *identifier in identifiers) {
SignalRecipient *recipient = [SignalRecipient recipientWithTextSecureIdentifier:identifier [SignalRecipient ensureRecipientExistsWithRecipientId:identifier transaction:transaction];
withTransaction:transaction];
if (!recipient) {
recipient = [[SignalRecipient alloc] initWithTextSecureIdentifier:identifier relay:nil];
}
NSDictionary *attributes = [attributesForIdentifier objectForKey:identifier];
recipient.relay = attributes[@"relay"];
[recipient saveWithTransaction:transaction];
} }
}]; }];
success([NSSet setWithArray:attributesForIdentifier.allKeys]); success([identifiers copy]);
} }
failure:^(NSURLSessionDataTask *task, NSError *error) { failure:^(NSURLSessionDataTask *task, NSError *error) {
if (!IsNSErrorNetworkFailure(error)) { if (!IsNSErrorNetworkFailure(error)) {

@ -15,7 +15,6 @@ NS_ASSUME_NONNULL_BEGIN
// * Contacts with multiple signal accounts will correspond to // * Contacts with multiple signal accounts will correspond to
// multiple instances of SignalAccount. // multiple instances of SignalAccount.
// * For non-contacts, the contact property will be nil. // * For non-contacts, the contact property will be nil.
//
@interface SignalAccount : TSYapDatabaseObject @interface SignalAccount : TSYapDatabaseObject
// An E164 value identifying the signal account. // An E164 value identifying the signal account.

@ -6,32 +6,36 @@
NS_ASSUME_NONNULL_BEGIN 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 @interface SignalRecipient : TSYapDatabaseObject
- (instancetype)initWithTextSecureIdentifier:(NSString *)textSecureIdentifier @property (readonly) NSOrderedSet *devices;
relay:(nullable NSString *)relay;
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)selfRecipient; + (instancetype)selfRecipient;
+ (SignalRecipient *)ensureRecipientExistsWithRecipientId:(NSString *)recipientId
transaction:(YapDatabaseReadWriteTransaction *)transaction;
+ (void)ensureRecipientExistsWithRecipientId:(NSString *)recipientId + (void)ensureRecipientExistsWithRecipientId:(NSString *)recipientId
deviceId:(UInt32)deviceId deviceId:(UInt32)deviceId
relay:(NSString *)relay
transaction:(YapDatabaseReadWriteTransaction *)transaction; transaction:(YapDatabaseReadWriteTransaction *)transaction;
+ (nullable instancetype)recipientWithTextSecureIdentifier:(NSString *)textSecureIdentifier; + (nullable instancetype)recipientWithTextSecureIdentifier:(NSString *)textSecureIdentifier;
+ (nullable instancetype)recipientWithTextSecureIdentifier:(NSString *)textSecureIdentifier + (nullable instancetype)recipientWithTextSecureIdentifier:(NSString *)textSecureIdentifier
withTransaction:(YapDatabaseReadTransaction *)transaction; withTransaction:(YapDatabaseReadTransaction *)transaction;
@property (readonly) NSOrderedSet *devices;
- (void)addDevices:(NSSet *)set; - (void)addDevices:(NSSet *)set;
- (void)removeDevices:(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; - (NSString *)recipientId;
- (NSComparisonResult)compare:(SignalRecipient *)other; - (NSComparisonResult)compare:(SignalRecipient *)other;

@ -3,7 +3,6 @@
// //
#import "SignalRecipient.h" #import "SignalRecipient.h"
#import "OWSIdentityManager.h"
#import "TSAccountManager.h" #import "TSAccountManager.h"
#import <YapDatabase/YapDatabaseConnection.h> #import <YapDatabase/YapDatabaseConnection.h>
@ -15,24 +14,44 @@ NS_ASSUME_NONNULL_BEGIN
@end @end
#pragma mark -
@implementation SignalRecipient @implementation SignalRecipient
+ (NSString *)collection { + (NSString *)collection {
return @"SignalRecipient"; 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 + (void)ensureRecipientExistsWithRecipientId:(NSString *)recipientId
deviceId:(UInt32)deviceId deviceId:(UInt32)deviceId
relay:(NSString *)relay
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
SignalRecipient *_Nullable existingRecipient = SignalRecipient *_Nullable existingRecipient =
[self recipientWithTextSecureIdentifier:recipientId withTransaction:transaction]; [self recipientWithTextSecureIdentifier:recipientId withTransaction:transaction];
if (!existingRecipient) { if (!existingRecipient) {
DDLogDebug( DDLogDebug(@"%@ in %s creating recipient: %@, with deviceId: %u",
@"%@ in %s creating recipient with deviceId: %u", self.logTag, __PRETTY_FUNCTION__, (unsigned int)deviceId); 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 addDevices:[NSSet setWithObject:@(deviceId)]];
[newRecipient saveWithTransaction:transaction]; [newRecipient saveWithTransaction:transaction];
@ -51,7 +70,6 @@ NS_ASSUME_NONNULL_BEGIN
} }
- (instancetype)initWithTextSecureIdentifier:(NSString *)textSecureIdentifier - (instancetype)initWithTextSecureIdentifier:(NSString *)textSecureIdentifier
relay:(nullable NSString *)relay
{ {
self = [super initWithUniqueId:textSecureIdentifier]; self = [super initWithUniqueId:textSecureIdentifier];
if (!self) { if (!self) {
@ -75,8 +93,6 @@ NS_ASSUME_NONNULL_BEGIN
_devices = [NSOrderedSet orderedSetWithObject:@(1)]; _devices = [NSOrderedSet orderedSetWithObject:@(1)];
} }
_relay = [relay isEqualToString:@""] ? nil : relay;
return self; return self;
} }
@ -118,7 +134,7 @@ NS_ASSUME_NONNULL_BEGIN
{ {
SignalRecipient *myself = [self recipientWithTextSecureIdentifier:[TSAccountManager localNumber]]; SignalRecipient *myself = [self recipientWithTextSecureIdentifier:[TSAccountManager localNumber]];
if (!myself) { if (!myself) {
myself = [[self alloc] initWithTextSecureIdentifier:[TSAccountManager localNumber] relay:nil]; myself = [[self alloc] initWithTextSecureIdentifier:[TSAccountManager localNumber]];
} }
return myself; return myself;
} }
@ -144,16 +160,6 @@ NS_ASSUME_NONNULL_BEGIN
self.devices = [updatedDevices copy]; self.devices = [updatedDevices copy];
} }
- (BOOL)supportsVoice
{
return YES;
}
- (BOOL)supportsWebRTC
{
return YES;
}
- (NSString *)recipientId - (NSString *)recipientId
{ {
return self.uniqueId; return self.uniqueId;

@ -15,10 +15,6 @@ NS_ASSUME_NONNULL_BEGIN
+ (instancetype)getOrCreateThreadWithContactId:(NSString *)contactId + (instancetype)getOrCreateThreadWithContactId:(NSString *)contactId
transaction:(YapDatabaseReadWriteTransaction *)transaction; 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. // Unlike getOrCreateThreadWithContactId, this will _NOT_ create a thread if one does not already exist.
+ (nullable instancetype)getThreadWithContactId:(NSString *)contactId transaction:(YapDatabaseReadTransaction *)transaction; + (nullable instancetype)getThreadWithContactId:(NSString *)contactId transaction:(YapDatabaseReadTransaction *)transaction;

@ -27,35 +27,6 @@ NS_ASSUME_NONNULL_BEGIN
return self; 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 + (instancetype)getOrCreateThreadWithContactId:(NSString *)contactId
transaction:(YapDatabaseReadWriteTransaction *)transaction { transaction:(YapDatabaseReadWriteTransaction *)transaction {
OWSAssert(contactId.length > 0); OWSAssert(contactId.length > 0);
@ -68,6 +39,9 @@ NS_ASSUME_NONNULL_BEGIN
[thread saveWithTransaction:transaction]; [thread saveWithTransaction:transaction];
} }
// TODO: Do we need to _eagerly_ ensure a SignalRecipient instance exists?
[SignalRecipient ensureRecipientExistsWithRecipientId:contactId transaction:transaction];
return thread; return thread;
} }

@ -4,7 +4,6 @@
#import "TSGroupThread.h" #import "TSGroupThread.h"
#import "NSData+Base64.h" #import "NSData+Base64.h"
#import "SignalRecipient.h"
#import "TSAttachmentStream.h" #import "TSAttachmentStream.h"
#import <SignalServiceKit/TSAccountManager.h> #import <SignalServiceKit/TSAccountManager.h>
#import <YapDatabase/YapDatabaseConnection.h> #import <YapDatabase/YapDatabaseConnection.h>

@ -80,7 +80,6 @@ NS_ASSUME_NONNULL_BEGIN
OWSAttachmentsProcessor *attachmentsProcessor = OWSAttachmentsProcessor *attachmentsProcessor =
[[OWSAttachmentsProcessor alloc] initWithAttachmentProtos:transcript.attachmentPointerProtos [[OWSAttachmentsProcessor alloc] initWithAttachmentProtos:transcript.attachmentPointerProtos
relay:transcript.relay
networkManager:self.networkManager networkManager:self.networkManager
transaction:transaction]; transaction:transaction];

@ -30,7 +30,6 @@ extern NSString *const kAttachmentDownloadAttachmentIDKey;
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithAttachmentProtos:(NSArray<OWSSignalServiceProtosAttachmentPointer *> *)attachmentProtos - (instancetype)initWithAttachmentProtos:(NSArray<OWSSignalServiceProtosAttachmentPointer *> *)attachmentProtos
relay:(nullable NSString *)relay
networkManager:(TSNetworkManager *)networkManager networkManager:(TSNetworkManager *)networkManager
transaction:(YapDatabaseReadWriteTransaction *)transaction NS_DESIGNATED_INITIALIZER; transaction:(YapDatabaseReadWriteTransaction *)transaction NS_DESIGNATED_INITIALIZER;

@ -57,7 +57,6 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
} }
- (instancetype)initWithAttachmentProtos:(NSArray<OWSSignalServiceProtosAttachmentPointer *> *)attachmentProtos - (instancetype)initWithAttachmentProtos:(NSArray<OWSSignalServiceProtosAttachmentPointer *> *)attachmentProtos
relay:(nullable NSString *)relay
networkManager:(TSNetworkManager *)networkManager networkManager:(TSNetworkManager *)networkManager
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
@ -72,7 +71,7 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
NSMutableArray<TSAttachmentPointer *> *attachmentPointers = [NSMutableArray new]; NSMutableArray<TSAttachmentPointer *> *attachmentPointers = [NSMutableArray new];
for (OWSSignalServiceProtosAttachmentPointer *attachmentProto in attachmentProtos) { for (OWSSignalServiceProtosAttachmentPointer *attachmentProto in attachmentProtos) {
TSAttachmentPointer *pointer = [TSAttachmentPointer attachmentPointerFromProto:attachmentProto relay:relay]; TSAttachmentPointer *pointer = [TSAttachmentPointer attachmentPointerFromProto:attachmentProto];
[attachmentIds addObject:pointer.uniqueId]; [attachmentIds addObject:pointer.uniqueId];
[pointer saveWithTransaction:transaction]; [pointer saveWithTransaction:transaction];
@ -152,8 +151,7 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
if (attachment.serverId < 100) { if (attachment.serverId < 100) {
DDLogError(@"%@ Suspicious attachment id: %llu", self.logTag, (unsigned long long)attachment.serverId); DDLogError(@"%@ Suspicious attachment id: %llu", self.logTag, (unsigned long long)attachment.serverId);
} }
TSRequest *request = TSRequest *request = [OWSRequestFactory attachmentRequestWithAttachmentId:attachment.serverId];
[OWSRequestFactory attachmentRequestWithAttachmentId:attachment.serverId relay:attachment.relay];
[self.networkManager makeRequest:request [self.networkManager makeRequest:request
success:^(NSURLSessionDataTask *task, id responseObject) { success:^(NSURLSessionDataTask *task, id responseObject) {

@ -25,14 +25,11 @@ typedef NS_ENUM(NSUInteger, TSAttachmentPointerState) {
digest:(nullable NSData *)digest digest:(nullable NSData *)digest
byteCount:(UInt32)byteCount byteCount:(UInt32)byteCount
contentType:(NSString *)contentType contentType:(NSString *)contentType
relay:(NSString *)relay
sourceFilename:(nullable NSString *)sourceFilename sourceFilename:(nullable NSString *)sourceFilename
attachmentType:(TSAttachmentType)attachmentType NS_DESIGNATED_INITIALIZER; attachmentType:(TSAttachmentType)attachmentType NS_DESIGNATED_INITIALIZER;
+ (TSAttachmentPointer *)attachmentPointerFromProto:(OWSSignalServiceProtosAttachmentPointer *)attachmentProto + (TSAttachmentPointer *)attachmentPointerFromProto:(OWSSignalServiceProtosAttachmentPointer *)attachmentProto;
relay:(NSString *_Nullable)relay;
@property (nonatomic, readonly) NSString *relay;
@property (atomic) TSAttachmentPointerState state; @property (atomic) TSAttachmentPointerState state;
@property (nullable, atomic) NSString *mostRecentFailureLocalizedText; @property (nullable, atomic) NSString *mostRecentFailureLocalizedText;

@ -30,7 +30,6 @@ NS_ASSUME_NONNULL_BEGIN
digest:(nullable NSData *)digest digest:(nullable NSData *)digest
byteCount:(UInt32)byteCount byteCount:(UInt32)byteCount
contentType:(NSString *)contentType contentType:(NSString *)contentType
relay:(NSString *)relay
sourceFilename:(nullable NSString *)sourceFilename sourceFilename:(nullable NSString *)sourceFilename
attachmentType:(TSAttachmentType)attachmentType attachmentType:(TSAttachmentType)attachmentType
{ {
@ -45,7 +44,6 @@ NS_ASSUME_NONNULL_BEGIN
_digest = digest; _digest = digest;
_state = TSAttachmentPointerStateEnqueued; _state = TSAttachmentPointerStateEnqueued;
_relay = relay;
self.attachmentType = attachmentType; self.attachmentType = attachmentType;
return self; return self;
@ -53,7 +51,6 @@ NS_ASSUME_NONNULL_BEGIN
+ (TSAttachmentPointer *)attachmentPointerFromProto:(OWSSignalServiceProtosAttachmentPointer *)attachmentProto + (TSAttachmentPointer *)attachmentPointerFromProto:(OWSSignalServiceProtosAttachmentPointer *)attachmentProto
relay:(NSString *_Nullable)relay
{ {
OWSAssert(attachmentProto.id != 0); OWSAssert(attachmentProto.id != 0);
OWSAssert(attachmentProto.key != nil); OWSAssert(attachmentProto.key != nil);
@ -75,7 +72,6 @@ NS_ASSUME_NONNULL_BEGIN
digest:digest digest:digest
byteCount:attachmentProto.size byteCount:attachmentProto.size
contentType:attachmentProto.contentType contentType:attachmentProto.contentType
relay:relay
sourceFilename:attachmentProto.fileName sourceFilename:attachmentProto.fileName
attachmentType:attachmentType]; attachmentType:attachmentType];
return pointer; return pointer;

@ -19,10 +19,8 @@ NS_ASSUME_NONNULL_BEGIN
@interface OWSIncomingSentMessageTranscript : NSObject @interface OWSIncomingSentMessageTranscript : NSObject
- (instancetype)initWithProto:(OWSSignalServiceProtosSyncMessageSent *)sentProto - (instancetype)initWithProto:(OWSSignalServiceProtosSyncMessageSent *)sentProto
relay:(nullable NSString *)relay
transaction:(YapDatabaseReadWriteTransaction *)transaction; transaction:(YapDatabaseReadWriteTransaction *)transaction;
@property (nonatomic, readonly) NSString *relay;
@property (nonatomic, readonly) OWSSignalServiceProtosDataMessage *dataMessage; @property (nonatomic, readonly) OWSSignalServiceProtosDataMessage *dataMessage;
@property (nonatomic, readonly) NSString *recipientId; @property (nonatomic, readonly) NSString *recipientId;
@property (nonatomic, readonly) uint64_t timestamp; @property (nonatomic, readonly) uint64_t timestamp;

@ -19,7 +19,6 @@ NS_ASSUME_NONNULL_BEGIN
@implementation OWSIncomingSentMessageTranscript @implementation OWSIncomingSentMessageTranscript
- (instancetype)initWithProto:(OWSSignalServiceProtosSyncMessageSent *)sentProto - (instancetype)initWithProto:(OWSSignalServiceProtosSyncMessageSent *)sentProto
relay:(nullable NSString *)relay
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
self = [super init]; self = [super init];
@ -27,7 +26,6 @@ NS_ASSUME_NONNULL_BEGIN
return self; return self;
} }
_relay = relay;
_dataMessage = sentProto.message; _dataMessage = sentProto.message;
_recipientId = sentProto.destination; _recipientId = sentProto.destination;
_timestamp = sentProto.timestamp; _timestamp = sentProto.timestamp;
@ -45,9 +43,8 @@ NS_ASSUME_NONNULL_BEGIN
_thread = [TSContactThread getOrCreateThreadWithContactId:_recipientId transaction:transaction]; _thread = [TSContactThread getOrCreateThreadWithContactId:_recipientId transaction:transaction];
} }
_quotedMessage = _quotedMessage = [TSQuotedMessage quotedMessageForDataMessage:_dataMessage thread:_thread transaction:transaction];
[TSQuotedMessage quotedMessageForDataMessage:_dataMessage thread:_thread relay:relay transaction:transaction]; _contact = [OWSContacts contactForDataMessage:_dataMessage transaction:transaction];
_contact = [OWSContacts contactForDataMessage:_dataMessage relay:relay transaction:transaction];
return self; return self;
} }

@ -10,7 +10,6 @@ NS_ASSUME_NONNULL_BEGIN
@class CNContact; @class CNContact;
@class OWSAttachmentInfo; @class OWSAttachmentInfo;
@class OWSSignalServiceProtosDataMessage; @class OWSSignalServiceProtosDataMessage;
@class OWSSignalServiceProtosDataMessage;
@class OWSSignalServiceProtosDataMessageContact; @class OWSSignalServiceProtosDataMessageContact;
@class TSAttachment; @class TSAttachment;
@class TSAttachmentStream; @class TSAttachmentStream;
@ -177,7 +176,6 @@ NSString *NSStringForContactAddressType(OWSContactAddressType value);
+ (nullable OWSSignalServiceProtosDataMessageContact *)protoForContact:(OWSContact *)contact; + (nullable OWSSignalServiceProtosDataMessageContact *)protoForContact:(OWSContact *)contact;
+ (nullable OWSContact *)contactForDataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage + (nullable OWSContact *)contactForDataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
relay:(nullable NSString *)relay
transaction:(YapDatabaseReadWriteTransaction *)transaction; transaction:(YapDatabaseReadWriteTransaction *)transaction;
@end @end

@ -893,7 +893,6 @@ NSString *NSStringForContactAddressType(OWSContactAddressType value)
} }
+ (nullable OWSContact *)contactForDataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage + (nullable OWSContact *)contactForDataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
relay:(nullable NSString *)relay
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
OWSAssert(dataMessage); OWSAssert(dataMessage);
@ -968,8 +967,7 @@ NSString *NSStringForContactAddressType(OWSContactAddressType value)
if (avatarInfo.hasAvatar) { if (avatarInfo.hasAvatar) {
OWSSignalServiceProtosAttachmentPointer *avatarAttachment = avatarInfo.avatar; OWSSignalServiceProtosAttachmentPointer *avatarAttachment = avatarInfo.avatar;
TSAttachmentPointer *attachmentPointer = TSAttachmentPointer *attachmentPointer = [TSAttachmentPointer attachmentPointerFromProto:avatarAttachment];
[TSAttachmentPointer attachmentPointerFromProto:avatarAttachment relay:relay];
[attachmentPointer saveWithTransaction:transaction]; [attachmentPointer saveWithTransaction:transaction];
contact.avatarAttachmentId = attachmentPointer.uniqueId; contact.avatarAttachmentId = attachmentPointer.uniqueId;

@ -92,7 +92,6 @@ NS_ASSUME_NONNULL_BEGIN
+ (nullable instancetype)quotedMessageForDataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage + (nullable instancetype)quotedMessageForDataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
thread:(TSThread *)thread thread:(TSThread *)thread
relay:(nullable NSString *)relay
transaction:(YapDatabaseReadWriteTransaction *)transaction; transaction:(YapDatabaseReadWriteTransaction *)transaction;
@end @end

@ -105,7 +105,6 @@ NS_ASSUME_NONNULL_BEGIN
+ (TSQuotedMessage *_Nullable)quotedMessageForDataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage + (TSQuotedMessage *_Nullable)quotedMessageForDataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
thread:(TSThread *)thread thread:(TSThread *)thread
relay:(nullable NSString *)relay
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
OWSAssert(dataMessage); OWSAssert(dataMessage);
@ -169,7 +168,7 @@ NS_ASSUME_NONNULL_BEGIN
OWSSignalServiceProtosAttachmentPointer *thumbnailAttachmentProto = quotedAttachment.thumbnail; OWSSignalServiceProtosAttachmentPointer *thumbnailAttachmentProto = quotedAttachment.thumbnail;
TSAttachmentPointer *thumbnailPointer = TSAttachmentPointer *thumbnailPointer =
[TSAttachmentPointer attachmentPointerFromProto:thumbnailAttachmentProto relay:relay]; [TSAttachmentPointer attachmentPointerFromProto:thumbnailAttachmentProto];
[thumbnailPointer saveWithTransaction:transaction]; [thumbnailPointer saveWithTransaction:transaction];
attachmentInfo.thumbnailAttachmentPointerId = thumbnailPointer.uniqueId; attachmentInfo.thumbnailAttachmentPointerId = thumbnailPointer.uniqueId;

@ -8,7 +8,6 @@
#import "OWSPrimaryStorage+SessionStore.h" #import "OWSPrimaryStorage+SessionStore.h"
#import "OWSPrimaryStorage.h" #import "OWSPrimaryStorage.h"
#import "PreKeyBundle+jsonDict.h" #import "PreKeyBundle+jsonDict.h"
#import "SignalRecipient.h"
#import "TSContactThread.h" #import "TSContactThread.h"
#import "TSErrorMessage_privateConstructor.h" #import "TSErrorMessage_privateConstructor.h"
#import "TSOutgoingMessage.h" #import "TSOutgoingMessage.h"

@ -112,7 +112,6 @@ NS_ASSUME_NONNULL_BEGIN
= ^(NSData *_Nullable plaintextData, YapDatabaseReadWriteTransaction *transaction) { = ^(NSData *_Nullable plaintextData, YapDatabaseReadWriteTransaction *transaction) {
[SignalRecipient ensureRecipientExistsWithRecipientId:envelope.source [SignalRecipient ensureRecipientExistsWithRecipientId:envelope.source
deviceId:envelope.sourceDevice deviceId:envelope.sourceDevice
relay:envelope.relay
transaction:transaction]; transaction:transaction];
successBlockParameter(plaintextData, transaction); successBlockParameter(plaintextData, transaction);

@ -516,7 +516,6 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(groupThread); OWSAssert(groupThread);
OWSAttachmentsProcessor *attachmentsProcessor = OWSAttachmentsProcessor *attachmentsProcessor =
[[OWSAttachmentsProcessor alloc] initWithAttachmentProtos:@[ dataMessage.group.avatar ] [[OWSAttachmentsProcessor alloc] initWithAttachmentProtos:@[ dataMessage.group.avatar ]
relay:envelope.relay
networkManager:self.networkManager networkManager:self.networkManager
transaction:transaction]; transaction:transaction];
@ -553,7 +552,6 @@ NS_ASSUME_NONNULL_BEGIN
OWSAttachmentsProcessor *attachmentsProcessor = OWSAttachmentsProcessor *attachmentsProcessor =
[[OWSAttachmentsProcessor alloc] initWithAttachmentProtos:dataMessage.attachments [[OWSAttachmentsProcessor alloc] initWithAttachmentProtos:dataMessage.attachments
relay:envelope.relay
networkManager:self.networkManager networkManager:self.networkManager
transaction:transaction]; transaction:transaction];
if (!attachmentsProcessor.hasSupportedAttachments) { if (!attachmentsProcessor.hasSupportedAttachments) {
@ -605,7 +603,6 @@ NS_ASSUME_NONNULL_BEGIN
if (syncMessage.hasSent) { if (syncMessage.hasSent) {
OWSIncomingSentMessageTranscript *transcript = OWSIncomingSentMessageTranscript *transcript =
[[OWSIncomingSentMessageTranscript alloc] initWithProto:syncMessage.sent [[OWSIncomingSentMessageTranscript alloc] initWithProto:syncMessage.sent
relay:envelope.relay
transaction:transaction]; transaction:transaction];
OWSRecordTranscriptJob *recordJob = OWSRecordTranscriptJob *recordJob =
@ -916,8 +913,7 @@ NS_ASSUME_NONNULL_BEGIN
uint64_t timestamp = envelope.timestamp; uint64_t timestamp = envelope.timestamp;
NSString *body = dataMessage.body; NSString *body = dataMessage.body;
NSData *groupId = dataMessage.hasGroup ? dataMessage.group.id : nil; NSData *groupId = dataMessage.hasGroup ? dataMessage.group.id : nil;
OWSContact *_Nullable contact = OWSContact *_Nullable contact = [OWSContacts contactForDataMessage:dataMessage transaction:transaction];
[OWSContacts contactForDataMessage:dataMessage relay:envelope.relay transaction:transaction];
if (dataMessage.group.type == OWSSignalServiceProtosGroupContextTypeRequestInfo) { if (dataMessage.group.type == OWSSignalServiceProtosGroupContextTypeRequestInfo) {
[self handleGroupInfoRequest:envelope dataMessage:dataMessage transaction:transaction]; [self handleGroupInfoRequest:envelope dataMessage:dataMessage transaction:transaction];
@ -1016,7 +1012,6 @@ NS_ASSUME_NONNULL_BEGIN
TSQuotedMessage *_Nullable quotedMessage = [TSQuotedMessage quotedMessageForDataMessage:dataMessage TSQuotedMessage *_Nullable quotedMessage = [TSQuotedMessage quotedMessageForDataMessage:dataMessage
thread:oldGroupThread thread:oldGroupThread
relay:envelope.relay
transaction:transaction]; transaction:transaction];
DDLogDebug(@"%@ incoming message from: %@ for group: %@ with timestamp: %lu", DDLogDebug(@"%@ incoming message from: %@ for group: %@ with timestamp: %lu",
@ -1060,13 +1055,11 @@ NS_ASSUME_NONNULL_BEGIN
self.logTag, self.logTag,
envelopeAddress(envelope), envelopeAddress(envelope),
(unsigned long)timestamp); (unsigned long)timestamp);
TSContactThread *thread = [TSContactThread getOrCreateThreadWithContactId:envelope.source TSContactThread *thread =
transaction:transaction [TSContactThread getOrCreateThreadWithContactId:envelope.source transaction:transaction];
relay:envelope.relay];
TSQuotedMessage *_Nullable quotedMessage = [TSQuotedMessage quotedMessageForDataMessage:dataMessage TSQuotedMessage *_Nullable quotedMessage = [TSQuotedMessage quotedMessageForDataMessage:dataMessage
thread:thread thread:thread
relay:envelope.relay
transaction:transaction]; transaction:transaction];
TSIncomingMessage *incomingMessage = TSIncomingMessage *incomingMessage =

@ -8,11 +8,9 @@ NS_ASSUME_NONNULL_BEGIN
extern const NSUInteger kOversizeTextMessageSizeThreshold; extern const NSUInteger kOversizeTextMessageSizeThreshold;
@class ContactsUpdater;
@class OWSBlockingManager; @class OWSBlockingManager;
@class OWSPrimaryStorage; @class OWSPrimaryStorage;
@class OWSUploadingService; @class OWSUploadingService;
@class SignalRecipient;
@class TSInvalidIdentityKeySendingErrorMessage; @class TSInvalidIdentityKeySendingErrorMessage;
@class TSNetworkManager; @class TSNetworkManager;
@class TSOutgoingMessage; @class TSOutgoingMessage;
@ -42,15 +40,13 @@ NS_SWIFT_NAME(MessageSender)
// For subclassing in tests // For subclassing in tests
OWSUploadingService *_uploadingService; OWSUploadingService *_uploadingService;
ContactsUpdater *_contactsUpdater;
} }
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithNetworkManager:(TSNetworkManager *)networkManager - (instancetype)initWithNetworkManager:(TSNetworkManager *)networkManager
primaryStorage:(OWSPrimaryStorage *)primaryStorage primaryStorage:(OWSPrimaryStorage *)primaryStorage
contactsManager:(id<ContactsManagerProtocol>)contactsManager contactsManager:(id<ContactsManagerProtocol>)contactsManager;
contactsUpdater:(ContactsUpdater *)contactsUpdater;
- (void)setBlockingManager:(OWSBlockingManager *)blockingManager; - (void)setBlockingManager:(OWSBlockingManager *)blockingManager;

@ -4,7 +4,6 @@
#import "OWSMessageSender.h" #import "OWSMessageSender.h"
#import "AppContext.h" #import "AppContext.h"
#import "ContactsUpdater.h"
#import "NSData+keyVersionByte.h" #import "NSData+keyVersionByte.h"
#import "NSData+messagePadding.h" #import "NSData+messagePadding.h"
#import "NSDate+OWS.h" #import "NSDate+OWS.h"
@ -216,7 +215,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
@property (nonatomic, readonly) OWSBlockingManager *blockingManager; @property (nonatomic, readonly) OWSBlockingManager *blockingManager;
@property (nonatomic, readonly) YapDatabaseConnection *dbConnection; @property (nonatomic, readonly) YapDatabaseConnection *dbConnection;
@property (nonatomic, readonly) id<ContactsManagerProtocol> contactsManager; @property (nonatomic, readonly) id<ContactsManagerProtocol> contactsManager;
@property (nonatomic, readonly) ContactsUpdater *contactsUpdater;
@property (atomic, readonly) NSMutableDictionary<NSString *, NSOperationQueue *> *sendingQueueMap; @property (atomic, readonly) NSMutableDictionary<NSString *, NSOperationQueue *> *sendingQueueMap;
@end @end
@ -226,7 +224,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
- (instancetype)initWithNetworkManager:(TSNetworkManager *)networkManager - (instancetype)initWithNetworkManager:(TSNetworkManager *)networkManager
primaryStorage:(OWSPrimaryStorage *)primaryStorage primaryStorage:(OWSPrimaryStorage *)primaryStorage
contactsManager:(id<ContactsManagerProtocol>)contactsManager contactsManager:(id<ContactsManagerProtocol>)contactsManager
contactsUpdater:(ContactsUpdater *)contactsUpdater
{ {
self = [super init]; self = [super init];
if (!self) { if (!self) {
@ -236,7 +233,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
_networkManager = networkManager; _networkManager = networkManager;
_primaryStorage = primaryStorage; _primaryStorage = primaryStorage;
_contactsManager = contactsManager; _contactsManager = contactsManager;
_contactsUpdater = contactsUpdater;
_sendingQueueMap = [NSMutableDictionary new]; _sendingQueueMap = [NSMutableDictionary new];
_dbConnection = primaryStorage.newDatabaseConnection; _dbConnection = primaryStorage.newDatabaseConnection;
@ -451,42 +447,19 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
- (NSArray<SignalRecipient *> *)signalRecipientsForRecipientIds:(NSArray<NSString *> *)recipientIds - (NSArray<SignalRecipient *> *)signalRecipientsForRecipientIds:(NSArray<NSString *> *)recipientIds
message:(TSOutgoingMessage *)message message:(TSOutgoingMessage *)message
error:(NSError **)error
{ {
OWSAssert(recipientIds); OWSAssert(recipientIds);
OWSAssert(message); OWSAssert(message);
OWSAssert(error);
*error = nil;
NSMutableArray<SignalRecipient *> *recipients = [NSMutableArray new]; NSMutableArray<SignalRecipient *> *recipients = [NSMutableArray new];
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
for (NSString *recipientId in recipientIds) { for (NSString *recipientId in recipientIds) {
SignalRecipient *existingRecipient = [SignalRecipient recipientWithTextSecureIdentifier:recipientId]; SignalRecipient *recipient =
[SignalRecipient ensureRecipientExistsWithRecipientId:recipientId transaction:transaction];
if (existingRecipient) { [recipients addObject:recipient];
[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];
}];
}
} }
} }];
return recipients;
if (recipients.count == 0 && !*error) {
// error should be set in contactsUpater, but just in case.
OWSProdError([OWSAnalyticsEvents messageSenderErrorCouldNotFindContacts1]);
*error = OWSErrorMakeFailedToSendOutgoingMessageError();
}
return [recipients copy];
} }
- (void)sendMessageToService:(TSOutgoingMessage *)message - (void)sendMessageToService:(TSOutgoingMessage *)message
@ -553,20 +526,9 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
return; return;
} }
NSError *error;
NSArray<SignalRecipient *> *recipients = NSArray<SignalRecipient *> *recipients =
[self signalRecipientsForRecipientIds:sendingRecipientIds.allObjects message:message error:&error]; [self signalRecipientsForRecipientIds:sendingRecipientIds.allObjects message:message];
OWSAssert(recipients.count == sendingRecipientIds.count);
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 groupSend:recipients message:message thread:gThread success:successHandler failure:failureHandler]; [self groupSend:recipients message:message thread:gThread success:successHandler failure:failureHandler];
@ -593,26 +555,11 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
return; return;
} }
SignalRecipient *recipient = [SignalRecipient recipientWithTextSecureIdentifier:recipientContactId]; __block SignalRecipient *recipient;
if (!recipient) { [self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
NSError *error; recipient =
// possibly returns nil. [SignalRecipient ensureRecipientExistsWithRecipientId:recipientContactId transaction:transaction];
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;
}
}
if (!recipient) { if (!recipient) {
NSError *error = OWSErrorMakeFailedToSendOutgoingMessageError(); NSError *error = OWSErrorMakeFailedToSendOutgoingMessageError();
@ -977,7 +924,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
TSRequest *request = [OWSRequestFactory submitMessageRequestWithRecipient:recipient.uniqueId TSRequest *request = [OWSRequestFactory submitMessageRequestWithRecipient:recipient.uniqueId
messages:deviceMessages messages:deviceMessages
relay:recipient.relay
timeStamp:message.timestamp]; timeStamp:message.timestamp];
if (useWebsocketIfAvailable && TSSocketManager.canMakeRequests) { if (useWebsocketIfAvailable && TSSocketManager.canMakeRequests) {
[TSSocketManager.sharedManager makeRequest:request [TSSocketManager.sharedManager makeRequest:request

@ -37,7 +37,7 @@ typedef NS_ENUM(NSUInteger, TSVerificationTransport) { TSVerificationTransportVo
+ (TSRequest *)allocAttachmentRequest; + (TSRequest *)allocAttachmentRequest;
+ (TSRequest *)attachmentRequestWithAttachmentId:(UInt64)attachmentId relay:(nullable NSString *)relay; + (TSRequest *)attachmentRequestWithAttachmentId:(UInt64)attachmentId;
+ (TSRequest *)availablePreKeysCountRequest; + (TSRequest *)availablePreKeysCountRequest;
@ -60,7 +60,6 @@ typedef NS_ENUM(NSUInteger, TSVerificationTransport) { TSVerificationTransportVo
+ (TSRequest *)submitMessageRequestWithRecipient:(NSString *)recipientId + (TSRequest *)submitMessageRequestWithRecipient:(NSString *)recipientId
messages:(NSArray *)messages messages:(NSArray *)messages
relay:(nullable NSString *)relay
timeStamp:(uint64_t)timeStamp; timeStamp:(uint64_t)timeStamp;
+ (TSRequest *)registerSignedPrekeyRequestWithSignedPreKeyRecord:(SignedPreKeyRecord *)signedPreKey; + (TSRequest *)registerSignedPrekeyRequestWithSignedPreKeyRecord:(SignedPreKeyRecord *)signedPreKey;

@ -101,17 +101,12 @@ NS_ASSUME_NONNULL_BEGIN
return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"GET" parameters:@{}]; return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"GET" parameters:@{}];
} }
+ (TSRequest *)attachmentRequestWithAttachmentId:(UInt64)attachmentId relay:(nullable NSString *)relay + (TSRequest *)attachmentRequestWithAttachmentId:(UInt64)attachmentId
{ {
OWSAssert(attachmentId > 0); OWSAssert(attachmentId > 0);
NSString *path = [NSString stringWithFormat:@"%@/%llu", textSecureAttachmentsAPI, attachmentId]; 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:@{}]; return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"GET" parameters:@{}];
} }
@ -211,7 +206,6 @@ NS_ASSUME_NONNULL_BEGIN
+ (TSRequest *)submitMessageRequestWithRecipient:(NSString *)recipientId + (TSRequest *)submitMessageRequestWithRecipient:(NSString *)recipientId
messages:(NSArray *)messages messages:(NSArray *)messages
relay:(nullable NSString *)relay
timeStamp:(uint64_t)timeStamp timeStamp:(uint64_t)timeStamp
{ {
// NOTE: messages may be empty; See comments in OWSDeviceManager. // NOTE: messages may be empty; See comments in OWSDeviceManager.
@ -219,14 +213,11 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(timeStamp > 0); OWSAssert(timeStamp > 0);
NSString *path = [textSecureMessagesAPI stringByAppendingString:recipientId]; NSString *path = [textSecureMessagesAPI stringByAppendingString:recipientId];
NSMutableDictionary *parameters = [@{ NSDictionary *parameters = @{
@"messages" : messages, @"messages" : messages,
@"timestamp" : @(timeStamp), @"timestamp" : @(timeStamp),
} mutableCopy]; };
if (relay) {
parameters[@"relay"] = relay;
}
return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"PUT" parameters:parameters]; return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"PUT" parameters:parameters];
} }

@ -222,6 +222,7 @@ typedef void (^failureBlock)(NSURLSessionDataTask *task, NSError *error);
break; break;
} }
case 417: { case 417: {
// TODO: Is this response code obsolete?
DDLogWarn(@"The number is already registered on a relay. Please unregister there first: %@", request); DDLogWarn(@"The number is already registered on a relay. Please unregister there first: %@", request);
failureBlock(task, failureBlock(task,
[self errorWithHTTPCode:statusCode [self errorWithHTTPCode:statusCode

@ -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 "ProfileManagerProtocol.h"
#import "ProtoBuf+OWS.h" #import "ProtoBuf+OWS.h"
#import "SignalRecipient.h"
#import "TSThread.h" #import "TSThread.h"
#import "TextSecureKitEnv.h" #import "TextSecureKitEnv.h"
#import "Cryptography.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN

Loading…
Cancel
Save