mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Fix fake contacts.
// FREEBIE
This commit is contained in:
parent
a35a21d5cc
commit
94daccc78e
|
@ -172,7 +172,7 @@
|
||||||
[weakSelf showAbout];
|
[weakSelf showAbout];
|
||||||
}]];
|
}]];
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef USE_DEBUG_UI
|
||||||
[section addItem:[OWSTableItem disclosureItemWithText:@"Debug UI"
|
[section addItem:[OWSTableItem disclosureItemWithText:@"Debug UI"
|
||||||
actionBlock:^{
|
actionBlock:^{
|
||||||
[weakSelf showDebugUI];
|
[weakSelf showDebugUI];
|
||||||
|
|
|
@ -1221,7 +1221,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
|
||||||
[self.navigationBarTitleView
|
[self.navigationBarTitleView
|
||||||
addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self
|
addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self
|
||||||
action:@selector(navigationTitleTapped:)]];
|
action:@selector(navigationTitleTapped:)]];
|
||||||
#ifdef DEBUG
|
#ifdef USE_DEBUG_UI
|
||||||
[self.navigationBarTitleView addGestureRecognizer:[[UILongPressGestureRecognizer alloc]
|
[self.navigationBarTitleView addGestureRecognizer:[[UILongPressGestureRecognizer alloc]
|
||||||
initWithTarget:self
|
initWithTarget:self
|
||||||
action:@selector(navigationTitleLongPressed:)]];
|
action:@selector(navigationTitleLongPressed:)]];
|
||||||
|
@ -4148,7 +4148,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef USE_DEBUG_UI
|
||||||
- (void)navigationTitleLongPressed:(UIGestureRecognizer *)gestureRecognizer
|
- (void)navigationTitleLongPressed:(UIGestureRecognizer *)gestureRecognizer
|
||||||
{
|
{
|
||||||
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
|
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
|
||||||
|
|
|
@ -1150,10 +1150,12 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
NSUInteger batch = MIN(kMaxBatchSize, remainder);
|
NSUInteger batch = MIN(kMaxBatchSize, remainder);
|
||||||
remainder -= batch;
|
remainder -= batch;
|
||||||
[self createRandomContactsBatch:batch
|
[self createRandomContactsBatch:batch
|
||||||
contactHandler:nil
|
contactHandler:contactHandler
|
||||||
batchCompletionHandler:^{
|
batchCompletionHandler:^{
|
||||||
if (remainder > 0) {
|
if (remainder > 0) {
|
||||||
[self createRandomContacts:remainder contactHandler:contactHandler];
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[self createRandomContacts:remainder contactHandler:contactHandler];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
@ -1188,39 +1190,44 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
CNSaveRequest *request = [[CNSaveRequest alloc] init];
|
CNSaveRequest *request = [[CNSaveRequest alloc] init];
|
||||||
for (NSUInteger i = 0; i < count; i++) {
|
for (NSUInteger i = 0; i < count; i++) {
|
||||||
CNMutableContact *contact = [[CNMutableContact alloc] init];
|
@autoreleasepool {
|
||||||
contact.familyName = [@"Rando-" stringByAppendingString:[self randomLastName]];
|
CNMutableContact *contact = [[CNMutableContact alloc] init];
|
||||||
contact.givenName = [self randomFirstName];
|
contact.familyName = [@"Rando-" stringByAppendingString:[self randomLastName]];
|
||||||
|
contact.givenName = [self randomFirstName];
|
||||||
|
|
||||||
NSString *phoneString = [self randomPhoneNumber];
|
NSString *phoneString = [self randomPhoneNumber];
|
||||||
CNLabeledValue *homePhone = [CNLabeledValue
|
CNLabeledValue *homePhone = [CNLabeledValue
|
||||||
labeledValueWithLabel:CNLabelHome
|
labeledValueWithLabel:CNLabelHome
|
||||||
value:[CNPhoneNumber phoneNumberWithStringValue:phoneString]];
|
value:[CNPhoneNumber phoneNumberWithStringValue:phoneString]];
|
||||||
contact.phoneNumbers = @[ homePhone ];
|
contact.phoneNumbers = @[ homePhone ];
|
||||||
|
|
||||||
// 50% chance of fake contact having an avatar
|
// 50% chance of fake contact having an avatar
|
||||||
const NSUInteger kPercentWithAvatar = 50;
|
const NSUInteger kPercentWithAvatar = 50;
|
||||||
const NSUInteger kMinimumAvatarDiameter = 200;
|
const NSUInteger kMinimumAvatarDiameter = 200;
|
||||||
const NSUInteger kMaximumAvatarDiameter = 800;
|
const NSUInteger kMaximumAvatarDiameter = 800;
|
||||||
OWSAssert(kMaximumAvatarDiameter >= kMinimumAvatarDiameter);
|
OWSAssert(kMaximumAvatarDiameter >= kMinimumAvatarDiameter);
|
||||||
if (arc4random_uniform(100) < kPercentWithAvatar) {
|
if (arc4random_uniform(100) < kPercentWithAvatar) {
|
||||||
NSUInteger avatarDiameter
|
NSUInteger avatarDiameter
|
||||||
= arc4random_uniform(kMaximumAvatarDiameter - kMinimumAvatarDiameter)
|
= arc4random_uniform(kMaximumAvatarDiameter - kMinimumAvatarDiameter)
|
||||||
+ kMinimumAvatarDiameter;
|
+ kMinimumAvatarDiameter;
|
||||||
// Note this doesn't work on iOS9, since iOS9 doesn't generate the imageThumbnailData from
|
// Note this doesn't work on iOS9, since iOS9 doesn't generate the imageThumbnailData
|
||||||
// programmatically assigned imageData. We could make our own thumbnail in Contact.m, but
|
// from programmatically assigned imageData. We could make our own thumbnail in
|
||||||
// it's not worth it for the sake of debug UI.
|
// Contact.m, but it's not worth it for the sake of debug UI.
|
||||||
contact.imageData = UIImageJPEGRepresentation(
|
contact.imageData = UIImageJPEGRepresentation(
|
||||||
[OWSAvatarBuilder buildRandomAvatarWithDiameter:avatarDiameter], (CGFloat)0.9);
|
[OWSAvatarBuilder buildRandomAvatarWithDiameter:avatarDiameter], (CGFloat)0.9);
|
||||||
DDLogDebug(@"avatar size: %lu bytes", (unsigned long)contact.imageData.length);
|
DDLogDebug(@"avatar size: %lu bytes", (unsigned long)contact.imageData.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
[contacts addObject:contact];
|
||||||
|
[request addContact:contact toContainerWithIdentifier:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
[contacts addObject:contact];
|
|
||||||
[request addContact:contact toContainerWithIdentifier:nil];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DDLogError(@"Saving fake contacts: %zd", contacts.count);
|
||||||
|
|
||||||
NSError *saveError = nil;
|
NSError *saveError = nil;
|
||||||
if (![store executeSaveRequest:request error:&saveError]) {
|
if (![store executeSaveRequest:request error:&saveError]) {
|
||||||
NSLog(@"error = %@", saveError);
|
DDLogError(@"Error saving fake contacts: %@", saveError);
|
||||||
[OWSAlerts showAlertWithTitle:@"Error" message:saveError.localizedDescription];
|
[OWSAlerts showAlertWithTitle:@"Error" message:saveError.localizedDescription];
|
||||||
} else {
|
} else {
|
||||||
if (contactHandler) {
|
if (contactHandler) {
|
||||||
|
@ -1270,10 +1277,10 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
NSError *saveError = nil;
|
NSError *saveError = nil;
|
||||||
if (!result || fetchError) {
|
if (!result || fetchError) {
|
||||||
NSLog(@"error = %@", fetchError);
|
DDLogError(@"error = %@", fetchError);
|
||||||
[OWSAlerts showAlertWithTitle:@"Error" message:fetchError.localizedDescription];
|
[OWSAlerts showAlertWithTitle:@"Error" message:fetchError.localizedDescription];
|
||||||
} else if (![store executeSaveRequest:request error:&saveError]) {
|
} else if (![store executeSaveRequest:request error:&saveError]) {
|
||||||
NSLog(@"error = %@", saveError);
|
DDLogError(@"error = %@", saveError);
|
||||||
[OWSAlerts showAlertWithTitle:@"Error" message:saveError.localizedDescription];
|
[OWSAlerts showAlertWithTitle:@"Error" message:saveError.localizedDescription];
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
|
|
|
@ -85,6 +85,10 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
actionBlock:^{
|
actionBlock:^{
|
||||||
[DebugUIMessages sendFakeMessages:10 thread:thread];
|
[DebugUIMessages sendFakeMessages:10 thread:thread];
|
||||||
}],
|
}],
|
||||||
|
[OWSTableItem itemWithTitle:@"Create 1 fake thread with 1 message"
|
||||||
|
actionBlock:^{
|
||||||
|
[DebugUIMessages createFakeThreads:1 withFakeMessages:1];
|
||||||
|
}],
|
||||||
[OWSTableItem itemWithTitle:@"Create 100 fake threads with 10 messages"
|
[OWSTableItem itemWithTitle:@"Create 100 fake threads with 10 messages"
|
||||||
actionBlock:^{
|
actionBlock:^{
|
||||||
[DebugUIMessages createFakeThreads:100 withFakeMessages:10];
|
[DebugUIMessages createFakeThreads:100 withFakeMessages:10];
|
||||||
|
@ -887,6 +891,9 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
TSContactThread *contactThread = [TSContactThread getOrCreateThreadWithContactId:phoneNumber.toE164];
|
TSContactThread *contactThread = [TSContactThread getOrCreateThreadWithContactId:phoneNumber.toE164];
|
||||||
[self sendFakeMessages:messageCount thread:contactThread];
|
[self sendFakeMessages:messageCount thread:contactThread];
|
||||||
|
DDLogError(@"Create fake thread: %@, interactions: %zd",
|
||||||
|
phoneNumber.toE164,
|
||||||
|
contactThread.numberOfInteractions);
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,13 @@
|
||||||
|
|
||||||
#import "DebugUIPage.h"
|
#import "DebugUIPage.h"
|
||||||
|
|
||||||
|
// This preprocessor symbol controls whether or not the Debug UI is active.
|
||||||
|
//
|
||||||
|
// To show the DebugUI in production builds, comment out the #ifdef and #endif
|
||||||
|
#ifdef DEBUG
|
||||||
|
#define USE_DEBUG_UI
|
||||||
|
#endif
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@class OWSTableSection;
|
@class OWSTableSection;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#import "DebugUIPage.h"
|
||||||
#import "OWSTableViewController.h"
|
#import "OWSTableViewController.h"
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
Loading…
Reference in a new issue