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)
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

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

@ -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;

@ -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

@ -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.
//

@ -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)) {

@ -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.

@ -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;

@ -3,7 +3,6 @@
//
#import "SignalRecipient.h"
#import "OWSIdentityManager.h"
#import "TSAccountManager.h"
#import <YapDatabase/YapDatabaseConnection.h>
@ -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;

@ -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;

@ -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;
}

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

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

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

@ -57,7 +57,6 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
}
- (instancetype)initWithAttachmentProtos:(NSArray<OWSSignalServiceProtosAttachmentPointer *> *)attachmentProtos
relay:(nullable NSString *)relay
networkManager:(TSNetworkManager *)networkManager
transaction:(YapDatabaseReadWriteTransaction *)transaction
{
@ -72,7 +71,7 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
NSMutableArray<TSAttachmentPointer *> *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) {

@ -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;

@ -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;

@ -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;

@ -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;
}

@ -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

@ -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;

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

@ -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;

@ -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"

@ -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);

@ -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 =

@ -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<ContactsManagerProtocol>)contactsManager
contactsUpdater:(ContactsUpdater *)contactsUpdater;
contactsManager:(id<ContactsManagerProtocol>)contactsManager;
- (void)setBlockingManager:(OWSBlockingManager *)blockingManager;

@ -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<ContactsManagerProtocol> contactsManager;
@property (nonatomic, readonly) ContactsUpdater *contactsUpdater;
@property (atomic, readonly) NSMutableDictionary<NSString *, NSOperationQueue *> *sendingQueueMap;
@end
@ -226,7 +224,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
- (instancetype)initWithNetworkManager:(TSNetworkManager *)networkManager
primaryStorage:(OWSPrimaryStorage *)primaryStorage
contactsManager:(id<ContactsManagerProtocol>)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<SignalRecipient *> *)signalRecipientsForRecipientIds:(NSArray<NSString *> *)recipientIds
message:(TSOutgoingMessage *)message
error:(NSError **)error
{
OWSAssert(recipientIds);
OWSAssert(message);
OWSAssert(error);
*error = nil;
NSMutableArray<SignalRecipient *> *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<SignalRecipient *> *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

@ -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;

@ -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];
}

@ -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

@ -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

Loading…
Cancel
Save