diff --git a/src/Contacts/TSThread.h b/src/Contacts/TSThread.h index 4e4b7fbee..7a25f0882 100644 --- a/src/Contacts/TSThread.h +++ b/src/Contacts/TSThread.h @@ -176,9 +176,6 @@ NS_ASSUME_NONNULL_BEGIN // data loss and will resolve all known issues. - (void)updateWithMutedUntilDate:(NSDate *)mutedUntilDate; -// Returns YES IFF the interaction should show up in the inbox as the last message. -+ (BOOL)shouldInteractionAppearInInbox:(TSInteraction *)interaction; - @end NS_ASSUME_NONNULL_END diff --git a/src/Contacts/TSThread.m b/src/Contacts/TSThread.m index b1624eeb0..7adb7d197 100644 --- a/src/Contacts/TSThread.m +++ b/src/Contacts/TSThread.m @@ -283,6 +283,7 @@ NS_ASSUME_NONNULL_BEGIN } } +// Returns YES IFF the interaction should show up in the inbox as the last message. + (BOOL)shouldInteractionAppearInInbox:(TSInteraction *)interaction { OWSAssert(interaction); diff --git a/src/Messages/OWSIdentityManager.h b/src/Messages/OWSIdentityManager.h index 171c6d87c..e22f06975 100644 --- a/src/Messages/OWSIdentityManager.h +++ b/src/Messages/OWSIdentityManager.h @@ -33,7 +33,7 @@ extern const NSUInteger kIdentityKeyLength; - (void)setVerificationState:(OWSVerificationState)verificationState identityKey:(NSData *)identityKey recipientId:(NSString *)recipientId - sendSyncMessage:(BOOL)sendSyncMessage; + isUserInitiatedChange:(BOOL)isUserInitiatedChange; - (OWSVerificationState)verificationStateForRecipientId:(NSString *)recipientId; diff --git a/src/Messages/OWSIdentityManager.m b/src/Messages/OWSIdentityManager.m index 94e194361..6ee189f22 100644 --- a/src/Messages/OWSIdentityManager.m +++ b/src/Messages/OWSIdentityManager.m @@ -205,7 +205,7 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa - (void)setVerificationState:(OWSVerificationState)verificationState identityKey:(NSData *)identityKey recipientId:(NSString *)recipientId - sendSyncMessage:(BOOL)sendSyncMessage + isUserInitiatedChange:(BOOL)isUserInitiatedChange { OWSAssert(identityKey.length > 0); OWSAssert(recipientId.length > 0); @@ -235,7 +235,7 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa [recipientIdentity updateWithVerificationState:verificationState]; - if (sendSyncMessage) { + if (isUserInitiatedChange) { [self enqueueSyncMessageForVerificationState:verificationState identityKey:identityKey recipientId:recipientId]; diff --git a/src/Messages/OWSMessageSender.m b/src/Messages/OWSMessageSender.m index 3e3ae93df..d6571a23b 100644 --- a/src/Messages/OWSMessageSender.m +++ b/src/Messages/OWSMessageSender.m @@ -159,7 +159,6 @@ NSUInteger const OWSSendMessageOperationMaxRetries = 4; @property (nonatomic, readonly) void (^failureHandler)(NSError *_Nonnull error); @property (nonatomic) OWSSendMessageOperationState operationState; @property (nonatomic) UIBackgroundTaskIdentifier backgroundTaskIdentifier; -@property (nonatomic) BOOL hasCompleted; @end @@ -191,17 +190,11 @@ NSUInteger const OWSSendMessageOperationMaxRetries = 4; return; } - // Ensure we call the success or failure handler exactly once. - @synchronized(strongSelf) - { - OWSCAssert(!strongSelf.hasCompleted); - strongSelf.hasCompleted = YES; - } - [message updateWithMessageState:TSOutgoingMessageStateSentToService]; DDLogDebug(@"%@ succeeded.", strongSelf.tag); aSuccessHandler(); + [strongSelf markAsComplete]; }; @@ -212,17 +205,11 @@ NSUInteger const OWSSendMessageOperationMaxRetries = 4; return; } - // Ensure we call the success or failure handler exactly once. - @synchronized(strongSelf) - { - OWSCAssert(!strongSelf.hasCompleted); - strongSelf.hasCompleted = YES; - } - [strongSelf.message updateWithSendingError:error]; DDLogDebug(@"%@ failed with error: %@", strongSelf.tag, error); aFailureHandler(error); + [strongSelf markAsComplete]; }; @@ -333,7 +320,15 @@ NSUInteger const OWSSendMessageOperationMaxRetries = 4; { [self willChangeValueForKey:OWSSendMessageOperationKeyIsExecuting]; [self willChangeValueForKey:OWSSendMessageOperationKeyIsFinished]; - self.operationState = OWSSendMessageOperationStateFinished; + + // Ensure we call the success or failure handler exactly once. + @synchronized(self) + { + OWSAssert(self.operationState != OWSSendMessageOperationStateFinished); + + self.operationState = OWSSendMessageOperationStateFinished; + } + [self didChangeValueForKey:OWSSendMessageOperationKeyIsExecuting]; [self didChangeValueForKey:OWSSendMessageOperationKeyIsFinished]; diff --git a/src/Messages/TSCall.m b/src/Messages/TSCall.m index f885bec78..7f4e63eef 100644 --- a/src/Messages/TSCall.m +++ b/src/Messages/TSCall.m @@ -102,8 +102,6 @@ NSUInteger TSCallCurrentSchemaVersion = 1; [self touchThreadWithTransaction:transaction]; // Ignore sendReadReceipt and updateExpiration; they don't apply to calls. - // - // TODO: Should we update expiration of calls? } #pragma mark - Methods