Lookup methods yield SignalRecipient (#102)

Let's us remove some otherwise redundant code to look up the recipient
from their ID.

// FREEBIE
pull/1/head
Michael Kirk 8 years ago committed by GitHub
parent 9fdbbb7f8b
commit 6521a80c44

@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN
// This asynchronously updates the SignalRecipient for a given contactId.
- (void)lookupIdentifier:(NSString *)identifier
success:(void (^)(NSSet<NSString *> *matchedIds))success
success:(void (^)(SignalRecipient *recipient))success
failure:(void (^)(NSError *error))failure;
- (void)updateSignalContactIntersectionWithABContacts:(NSArray<Contact *> *)abContacts

@ -1,5 +1,6 @@
// Created by Frederic Jacobs on 21/11/15.
// Copyright © 2015 Open Whisper Systems. All rights reserved.
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "ContactsUpdater.h"
@ -35,12 +36,8 @@ NS_ASSUME_NONNULL_BEGIN
// retained until our error parameter can take ownership.
__block NSError *retainedError;
[self lookupIdentifier:identifier
success:^(NSSet<NSString *> *matchedIds) {
if (matchedIds.count == 1) {
recipient = [SignalRecipient recipientWithTextSecureIdentifier:identifier];
} else {
retainedError = [NSError errorWithDomain:@"contactsmanager.notfound" code:NOTFOUND_ERROR userInfo:nil];
}
success:^(SignalRecipient *fetchedRecipient) {
recipient = fetchedRecipient;
dispatch_semaphore_signal(sema);
}
failure:^(NSError *lookupError) {
@ -53,17 +50,28 @@ NS_ASSUME_NONNULL_BEGIN
return recipient;
}
- (void)lookupIdentifier:(NSString *)identifier
success:(void (^)(NSSet<NSString *> *matchedIds))success
success:(void (^)(SignalRecipient *recipient))success
failure:(void (^)(NSError *error))failure
{
// This should never happen according to nullability annotations... but IIRC it does. =/
if (!identifier) {
OWSAssert(NO);
failure(OWSErrorWithCodeDescription(OWSErrorCodeInvalidMethodParameters, @"Cannot lookup nil identifier"));
return;
}
[self contactIntersectionWithSet:[NSSet setWithObject:identifier] success:success failure:failure];
[self contactIntersectionWithSet:[NSSet setWithObject:identifier]
success:^(NSSet<NSString *> *_Nonnull matchedIds) {
if (matchedIds.count == 1) {
success([SignalRecipient recipientWithTextSecureIdentifier:identifier]);
} else {
failure([NSError errorWithDomain:@"contactsmanager.notfound"
code:NOTFOUND_ERROR
userInfo:nil]);
}
}
failure:failure];
}
- (void)updateSignalContactIntersectionWithABContacts:(NSArray<Contact *> *)abContacts

@ -29,6 +29,7 @@ NS_ASSUME_NONNULL_BEGIN
transaction:(YapDatabaseReadWriteTransaction *)transaction
relay:(nullable NSString *)relay
{
OWSAssert(contactId);
SignalRecipient *recipient =
[SignalRecipient recipientWithTextSecureIdentifier:contactId withTransaction:transaction];
@ -43,8 +44,9 @@ NS_ASSUME_NONNULL_BEGIN
supportsWebRTC:NO];
[recipient saveWithTransaction:transaction];
// Update recipient with Server record async.
[[ContactsUpdater sharedUpdater] lookupIdentifier:contactId
success:^(NSSet<NSString *> *matchedIds) {
success:^(SignalRecipient *recipient) {
}
failure:^(NSError *error) {
DDLogWarn(@"Failed to lookup contact with error:%@", error);

Loading…
Cancel
Save