[DEBUG-UI] create fake contact threads

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent bdd31fc772
commit 092578045e

@ -7,9 +7,14 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@class OWSTableSection; @class OWSTableSection;
@class CNContact;
@interface DebugUIContacts : DebugUIPage @interface DebugUIContacts : DebugUIPage
+ (void)createRandomContacts:(NSUInteger)count
contactHandler:
(nullable void (^)(CNContact *_Nonnull contact, NSUInteger idx, BOOL *_Nonnull stop))contactHandler;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -1137,13 +1137,20 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)createRandomContacts:(int)count + (void)createRandomContacts:(int)count
{ {
OWSAssert(count > 0); OWSAssert(count > 0);
[self createRandomContacts:count contactHandler:nil];
}
+ (void)createRandomContacts:(NSUInteger)count
contactHandler:
(nullable void (^)(CNContact *_Nonnull contact, NSUInteger idx, BOOL *_Nonnull stop))contactHandler
{
CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts]; CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts];
if (status == CNAuthorizationStatusDenied || status == CNAuthorizationStatusRestricted) { if (status == CNAuthorizationStatusDenied || status == CNAuthorizationStatusRestricted) {
[OWSAlerts showAlertWithTitle:@"Error" message:@"No contacts access."]; [OWSAlerts showAlertWithTitle:@"Error" message:@"No contacts access."];
return; return;
} }
NSMutableArray<CNContact *> *contacts = [NSMutableArray new];
CNContactStore *store = [[CNContactStore alloc] init]; CNContactStore *store = [[CNContactStore alloc] init];
[store [store
requestAccessForEntityType:CNEntityTypeContacts requestAccessForEntityType:CNEntityTypeContacts
@ -1166,12 +1173,17 @@ NS_ASSUME_NONNULL_BEGIN
value:[CNPhoneNumber phoneNumberWithStringValue:[self randomPhoneNumber]]]; value:[CNPhoneNumber phoneNumberWithStringValue:[self randomPhoneNumber]]];
contact.phoneNumbers = @[ homePhone ]; contact.phoneNumbers = @[ homePhone ];
[contacts addObject:contact];
[request addContact:contact toContainerWithIdentifier:nil]; [request addContact:contact toContainerWithIdentifier:nil];
} }
NSError *saveError = nil; NSError *saveError = nil;
if (![store executeSaveRequest:request error:&saveError]) { if (![store executeSaveRequest:request error:&saveError]) {
NSLog(@"error = %@", saveError); NSLog(@"error = %@", saveError);
[OWSAlerts showAlertWithTitle:@"Error" message:saveError.localizedDescription]; [OWSAlerts showAlertWithTitle:@"Error" message:saveError.localizedDescription];
} else {
if (contactHandler) {
[contacts enumerateObjectsUsingBlock:contactHandler];
}
} }
}]; }];
} }

@ -3,6 +3,7 @@
// //
#import "DebugUIMessages.h" #import "DebugUIMessages.h"
#import "DebugUIContacts.h"
#import "Environment.h" #import "Environment.h"
#import "OWSTableViewController.h" #import "OWSTableViewController.h"
#import "Signal-Swift.h" #import "Signal-Swift.h"
@ -82,6 +83,22 @@ NS_ASSUME_NONNULL_BEGIN
actionBlock:^{ actionBlock:^{
[DebugUIMessages sendFakeMessages:10 thread:thread]; [DebugUIMessages sendFakeMessages:10 thread:thread];
}], }],
[OWSTableItem itemWithTitle:@"Create 100 fake threads with 10 messages"
actionBlock:^{
[DebugUIMessages createFakeThreads:100 withFakeMessages:10];
}],
[OWSTableItem itemWithTitle:@"Create 10 fake threads with 100 messages"
actionBlock:^{
[DebugUIMessages createFakeThreads:10 withFakeMessages:100];
}],
[OWSTableItem itemWithTitle:@"Create 10 fake threads with 10 messages"
actionBlock:^{
[DebugUIMessages createFakeThreads:10 withFakeMessages:10];
}],
[OWSTableItem itemWithTitle:@"Create 100 fake threads with 100 messages"
actionBlock:^{
[DebugUIMessages createFakeThreads:100 withFakeMessages:100];
}],
[OWSTableItem itemWithTitle:@"Create 1k fake messages" [OWSTableItem itemWithTitle:@"Create 1k fake messages"
actionBlock:^{ actionBlock:^{
[DebugUIMessages sendFakeMessages:1000 thread:thread]; [DebugUIMessages sendFakeMessages:1000 thread:thread];
@ -836,11 +853,27 @@ NS_ASSUME_NONNULL_BEGIN
}]; }];
} }
+ (void)sendFakeMessages:(int)counter thread:(TSThread *)thread + (void)createFakeThreads:(NSUInteger)threadCount withFakeMessages:(NSUInteger)messageCount
{
[DebugUIContacts
createRandomContacts:threadCount
contactHandler:^(CNContact *_Nonnull contact, NSUInteger idx, BOOL *_Nonnull stop) {
NSString *phoneNumberText = contact.phoneNumbers.firstObject.value.stringValue;
OWSAssert(phoneNumberText);
PhoneNumber *phoneNumber = [PhoneNumber tryParsePhoneNumberFromUserSpecifiedText:phoneNumberText];
OWSAssert(phoneNumber);
OWSAssert(phoneNumber.toE164);
TSContactThread *contactThread = [TSContactThread getOrCreateThreadWithContactId:phoneNumber.toE164];
[self sendFakeMessages:messageCount thread:contactThread];
}];
}
+ (void)sendFakeMessages:(NSUInteger)counter thread:(TSThread *)thread
{ {
[TSStorageManager.sharedManager.dbReadWriteConnection readWriteWithBlock:^( [TSStorageManager.sharedManager.dbReadWriteConnection readWriteWithBlock:^(
YapDatabaseReadWriteTransaction *transaction) { YapDatabaseReadWriteTransaction *transaction) {
for (int i = 0; i < counter; i++) { for (NSUInteger i = 0; i < counter; i++) {
NSString *randomText = [self randomText]; NSString *randomText = [self randomText];
switch (arc4random_uniform(4)) { switch (arc4random_uniform(4)) {
case 0: { case 0: {

Loading…
Cancel
Save