Use a separate sending queue for each conversation.

// FREEBIE
pull/1/head
Matthew Chen 9 years ago
parent 289d0df064
commit c3d2ea7abd

@ -257,7 +257,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
@property (nonatomic, readonly) id<ContactsManagerProtocol> contactsManager; @property (nonatomic, readonly) id<ContactsManagerProtocol> contactsManager;
@property (nonatomic, readonly) ContactsUpdater *contactsUpdater; @property (nonatomic, readonly) ContactsUpdater *contactsUpdater;
@property (nonatomic, readonly) OWSDisappearingMessagesJob *disappearingMessagesJob; @property (nonatomic, readonly) OWSDisappearingMessagesJob *disappearingMessagesJob;
@property (nonatomic, readonly) NSOperationQueue *sendingQueue; @property (atomic, readonly) NSMutableDictionary *sendingQueueMap;
@end @end
@ -277,9 +277,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
_storageManager = storageManager; _storageManager = storageManager;
_contactsManager = contactsManager; _contactsManager = contactsManager;
_contactsUpdater = contactsUpdater; _contactsUpdater = contactsUpdater;
_sendingQueue = [NSOperationQueue new]; _sendingQueueMap = [NSMutableDictionary new];
_sendingQueue.qualityOfService = NSOperationQualityOfServiceUserInitiated;
_sendingQueue.maxConcurrentOperationCount = 1;
_uploadingService = [[OWSUploadingService alloc] initWithNetworkManager:networkManager]; _uploadingService = [[OWSUploadingService alloc] initWithNetworkManager:networkManager];
_dbConnection = storageManager.newDatabaseConnection; _dbConnection = storageManager.newDatabaseConnection;
@ -288,6 +286,30 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
return self; return self;
} }
- (NSOperationQueue *)sendingQueueForMessage:(TSOutgoingMessage *)message
{
OWSAssert(message);
NSString *kDefaultQueueKey = @"kDefaultQueueKey";
NSString *queueKey = message.uniqueThreadId ?: kDefaultQueueKey;
OWSAssert(queueKey.length > 0);
@synchronized(self)
{
NSOperationQueue *sendingQueue = self.sendingQueueMap[queueKey];
if (!sendingQueue) {
sendingQueue = [NSOperationQueue new];
sendingQueue.qualityOfService = NSOperationQualityOfServiceUserInitiated;
sendingQueue.maxConcurrentOperationCount = 1;
self.sendingQueueMap[queueKey] = sendingQueue;
}
return sendingQueue;
}
}
- (void)sendMessage:(TSOutgoingMessage *)message - (void)sendMessage:(TSOutgoingMessage *)message
success:(void (^)())successHandler success:(void (^)())successHandler
failure:(void (^)(NSError *error))failureHandler failure:(void (^)(NSError *error))failureHandler
@ -303,7 +325,9 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
// We call `startBackgroundTask` here to prevent our app from suspending while being backgrounded // We call `startBackgroundTask` here to prevent our app from suspending while being backgrounded
// until the operation is completed - at which point the OWSSendMessageOperation ends it's background task. // until the operation is completed - at which point the OWSSendMessageOperation ends it's background task.
[sendMessageOperation startBackgroundTask]; [sendMessageOperation startBackgroundTask];
[self.sendingQueue addOperation:sendMessageOperation];
NSOperationQueue *sendingQueue = [self sendingQueueForMessage:message];
[sendingQueue addOperation:sendMessageOperation];
} }
- (void)attemptToSendMessage:(TSOutgoingMessage *)message - (void)attemptToSendMessage:(TSOutgoingMessage *)message

Loading…
Cancel
Save