From 6bd8512887ecf53b2089f6359f5de93965ff7e85 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 8 May 2020 12:20:31 +1000 Subject: [PATCH] Fix duplicate AFR issue --- .../src/Messages/OWSMessageSender.m | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index e5c0f6549..93069f440 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -364,6 +364,16 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; // Not really true but better from a UI point of view [NSNotificationCenter.defaultCenter postNotificationName:NSNotification.calculatingPoW object:[[NSNumber alloc] initWithUnsignedLongLong:message.timestamp]]; } + + dispatch_async(dispatch_get_main_queue(), ^{ + if ([LKFriendRequestProtocol shouldUpdateFriendRequestStatusFromMessage:message]) { + [self.primaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { + // Loki: Optimistically update friend request status when we can. This is used for + // e.g. preventing AFRs from being sent twice on a contact sync. + [LKFriendRequestProtocol setFriendRequestStatusToSendingIfNeededForHexEncodedPublicKey:message.thread.contactIdentifier transaction:transaction]; + }]; + } + }); dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSMutableArray *allAttachmentIds = [NSMutableArray new]; @@ -383,14 +393,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; [self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { [allAttachmentIds addObjectsFromArray:[OutgoingMessagePreparer prepareMessageForSending:message transaction:transaction]]; - - // Loki: Optimistically update friend request status when we can. This is used for - // e.g. preventing AFRs from being sent twice on a contact sync. - /* - if ([LKFriendRequestProtocol shouldUpdateFriendRequestStatusFromMessage:message]) { - [LKFriendRequestProtocol setFriendRequestStatusToSendingIfNeededForHexEncodedPublicKey:message.thread.contactIdentifier transaction:transaction]; - } - */ }]; NSOperationQueue *sendingQueue = [self sendingQueueForMessage:message];