|
|
|
@ -10,6 +10,7 @@
|
|
|
|
|
#import "SSKEnvironment.h"
|
|
|
|
|
#import "TSContactThread.h"
|
|
|
|
|
#import "TSYapDatabaseObject.h"
|
|
|
|
|
#import <Reachability/Reachability.h>
|
|
|
|
|
#import <SignalServiceKit/SignalServiceKit-Swift.h>
|
|
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
@ -20,6 +21,8 @@ NSString *const kDeliveryReceiptManagerCollection = @"kDeliveryReceiptManagerCol
|
|
|
|
|
|
|
|
|
|
@property (nonatomic, readonly) YapDatabaseConnection *dbConnection;
|
|
|
|
|
|
|
|
|
|
@property (nonatomic) Reachability *reachability;
|
|
|
|
|
|
|
|
|
|
// Should only be accessed on the serialQueue.
|
|
|
|
|
@property (nonatomic) BOOL isProcessing;
|
|
|
|
|
|
|
|
|
@ -42,10 +45,17 @@ NSString *const kDeliveryReceiptManagerCollection = @"kDeliveryReceiptManagerCol
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.reachability = [Reachability reachabilityForInternetConnection];
|
|
|
|
|
|
|
|
|
|
_dbConnection = primaryStorage.newDatabaseConnection;
|
|
|
|
|
|
|
|
|
|
OWSSingletonAssert();
|
|
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
|
selector:@selector(reachabilityChanged)
|
|
|
|
|
name:kReachabilityChangedNotification
|
|
|
|
|
object:nil];
|
|
|
|
|
|
|
|
|
|
// Start processing.
|
|
|
|
|
[AppReadiness runNowOrWhenAppIsReady:^{
|
|
|
|
|
[self scheduleProcessing];
|
|
|
|
@ -96,6 +106,12 @@ NSString *const kDeliveryReceiptManagerCollection = @"kDeliveryReceiptManagerCol
|
|
|
|
|
- (void)process {
|
|
|
|
|
OWSLogVerbose(@"Processing outbound delivery receipts.");
|
|
|
|
|
|
|
|
|
|
if (!self.reachability.isReachable) {
|
|
|
|
|
// No network availability; abort.
|
|
|
|
|
self.isProcessing = NO;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NSMutableDictionary<NSString *, NSSet<NSNumber *> *> *deliveryReceiptMap = [NSMutableDictionary new];
|
|
|
|
|
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
|
|
|
|
[transaction enumerateKeysAndObjectsInCollection:kDeliveryReceiptManagerCollection
|
|
|
|
@ -221,6 +237,12 @@ NSString *const kDeliveryReceiptManagerCollection = @"kDeliveryReceiptManagerCol
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)reachabilityChanged {
|
|
|
|
|
OWSAssertIsOnMainThread();
|
|
|
|
|
|
|
|
|
|
[self scheduleProcessing];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|
|
|
|
|