From 6341905c9b8a20ba22b46c58bda6ffbbdab89c98 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 17 Apr 2017 16:45:22 -0400 Subject: [PATCH] Respond to CR. // FREEBIE --- src/Messages/Interactions/TSOutgoingMessage.h | 10 ++++++++++ src/Messages/Interactions/TSOutgoingMessage.m | 13 +++++++------ src/Messages/OWSMessageSender.m | 16 +++++++++++++--- src/Util/OWSError.h | 1 + 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/Messages/Interactions/TSOutgoingMessage.h b/src/Messages/Interactions/TSOutgoingMessage.h index af4cac438..1d7b5179c 100644 --- a/src/Messages/Interactions/TSOutgoingMessage.h +++ b/src/Messages/Interactions/TSOutgoingMessage.h @@ -34,6 +34,10 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) { @interface TSOutgoingMessage : TSMessage +- (instancetype)initWithTimestamp:(uint64_t)timestamp; + +- (instancetype)initWithTimestamp:(uint64_t)timestamp inThread:(nullable TSThread *)thread; + - (instancetype)initWithTimestamp:(uint64_t)timestamp inThread:(nullable TSThread *)thread messageBody:(nullable NSString *)body; @@ -42,6 +46,11 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) { inThread:(nullable TSThread *)thread groupMetaMessage:(TSGroupMetaMessage)groupMetaMessage; +- (instancetype)initWithTimestamp:(uint64_t)timestamp + inThread:(nullable TSThread *)thread + messageBody:(nullable NSString *)body + attachmentIds:(NSMutableArray *)attachmentIds; + - (instancetype)initWithTimestamp:(uint64_t)timestamp inThread:(nullable TSThread *)thread messageBody:(nullable NSString *)body @@ -153,6 +162,7 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) { #pragma mark - Sent Recipients +- (NSUInteger)sentRecipientsCount; - (BOOL)wasSentToRecipient:(NSString *)contactId; - (void)updateWithSentRecipient:(NSString *)contactId transaction:(YapDatabaseReadWriteTransaction *)transaction; - (void)updateWithSentRecipient:(NSString *)contactId; diff --git a/src/Messages/Interactions/TSOutgoingMessage.m b/src/Messages/Interactions/TSOutgoingMessage.m index bffff4108..73e8befc4 100644 --- a/src/Messages/Interactions/TSOutgoingMessage.m +++ b/src/Messages/Interactions/TSOutgoingMessage.m @@ -65,15 +65,11 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec - (instancetype)initWithTimestamp:(uint64_t)timestamp { - OWSAssert(0); - return [self initWithTimestamp:timestamp inThread:nil]; } - (instancetype)initWithTimestamp:(uint64_t)timestamp inThread:(nullable TSThread *)thread { - OWSAssert(0); - return [self initWithTimestamp:timestamp inThread:thread messageBody:nil]; } @@ -93,8 +89,6 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec messageBody:(nullable NSString *)body attachmentIds:(NSMutableArray *)attachmentIds { - OWSAssert(0); - return [self initWithTimestamp:timestamp inThread:thread messageBody:body @@ -336,6 +330,13 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec return [self.sentRecipients containsObject:contactId]; } +- (NSUInteger)sentRecipientsCount +{ + OWSAssert(self.sentRecipients); + + return self.sentRecipients.count; +} + - (void)updateWithSentRecipient:(NSString *)contactId transaction:(YapDatabaseReadWriteTransaction *)transaction { OWSAssert(transaction); diff --git a/src/Messages/OWSMessageSender.m b/src/Messages/OWSMessageSender.m index 4383e61c0..d566882a6 100644 --- a/src/Messages/OWSMessageSender.m +++ b/src/Messages/OWSMessageSender.m @@ -578,7 +578,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; DDLogError(@"%@ Unknown error finding contacts", self.tag); error = OWSErrorMakeFailedToSendOutgoingMessageError(); } - // If not recipients were found, there's no reason to retry. It will just fail again. + // If no recipients were found, there's no reason to retry. It will just fail again. [error setIsRetryable:NO]; failureHandler(error); return; @@ -609,6 +609,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; OWSAssert(recipientContactId.length > 0); NSArray *blockedPhoneNumbers = _blockingManager.blockedPhoneNumbers; if ([blockedPhoneNumbers containsObject:recipientContactId]) { + DDLogInfo(@"%@ skipping 1:1 send to blocked contact: %@", self.tag, recipientContactId); NSError *error = OWSErrorMakeMessageSendFailedToBlockListError(); // No need to retry - the user will continue to be blocked. [error setIsRetryable:NO]; @@ -757,8 +758,17 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; return failureHandler(firstNonRetryableError); } else { // If we only received errors that we should ignore, - // consider this send a success. - successHandler(); + // consider this send a success, unless the message could + // not be sent to any recipient. + if (message.sentRecipientsCount == 0) { + NSError *error = OWSErrorWithCodeDescription(OWSErrorCodeMessageSendNoValidRecipients, + NSLocalizedString(@"ERROR_DESCRIPTION_NO_VALID_RECIPIENTS", + @"Error indicating that an outgoing message had no valid recipients.")); + [error setIsRetryable:NO]; + failureHandler(error); + } else { + successHandler(); + } } }]; } diff --git a/src/Util/OWSError.h b/src/Util/OWSError.h index b770f0661..bdc1891af 100644 --- a/src/Util/OWSError.h +++ b/src/Util/OWSError.h @@ -23,6 +23,7 @@ typedef NS_ENUM(NSInteger, OWSErrorCode) { OWSErrorCodeNoSuchSignalRecipient = 777404, OWSErrorCodeMessageSendDisabledDueToPreKeyUpdateFailures = 777405, OWSErrorCodeMessageSendFailedToBlockList = 777406, + OWSErrorCodeMessageSendNoValidRecipients = 777407, OWSErrorCodeContactsUpdaterRateLimit = 777407, };