|  |  | @ -225,6 +225,7 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo | 
			
		
	
		
		
			
				
					
					|  |  |  | @property (nonatomic, readonly) YapDatabaseConnection *dbConnection; |  |  |  | @property (nonatomic, readonly) YapDatabaseConnection *dbConnection; | 
			
		
	
		
		
			
				
					
					|  |  |  | @property (nonatomic, readonly) OWSMessageContentJobFinder *finder; |  |  |  | @property (nonatomic, readonly) OWSMessageContentJobFinder *finder; | 
			
		
	
		
		
			
				
					
					|  |  |  | @property (nonatomic) BOOL isDrainingQueue; |  |  |  | @property (nonatomic) BOOL isDrainingQueue; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | @property (atomic) BOOL isAppInBackground; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | - (instancetype)initWithMessagesManager:(OWSMessageManager *)messagesManager |  |  |  | - (instancetype)initWithMessagesManager:(OWSMessageManager *)messagesManager | 
			
		
	
		
		
			
				
					
					|  |  |  |                          primaryStorage:(OWSPrimaryStorage *)primaryStorage |  |  |  |                          primaryStorage:(OWSPrimaryStorage *)primaryStorage | 
			
		
	
	
		
		
			
				
					|  |  | @ -253,6 +254,15 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo | 
			
		
	
		
		
			
				
					
					|  |  |  |     _finder = finder; |  |  |  |     _finder = finder; | 
			
		
	
		
		
			
				
					
					|  |  |  |     _isDrainingQueue = NO; |  |  |  |     _isDrainingQueue = NO; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     [[NSNotificationCenter defaultCenter] addObserver:self | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                              selector:@selector(applicationWillEnterForeground:) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                                  name:OWSApplicationWillEnterForegroundNotification | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                                object:nil]; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     [[NSNotificationCenter defaultCenter] addObserver:self | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                              selector:@selector(applicationDidEnterBackground:) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                                  name:OWSApplicationDidEnterBackgroundNotification | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                                object:nil]; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     // Start processing. |  |  |  |     // Start processing. | 
			
		
	
		
		
			
				
					
					|  |  |  |     [AppReadiness runNowOrWhenAppIsReady:^{ |  |  |  |     [AppReadiness runNowOrWhenAppIsReady:^{ | 
			
		
	
		
		
			
				
					
					|  |  |  |         [self drainQueue]; |  |  |  |         [self drainQueue]; | 
			
		
	
	
		
		
			
				
					|  |  | @ -261,6 +271,23 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo | 
			
		
	
		
		
			
				
					
					|  |  |  |     return self; |  |  |  |     return self; | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | - (void)dealloc | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     [[NSNotificationCenter defaultCenter] removeObserver:self]; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | #pragma mark - Notifications | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | - (void)applicationWillEnterForeground:(NSNotification *)notification | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     self.isAppInBackground = NO; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | - (void)applicationDidEnterBackground:(NSNotification *)notification | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     self.isAppInBackground = YES; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | #pragma mark - instance methods |  |  |  | #pragma mark - instance methods | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | - (dispatch_queue_t)serialQueue |  |  |  | - (dispatch_queue_t)serialQueue | 
			
		
	
	
		
		
			
				
					|  |  | @ -353,7 +380,7 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo | 
			
		
	
		
		
			
				
					
					|  |  |  |                                       transaction:transaction]; |  |  |  |                                       transaction:transaction]; | 
			
		
	
		
		
			
				
					
					|  |  |  |             [processedJobs addObject:job]; |  |  |  |             [processedJobs addObject:job]; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (CurrentAppContext().isInBackground) { |  |  |  |             if (self.isAppInBackground) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 // If the app is in the background, stop processing this batch. |  |  |  |                 // If the app is in the background, stop processing this batch. | 
			
		
	
		
		
			
				
					
					|  |  |  |                 // |  |  |  |                 // | 
			
		
	
		
		
			
				
					
					|  |  |  |                 // Since this check is done after processing jobs, we'll continue |  |  |  |                 // Since this check is done after processing jobs, we'll continue | 
			
		
	
	
		
		
			
				
					|  |  | 
 |