From d8d3f3607005f3ee31571884ca0954e513decebe Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 7 Sep 2017 15:27:08 -0400 Subject: [PATCH 1/2] 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 1cba89339d..bfa13e8f40 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 From 0c281cab9506ae65a4ece507058fc60b0817424a Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 7 Sep 2017 15:33:12 -0400 Subject: [PATCH 2/2] Add "log user profiles" debug UI action. // FREEBIE --- Signal/src/Profiles/OWSProfileManager.h | 3 +++ Signal/src/Profiles/OWSProfileManager.m | 26 +++++++++++++++++++ .../DebugUI/DebugUIProfile.swift | 9 ++++--- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/Signal/src/Profiles/OWSProfileManager.h b/Signal/src/Profiles/OWSProfileManager.h index 4f6982dfcb..a6f8d42a5a 100644 --- a/Signal/src/Profiles/OWSProfileManager.h +++ b/Signal/src/Profiles/OWSProfileManager.h @@ -71,6 +71,9 @@ extern const NSUInteger kOWSProfileManager_MaxAvatarDiameter; #pragma mark - Other User's Profiles +// This method is for debugging. +- (void)logUserProfiles; + - (nullable OWSAES256Key *)profileKeyForRecipientId:(NSString *)recipientId; - (nullable NSString *)profileNameForRecipientId:(NSString *)recipientId; diff --git a/Signal/src/Profiles/OWSProfileManager.m b/Signal/src/Profiles/OWSProfileManager.m index 0ce053fcea..7fb262e736 100644 --- a/Signal/src/Profiles/OWSProfileManager.m +++ b/Signal/src/Profiles/OWSProfileManager.m @@ -934,6 +934,32 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640; #pragma mark - Other User's Profiles +- (void)logUserProfiles +{ + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + @synchronized(self) + { + DDLogError(@"logUserProfiles: %zd", [self.dbConnection numberOfKeysInCollection:UserProfile.collection]); + [self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { + [transaction + enumerateKeysAndObjectsInCollection:UserProfile.collection + usingBlock:^( + NSString *_Nonnull key, id _Nonnull object, BOOL *_Nonnull stop) { + OWSAssert([object isKindOfClass:[UserProfile class]]); + UserProfile *userProfile = object; + DDLogError(@"\t [%@]: has profile key: %d, has avatar URL: %d, has " + @"avatar file: %d, name: %@", + userProfile.recipientId, + userProfile.profileKey != nil, + userProfile.avatarUrlPath != nil, + userProfile.avatarFileName != nil, + userProfile.profileName); + }]; + }]; + } + }); +} + - (void)setProfileKeyData:(NSData *)profileKeyData forRecipientId:(NSString *)recipientId; { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIProfile.swift b/Signal/src/ViewControllers/DebugUI/DebugUIProfile.swift index 27011a500f..eade8157b5 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIProfile.swift +++ b/Signal/src/ViewControllers/DebugUI/DebugUIProfile.swift @@ -31,15 +31,18 @@ class DebugUIProfile: DebugUIPage { OWSTableItem(title: "Log Profile Whitelist") { self.profileManager.logProfileWhitelist() }, + OWSTableItem(title: "Log User Profiles") { + self.profileManager.logUserProfiles() + }, OWSTableItem(title: "Regenerate Profile/ProfileKey") { self.profileManager.regenerateLocalProfile() }, - OWSTableItem(title: "Send profile key message.") { + OWSTableItem(title: "Send Profile Key Message") { let message = OWSProfileKeyMessage(timestamp: NSDate.ows_millisecondTimeStamp(), in: aThread) self.messageSender.sendPromise(message: message).then { Logger.info("Successfully sent profile key message to thread: \(String(describing: aThread))") - }.catch { _ in - owsFail("Failed to send profile key message to thread: \(String(describing: aThread))") + }.catch { _ in + owsFail("Failed to send profile key message to thread: \(String(describing: aThread))") } } ]