From d8d3f3607005f3ee31571884ca0954e513decebe Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 7 Sep 2017 15:27:08 -0400 Subject: [PATCH] Add "delete all contacts" debug UI action. // FREEBIE --- .../ViewControllers/DebugUI/DebugUIContacts.m | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIContacts.m b/Signal/src/ViewControllers/DebugUI/DebugUIContacts.m index 1cba89339..bfa13e8f4 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIContacts.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUIContacts.m @@ -54,6 +54,10 @@ NS_ASSUME_NONNULL_BEGIN actionBlock:^{ [DebugUIContacts deleteRandomContacts]; }], + [OWSTableItem itemWithTitle:@"Delete All Contacts" + actionBlock:^{ + [DebugUIContacts deleteAllContacts]; + }], ]]; } @@ -1240,8 +1244,10 @@ NS_ASSUME_NONNULL_BEGIN }]; } -+ (void)deleteRandomContacts ++ (void)deleteContactsWithFilter:(BOOL (^_Nonnull)(CNContact *contact))filterBlock { + OWSAssert(filterBlock); + CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts]; if (status == CNAuthorizationStatusDenied || status == CNAuthorizationStatusRestricted) { [OWSAlerts showAlertWithTitle:@"Error" message:@"No contacts access."]; @@ -1270,7 +1276,7 @@ NS_ASSUME_NONNULL_BEGIN [store enumerateContactsWithFetchRequest:fetchRequest error:&fetchError usingBlock:^(CNContact *contact, BOOL *stop) { - if ([contact.familyName hasPrefix:@"Rando-"]) { + if (filterBlock(contact)) { [request deleteContact:[contact mutableCopy]]; } }]; @@ -1286,6 +1292,20 @@ NS_ASSUME_NONNULL_BEGIN }]; } ++ (void)deleteAllContacts +{ + [self deleteContactsWithFilter:^(CNContact *contact) { + return YES; + }]; +} + ++ (void)deleteRandomContacts +{ + [self deleteContactsWithFilter:^(CNContact *contact) { + return [contact.familyName hasPrefix:@"Rando-"]; + }]; +} + @end NS_ASSUME_NONNULL_END