mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
[DEBUG-UI] create fake contact threads
// FREEBIE
This commit is contained in:
parent
bdd31fc772
commit
092578045e
3 changed files with 52 additions and 2 deletions
|
@ -7,9 +7,14 @@
|
|||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class OWSTableSection;
|
||||
@class CNContact;
|
||||
|
||||
@interface DebugUIContacts : DebugUIPage
|
||||
|
||||
+ (void)createRandomContacts:(NSUInteger)count
|
||||
contactHandler:
|
||||
(nullable void (^)(CNContact *_Nonnull contact, NSUInteger idx, BOOL *_Nonnull stop))contactHandler;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
|
@ -1137,13 +1137,20 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
+ (void)createRandomContacts:(int)count
|
||||
{
|
||||
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];
|
||||
if (status == CNAuthorizationStatusDenied || status == CNAuthorizationStatusRestricted) {
|
||||
[OWSAlerts showAlertWithTitle:@"Error" message:@"No contacts access."];
|
||||
return;
|
||||
}
|
||||
|
||||
NSMutableArray<CNContact *> *contacts = [NSMutableArray new];
|
||||
CNContactStore *store = [[CNContactStore alloc] init];
|
||||
[store
|
||||
requestAccessForEntityType:CNEntityTypeContacts
|
||||
|
@ -1166,12 +1173,17 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
value:[CNPhoneNumber phoneNumberWithStringValue:[self randomPhoneNumber]]];
|
||||
contact.phoneNumbers = @[ homePhone ];
|
||||
|
||||
[contacts addObject:contact];
|
||||
[request addContact:contact toContainerWithIdentifier:nil];
|
||||
}
|
||||
NSError *saveError = nil;
|
||||
if (![store executeSaveRequest:request error:&saveError]) {
|
||||
NSLog(@"error = %@", saveError);
|
||||
[OWSAlerts showAlertWithTitle:@"Error" message:saveError.localizedDescription];
|
||||
} else {
|
||||
if (contactHandler) {
|
||||
[contacts enumerateObjectsUsingBlock:contactHandler];
|
||||
}
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
//
|
||||
|
||||
#import "DebugUIMessages.h"
|
||||
#import "DebugUIContacts.h"
|
||||
#import "Environment.h"
|
||||
#import "OWSTableViewController.h"
|
||||
#import "Signal-Swift.h"
|
||||
|
@ -82,6 +83,22 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
actionBlock:^{
|
||||
[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"
|
||||
actionBlock:^{
|
||||
[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:^(
|
||||
YapDatabaseReadWriteTransaction *transaction) {
|
||||
for (int i = 0; i < counter; i++) {
|
||||
for (NSUInteger i = 0; i < counter; i++) {
|
||||
NSString *randomText = [self randomText];
|
||||
switch (arc4random_uniform(4)) {
|
||||
case 0: {
|
||||
|
|
Loading…
Reference in a new issue