Only dispatch async at top level.

Previously each method was dispatching it's callbacks async. This is a
waste of code, processing, and makes crash logs impenetrable.

// FREEBIE
pull/1/head
Michael Kirk 9 years ago
parent b4c504f61d
commit 027fa10730

@ -8,7 +8,7 @@
Pod::Spec.new do |s|
s.name = "SignalServiceKit"
s.version = "0.5.0"
s.version = "0.5.1"
s.summary = "An Objective-C library for communicating with the Signal messaging service."
s.description = <<-DESC

@ -3,6 +3,8 @@
#import "SignalRecipient.h"
NS_ASSUME_NONNULL_BEGIN
@class Contact;
@interface ContactsUpdater : NSObject
@ -21,3 +23,5 @@
success:(void (^)())success
failure:(void (^)(NSError *error))failure;
@end
NS_ASSUME_NONNULL_END

@ -11,6 +11,8 @@
#import "TSNetworkManager.h"
#import "TSStorageManager.h"
NS_ASSUME_NONNULL_BEGIN
@implementation ContactsUpdater
+ (instancetype)sharedUpdater {
@ -50,20 +52,12 @@
success:(void (^)(NSSet<NSString *> *matchedIds))success
failure:(void (^)(NSError *error))failure
{
if(!identifier) {
NSError *error
= OWSErrorWithCodeDescription(OWSErrorCodeInvalidMethodParameters, @"Cannot lookup nil identifier");
BLOCK_SAFE_RUN(failure, error);
if (!identifier) {
failure(OWSErrorWithCodeDescription(OWSErrorCodeInvalidMethodParameters, @"Cannot lookup nil identifier"));
return;
}
[self contactIntersectionWithSet:[NSSet setWithObject:identifier]
success:^(NSSet<NSString *> *matchedIds) {
BLOCK_SAFE_RUN(success, matchedIds);
}
failure:^(NSError *error) {
BLOCK_SAFE_RUN(failure, error);
}];
[self contactIntersectionWithSet:[NSSet setWithObject:identifier] success:success failure:failure];
}
- (void)updateSignalContactIntersectionWithABContacts:(NSArray<Contact *> *)abContacts
@ -77,7 +71,7 @@
}
}
__block NSMutableSet *recipientIds = [NSMutableSet set];
NSMutableSet *recipientIds = [NSMutableSet set];
[[TSStorageManager sharedManager]
.dbConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) {
NSArray *allRecipientKeys = [transaction allKeysInCollection:[SignalRecipient collection]];
@ -87,24 +81,25 @@
NSMutableSet<NSString *> *allContacts = [[abPhoneNumbers setByAddingObjectsFromSet:recipientIds] mutableCopy];
[self contactIntersectionWithSet:allContacts
success:^(NSSet<NSString *> *matchedIds) {
[recipientIds minusSet:matchedIds];
// Cleaning up unregistered identifiers
[[TSStorageManager sharedManager]
.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
for (NSString *identifier in recipientIds) {
SignalRecipient *recipient =
[SignalRecipient fetchObjectWithUniqueID:identifier transaction:transaction];
[recipient removeWithTransaction:transaction];
}
}];
BLOCK_SAFE_RUN(success);
}
failure:^(NSError *error) {
BLOCK_SAFE_RUN(failure, error);
}];
success:^(NSSet<NSString *> *matchedIds) {
[recipientIds minusSet:matchedIds];
// Cleaning up unregistered identifiers
[[TSStorageManager sharedManager].dbConnection
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
for (NSString *identifier in recipientIds) {
SignalRecipient *recipient =
[SignalRecipient fetchObjectWithUniqueID:identifier
transaction:transaction];
[recipient removeWithTransaction:transaction];
}
}];
DDLogInfo(@"%@ successfully intersected contacts.", self.tag);
success();
}
failure:failure];
}
- (void)contactIntersectionWithSet:(NSSet<NSString *> *)idSet
@ -131,7 +126,7 @@
NSString *identifier = [phoneNumbersByHashes objectForKey:hash];
if (!identifier) {
DDLogWarn(@"An interesecting hash wasn't found in the mapping.");
DDLogWarn(@"%@ An interesecting hash wasn't found in the mapping.", self.tag);
break;
}
@ -170,12 +165,26 @@
}
}];
BLOCK_SAFE_RUN(success, [NSSet setWithArray:attributesForIdentifier.allKeys]);
success([NSSet setWithArray:attributesForIdentifier.allKeys]);
}
failure:^(NSURLSessionDataTask *task, NSError *error) {
BLOCK_SAFE_RUN(failure, error);
failure(error);
}];
});
}
#pragma mark - Logging
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
- (NSString *)tag
{
return self.class.tag;
}
@end
NS_ASSUME_NONNULL_END

@ -35,7 +35,7 @@ NS_ASSUME_NONNULL_BEGIN
success:^(NSSet<NSString *> *matchedIds) {
}
failure:^(NSError *error) {
DDLogInfo(@"Failed to retreive call status. Will be retreived on next contact intersection.");
DDLogWarn(@"Failed to lookup contact with error:%@", error);
}];
[recipient saveWithTransaction:transaction];
}

Loading…
Cancel
Save