Fix glitch in batch processing of incoming messages.
This commit is contained in:
parent
e48542e1db
commit
6f28c75257
|
@ -8,6 +8,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
+ (NSDateFormatter *)dateFormatter;
|
||||
+ (NSDateFormatter *)timeFormatter;
|
||||
|
||||
+ (BOOL)dateIsOlderThanOneDay:(NSDate *)date;
|
||||
+ (BOOL)dateIsOlderThanOneWeek:(NSDate *)date;
|
||||
+ (BOOL)dateIsToday:(NSDate *)date;
|
||||
|
|
|
@ -269,6 +269,10 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
|
|||
selector:@selector(appIsReady)
|
||||
name:AppIsReadyNotification
|
||||
object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(yapDatabaseModified:)
|
||||
name:YapDatabaseModifiedNotification
|
||||
object:TSStorageManager.sharedManager.dbNotificationObject];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
@ -283,6 +287,13 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
|
|||
[self drainQueue];
|
||||
}
|
||||
|
||||
- (void)yapDatabaseModified:(NSNotification *)notification
|
||||
{
|
||||
OWSAssertIsOnMainThread();
|
||||
|
||||
[self drainQueue];
|
||||
}
|
||||
|
||||
#pragma mark - instance methods
|
||||
|
||||
- (dispatch_queue_t)serialQueue
|
||||
|
@ -316,6 +327,13 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
|
|||
dispatch_async(self.serialQueue, ^{
|
||||
if (!AppReadiness.isAppReady) {
|
||||
// We don't want to process incoming messages until storage is ready.
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[self drainQueue];
|
||||
}];
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -471,7 +489,8 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
|
|||
|
||||
// We need to persist the decrypted envelope data ASAP to prevent data loss.
|
||||
[self.processingQueue enqueueEnvelopeData:envelopeData plaintextData:plaintextData transaction:transaction];
|
||||
[self.processingQueue drainQueue];
|
||||
// The new envelope won't be visible to the finder until this transaction commits,
|
||||
// so don't bother calling drainQueue here.
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -137,9 +137,12 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
- (void)yapDatabaseModified:(NSNotification *)notification
|
||||
{
|
||||
if (AppReadiness.isAppReady) {
|
||||
[OWSMessageUtils.sharedManager updateApplicationBadgeCount];
|
||||
}
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[OWSMessageUtils.sharedManager updateApplicationBadgeCount];
|
||||
}];
|
||||
});
|
||||
}
|
||||
|
||||
#pragma mark - Blocking
|
||||
|
|
|
@ -123,7 +123,8 @@ NSString *const OWSMessageDecryptJobFinderExtensionGroup = @"OWSMessageProcessin
|
|||
- (void)addJobForEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
|
||||
{
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[[[OWSMessageDecryptJob alloc] initWithEnvelope:envelope] saveWithTransaction:transaction];
|
||||
OWSMessageDecryptJob *job = [[OWSMessageDecryptJob alloc] initWithEnvelope:envelope];
|
||||
[job saveWithTransaction:transaction];
|
||||
}];
|
||||
}
|
||||
|
||||
|
@ -287,6 +288,12 @@ NSString *const OWSMessageDecryptJobFinderExtensionGroup = @"OWSMessageProcessin
|
|||
dispatch_async(self.serialQueue, ^{
|
||||
if (!AppReadiness.isAppReady) {
|
||||
// We don't want to process incoming messages until storage is ready.
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[self drainQueue];
|
||||
}];
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -206,6 +206,12 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
|
|||
{
|
||||
if (!AppReadiness.isAppReady) {
|
||||
DDLogInfo(@"%@ Deferring read receipt processing; storage not yet ready.", self.logTag);
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[self scheduleProcessing];
|
||||
}];
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (self.isProcessing) {
|
||||
|
|
|
@ -610,6 +610,12 @@ NSString *const kNSNotification_SocketManagerStateDidChange = @"kNSNotification_
|
|||
OWSAssertIsOnMainThread();
|
||||
|
||||
if (!AppReadiness.isAppReady) {
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[self applyDesiredSocketState];
|
||||
}];
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -94,10 +94,12 @@ NSString *const AppIsReadyNotification = @"AppIsReadyNotification";
|
|||
OWSAssertIsOnMainThread();
|
||||
OWSAssert(self.isAppReady);
|
||||
|
||||
for (AppReadyBlock block in self.appReadyBlocks) {
|
||||
// Make a local copy, then clear this state.
|
||||
NSArray<AppReadyBlock> *appReadyBlocks = self.appReadyBlocks;
|
||||
self.appReadyBlocks = nil;
|
||||
for (AppReadyBlock block in appReadyBlocks) {
|
||||
block();
|
||||
}
|
||||
self.appReadyBlocks = nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in New Issue