Merge branch 'charlesmchen/backgroundEdgeCases' into hotfix/2.20.1

pull/1/head
Matthew Chen 7 years ago
commit a471cc32b9

@ -8,6 +8,7 @@
#import "ContactsManagerProtocol.h" #import "ContactsManagerProtocol.h"
#import "NSDate+OWS.h" #import "NSDate+OWS.h"
#import "NSTimer+OWS.h" #import "NSTimer+OWS.h"
#import "OWSBackgroundTask.h"
#import "OWSDisappearingConfigurationUpdateInfoMessage.h" #import "OWSDisappearingConfigurationUpdateInfoMessage.h"
#import "OWSDisappearingMessagesConfiguration.h" #import "OWSDisappearingMessagesConfiguration.h"
#import "OWSDisappearingMessagesFinder.h" #import "OWSDisappearingMessagesFinder.h"
@ -88,6 +89,8 @@ NS_ASSUME_NONNULL_BEGIN
{ {
uint64_t now = [NSDate ows_millisecondTimeStamp]; uint64_t now = [NSDate ows_millisecondTimeStamp];
OWSBackgroundTask *_Nullable backgroundTask = [OWSBackgroundTask backgroundTaskWithLabelStr:__PRETTY_FUNCTION__];
__block uint expirationCount = 0; __block uint expirationCount = 0;
[self.databaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) { [self.databaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
[self.disappearingMessagesFinder enumerateExpiredMessagesWithBlock:^(TSMessage *message) { [self.disappearingMessagesFinder enumerateExpiredMessagesWithBlock:^(TSMessage *message) {
@ -106,6 +109,8 @@ NS_ASSUME_NONNULL_BEGIN
}]; }];
DDLogDebug(@"%@ Removed %u expired messages", self.logTag, expirationCount); DDLogDebug(@"%@ Removed %u expired messages", self.logTag, expirationCount);
backgroundTask = nil;
} }
// This method should only be called on the serialQueue. // This method should only be called on the serialQueue.
@ -203,6 +208,8 @@ NS_ASSUME_NONNULL_BEGIN
// This method should only be called on the serialQueue. // This method should only be called on the serialQueue.
- (void)setExpirationsForThread:(TSThread *)thread - (void)setExpirationsForThread:(TSThread *)thread
{ {
OWSBackgroundTask *_Nullable backgroundTask = [OWSBackgroundTask backgroundTaskWithLabelStr:__PRETTY_FUNCTION__];
uint64_t now = [NSDate ows_millisecondTimeStamp]; uint64_t now = [NSDate ows_millisecondTimeStamp];
[self.databaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) { [self.databaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
[self.disappearingMessagesFinder [self.disappearingMessagesFinder
@ -220,6 +227,8 @@ NS_ASSUME_NONNULL_BEGIN
} }
transaction:transaction]; transaction:transaction];
}]; }];
backgroundTask = nil;
} }
+ (void)becomeConsistentWithConfigurationForMessage:(TSMessage *)message + (void)becomeConsistentWithConfigurationForMessage:(TSMessage *)message
@ -234,6 +243,8 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(message); OWSAssert(message);
OWSAssert(contactsManager); OWSAssert(contactsManager);
OWSBackgroundTask *_Nullable backgroundTask = [OWSBackgroundTask backgroundTaskWithLabelStr:__PRETTY_FUNCTION__];
dispatch_async(OWSDisappearingMessagesJob.serialQueue, ^{ dispatch_async(OWSDisappearingMessagesJob.serialQueue, ^{
// Become eventually consistent in the case that the remote changed their settings at the same time. // Become eventually consistent in the case that the remote changed their settings at the same time.
// Also in case remote doesn't support expiring messages // Also in case remote doesn't support expiring messages
@ -280,6 +291,8 @@ NS_ASSUME_NONNULL_BEGIN
configuration:disappearingMessagesConfiguration] configuration:disappearingMessagesConfiguration]
save]; save];
} }
backgroundTask = nil;
}); });
} }

@ -350,16 +350,23 @@ typedef NSData *_Nullable (^CreateDatabaseMetadataBlock)(void);
+ (void)setupStorage + (void)setupStorage
{ {
__block OWSBackgroundTask *_Nullable backgroundTask =
[OWSBackgroundTask backgroundTaskWithLabelStr:__PRETTY_FUNCTION__];
for (OWSStorage *storage in self.allStorages) { for (OWSStorage *storage in self.allStorages) {
[storage runSyncRegistrations]; [storage runSyncRegistrations];
} }
for (OWSStorage *storage in self.allStorages) { for (OWSStorage *storage in self.allStorages) {
[storage runAsyncRegistrationsWithCompletion:^{ [storage runAsyncRegistrationsWithCompletion:^{
if ([self postRegistrationCompleteNotificationIfPossible]) {
// If all registrations are complete, clean up the
// registration process.
[self postRegistrationCompleteNotificationIfPossible]; ((OWSDatabase *)storage.database).registrationConnectionCached = nil;
((OWSDatabase *)storage.database).registrationConnectionCached = nil; backgroundTask = nil;
}
}]; }];
} }
} }
@ -369,10 +376,11 @@ typedef NSData *_Nullable (^CreateDatabaseMetadataBlock)(void);
return self.database.registrationConnection; return self.database.registrationConnection;
} }
+ (void)postRegistrationCompleteNotificationIfPossible // Returns YES IFF all registrations are complete.
+ (BOOL)postRegistrationCompleteNotificationIfPossible
{ {
if (!self.isStorageReady) { if (!self.isStorageReady) {
return; return NO;
} }
static dispatch_once_t onceToken; static dispatch_once_t onceToken;
@ -381,6 +389,8 @@ typedef NSData *_Nullable (^CreateDatabaseMetadataBlock)(void);
object:nil object:nil
userInfo:nil]; userInfo:nil];
}); });
return YES;
} }
+ (BOOL)isStorageReady + (BOOL)isStorageReady

Loading…
Cancel
Save