diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 8fa0d640b..ff8f1140b 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -36,7 +36,6 @@ 34B3F8771E8DF1700035BE1A /* ContactsPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F83E1E8DF1700035BE1A /* ContactsPicker.swift */; }; 34B3F8781E8DF1700035BE1A /* ContactsPicker.xib in Resources */ = {isa = PBXBuildFile; fileRef = 34B3F83F1E8DF1700035BE1A /* ContactsPicker.xib */; }; 34B3F8791E8DF1700035BE1A /* CountryCodeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F8411E8DF1700035BE1A /* CountryCodeViewController.m */; }; - 34B3F87A1E8DF1700035BE1A /* DebugUITableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F8431E8DF1700035BE1A /* DebugUITableViewController.m */; }; 34B3F87B1E8DF1700035BE1A /* ExperienceUpgradesPageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F8441E8DF1700035BE1A /* ExperienceUpgradesPageViewController.swift */; }; 34B3F87C1E8DF1700035BE1A /* FingerprintViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F8461E8DF1700035BE1A /* FingerprintViewController.m */; }; 34B3F87D1E8DF1700035BE1A /* FullImageViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F8481E8DF1700035BE1A /* FullImageViewController.m */; }; @@ -70,6 +69,9 @@ 34D5CC961EA6AFAD005515DB /* OWSContactsSyncing.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D5CC951EA6AFAD005515DB /* OWSContactsSyncing.m */; }; 34D5CCA91EAE3D30005515DB /* GroupViewHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D5CCA81EAE3D30005515DB /* GroupViewHelper.m */; }; 34D5CCB11EAE7E7F005515DB /* SelectRecipientViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D5CCB01EAE7E7F005515DB /* SelectRecipientViewController.m */; }; + 34D8C0271ED3673300188D7C /* DebugUIMessages.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D8C0241ED3673300188D7C /* DebugUIMessages.m */; }; + 34D8C0281ED3673300188D7C /* DebugUITableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D8C0261ED3673300188D7C /* DebugUITableViewController.m */; }; + 34D8C02B1ED3685800188D7C /* DebugUIContacts.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D8C02A1ED3685800188D7C /* DebugUIContacts.m */; }; 34DFCB851E8E04B500053165 /* AddToBlockListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34DFCB841E8E04B500053165 /* AddToBlockListViewController.m */; }; 34E3E5681EC4B19400495BAC /* AudioProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34E3E5671EC4B19400495BAC /* AudioProgressView.swift */; }; 34F3089C1ECA4CDB00BB7697 /* TSUnreadIndicatorInteraction.m in Sources */ = {isa = PBXBuildFile; fileRef = 34F3089B1ECA4CDB00BB7697 /* TSUnreadIndicatorInteraction.m */; }; @@ -409,8 +411,6 @@ 34B3F83F1E8DF1700035BE1A /* ContactsPicker.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ContactsPicker.xib; sourceTree = ""; }; 34B3F8401E8DF1700035BE1A /* CountryCodeViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CountryCodeViewController.h; sourceTree = ""; }; 34B3F8411E8DF1700035BE1A /* CountryCodeViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CountryCodeViewController.m; sourceTree = ""; }; - 34B3F8421E8DF1700035BE1A /* DebugUITableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DebugUITableViewController.h; sourceTree = ""; }; - 34B3F8431E8DF1700035BE1A /* DebugUITableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DebugUITableViewController.m; sourceTree = ""; }; 34B3F8441E8DF1700035BE1A /* ExperienceUpgradesPageViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExperienceUpgradesPageViewController.swift; sourceTree = ""; }; 34B3F8451E8DF1700035BE1A /* FingerprintViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FingerprintViewController.h; sourceTree = ""; }; 34B3F8461E8DF1700035BE1A /* FingerprintViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FingerprintViewController.m; sourceTree = ""; }; @@ -472,6 +472,12 @@ 34D5CCAB1EAE7136005515DB /* OWSConversationSettingsViewDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSConversationSettingsViewDelegate.h; sourceTree = ""; }; 34D5CCAF1EAE7E7F005515DB /* SelectRecipientViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SelectRecipientViewController.h; sourceTree = ""; }; 34D5CCB01EAE7E7F005515DB /* SelectRecipientViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SelectRecipientViewController.m; sourceTree = ""; }; + 34D8C0231ED3673300188D7C /* DebugUIMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DebugUIMessages.h; sourceTree = ""; }; + 34D8C0241ED3673300188D7C /* DebugUIMessages.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DebugUIMessages.m; sourceTree = ""; }; + 34D8C0251ED3673300188D7C /* DebugUITableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DebugUITableViewController.h; sourceTree = ""; }; + 34D8C0261ED3673300188D7C /* DebugUITableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DebugUITableViewController.m; sourceTree = ""; }; + 34D8C0291ED3685800188D7C /* DebugUIContacts.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DebugUIContacts.h; sourceTree = ""; }; + 34D8C02A1ED3685800188D7C /* DebugUIContacts.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DebugUIContacts.m; sourceTree = ""; }; 34DFCB831E8E04B400053165 /* AddToBlockListViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AddToBlockListViewController.h; sourceTree = ""; }; 34DFCB841E8E04B500053165 /* AddToBlockListViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AddToBlockListViewController.m; sourceTree = ""; }; 34E3E5671EC4B19400495BAC /* AudioProgressView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AudioProgressView.swift; sourceTree = ""; }; @@ -894,8 +900,7 @@ 340CB2231EAC155C0001CAA1 /* ContactsViewHelper.m */, 34B3F8401E8DF1700035BE1A /* CountryCodeViewController.h */, 34B3F8411E8DF1700035BE1A /* CountryCodeViewController.m */, - 34B3F8421E8DF1700035BE1A /* DebugUITableViewController.h */, - 34B3F8431E8DF1700035BE1A /* DebugUITableViewController.m */, + 34D8C0221ED3673300188D7C /* DebugUI */, 34B3F8441E8DF1700035BE1A /* ExperienceUpgradesPageViewController.swift */, 34B3F8451E8DF1700035BE1A /* FingerprintViewController.h */, 34B3F8461E8DF1700035BE1A /* FingerprintViewController.m */, @@ -990,6 +995,19 @@ path = TSMessageAdapters; sourceTree = ""; }; + 34D8C0221ED3673300188D7C /* DebugUI */ = { + isa = PBXGroup; + children = ( + 34D8C0291ED3685800188D7C /* DebugUIContacts.h */, + 34D8C02A1ED3685800188D7C /* DebugUIContacts.m */, + 34D8C0231ED3673300188D7C /* DebugUIMessages.h */, + 34D8C0241ED3673300188D7C /* DebugUIMessages.m */, + 34D8C0251ED3673300188D7C /* DebugUITableViewController.h */, + 34D8C0261ED3673300188D7C /* DebugUITableViewController.m */, + ); + path = DebugUI; + sourceTree = ""; + }; 4505C2BD1E648E6E00CEBF41 /* ExperienceUpgrades */ = { isa = PBXGroup; children = ( @@ -2021,6 +2039,7 @@ 76EB063E18170B33006006FC /* Operation.m in Sources */, 34B3F8741E8DF1700035BE1A /* AttachmentSharing.m in Sources */, A5509ECD1A69B1D600ABA4BC /* CountryCodeTableViewCell.m in Sources */, + 34D8C02B1ED3685800188D7C /* DebugUIContacts.m in Sources */, 45C9DEB81DF4E35A0065CA84 /* WebRTCCallMessageHandler.swift in Sources */, 34B3F88E1E8DF1700035BE1A /* PrivacySettingsTableViewController.m in Sources */, 34B3F8831E8DF1700035BE1A /* MessagesViewController.m in Sources */, @@ -2079,7 +2098,6 @@ 452EA09E1EA7ABE00078744B /* AttachmentPointerView.swift in Sources */, 45666EC91D994C0D008FE134 /* OWSGroupAvatarBuilder.m in Sources */, 3471B1DA1EB7C63600F6AEC8 /* NewNonContactConversationViewController.m in Sources */, - 34B3F87A1E8DF1700035BE1A /* DebugUITableViewController.m in Sources */, 34B3F87C1E8DF1700035BE1A /* FingerprintViewController.m in Sources */, 76EB058218170B33006006FC /* Environment.m in Sources */, 34B3F8921E8DF1710035BE1A /* SignalAttachment.swift in Sources */, @@ -2117,8 +2135,10 @@ 4517642B1DE939FD00EDB8B9 /* ContactCell.swift in Sources */, 450573FE1E78A06D00615BB4 /* OWS103EnableVideoCalling.m in Sources */, 34B3F8751E8DF1700035BE1A /* CallViewController.swift in Sources */, + 34D8C0281ED3673300188D7C /* DebugUITableViewController.m in Sources */, 34B3F8851E8DF1700035BE1A /* NewGroupViewController.m in Sources */, B6C93C4E199567AD00EDF894 /* DebugLogger.m in Sources */, + 34D8C0271ED3673300188D7C /* DebugUIMessages.m in Sources */, 34B3F8821E8DF1700035BE1A /* MessageComposeTableViewController.m in Sources */, 3453D8EA1EC0D4ED003F9E6F /* OWSAlerts.swift in Sources */, 45F659821E1BE77000444429 /* NonCallKitCallUIAdaptee.swift in Sources */, diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIContacts.h b/Signal/src/ViewControllers/DebugUI/DebugUIContacts.h new file mode 100644 index 000000000..d38584520 --- /dev/null +++ b/Signal/src/ViewControllers/DebugUI/DebugUIContacts.h @@ -0,0 +1,15 @@ +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// + +#import "OWSTableViewController.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface DebugUIContacts : NSObject + ++ (OWSTableSection *)section; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/DebugUITableViewController.m b/Signal/src/ViewControllers/DebugUI/DebugUIContacts.m similarity index 70% rename from Signal/src/ViewControllers/DebugUITableViewController.m rename to Signal/src/ViewControllers/DebugUI/DebugUIContacts.m index c284b69cf..91774b10d 100644 --- a/Signal/src/ViewControllers/DebugUITableViewController.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUIContacts.m @@ -2,16 +2,14 @@ // Copyright (c) 2017 Open Whisper Systems. All rights reserved. // -#import "DebugUITableViewController.h" -#import "Environment.h" +#import "DebugUIContacts.h" +#import "DebugUIMessages.h" #import "Signal-Swift.h" -#import "ThreadUtil.h" -#import -#import +#import NS_ASSUME_NONNULL_BEGIN -@implementation DebugUITableViewController +@implementation DebugUIContacts #pragma mark - Logging @@ -27,112 +25,24 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - Factory Methods -+ (void)presentDebugUIForThread:(TSThread *)thread - fromViewController:(UIViewController *)fromViewController { - OWSAssert(thread); - OWSAssert(fromViewController); - - OWSTableContents *contents = [OWSTableContents new]; - contents.title = @"Debug: Conversation"; - - [contents - addSection:[OWSTableSection - sectionWithTitle:@"Messages View" - items:@[ - [OWSTableItem itemWithTitle:@"Send 10 messages (1/sec.)" - actionBlock:^{ - [DebugUITableViewController sendTextMessage:10 thread:thread]; - }], - [OWSTableItem itemWithTitle:@"Send 100 messages (1/sec.)" - actionBlock:^{ - [DebugUITableViewController sendTextMessage:100 - thread:thread]; - }], - [OWSTableItem itemWithTitle:@"Send 1,000 messages (1/sec.)" - actionBlock:^{ - [DebugUITableViewController sendTextMessage:1000 - thread:thread]; - }], - [OWSTableItem itemWithTitle:@"Send text/x-signal-plain" - actionBlock:^{ - [DebugUITableViewController sendOversizeTextMessage:thread]; - }], - [OWSTableItem - itemWithTitle:@"Send unknown mimetype" - actionBlock:^{ - [DebugUITableViewController - sendRandomAttachment:thread - uti:SignalAttachment.kUnknownTestAttachmentUTI]; - }], - [OWSTableItem itemWithTitle:@"Send pdf" - actionBlock:^{ - [DebugUITableViewController - sendRandomAttachment:thread - uti:(NSString *)kUTTypePDF]; - }], - ]]]; - - [contents - addSection:[OWSTableSection - sectionWithTitle:@"Session State" - items:@[ - [OWSTableItem itemWithTitle:@"Print all sessions" - actionBlock:^{ - dispatch_async([OWSDispatch sessionStoreQueue], ^{ - [[TSStorageManager sharedManager] printAllSessions]; - }); - }], - [OWSTableItem - itemWithTitle:@"Delete session (Contact Thread Only)" - actionBlock:^{ - if (![thread isKindOfClass:[TSContactThread class]]) { - DDLogError(@"Refusing to delete session for group thread."); - OWSAssert(NO); - return; - } - TSContactThread *contactThread = (TSContactThread *)thread; - dispatch_async([OWSDispatch sessionStoreQueue], ^{ - [[TSStorageManager sharedManager] - deleteAllSessionsForContact:contactThread.contactIdentifier]; - }); - }], - [OWSTableItem - itemWithTitle:@"Send session reset (Contact Thread Only)" - actionBlock:^{ - if (![thread isKindOfClass:[TSContactThread class]]) { - DDLogError(@"Refusing to reset session for group thread."); - OWSAssert(NO); - return; - } - TSContactThread *contactThread = (TSContactThread *)thread; - [OWSSessionResetJob - runWithContactThread:contactThread - messageSender:[Environment getCurrent].messageSender - storageManager:[TSStorageManager sharedManager]]; - }] - - ]]]; - - [contents addSection:[OWSTableSection - sectionWithTitle:@"Misc." - items:@[ - [OWSTableItem itemWithTitle:@"Create 1 Random Contact" - actionBlock:^{ - [DebugUITableViewController createRandomContacts:1]; - }], - [OWSTableItem itemWithTitle:@"Create 100 Random Contacts" - actionBlock:^{ - [DebugUITableViewController createRandomContacts:100]; - }], - [OWSTableItem itemWithTitle:@"Delete Random Contacts" - actionBlock:^{ - [DebugUITableViewController deleteRandomContacts]; - }], - ]]]; ++ (OWSTableSection *)section +{ - DebugUITableViewController *viewController = [DebugUITableViewController new]; - viewController.contents = contents; - [viewController presentFromViewController:fromViewController]; + return [OWSTableSection sectionWithTitle:@"Contacts" + items:@[ + [OWSTableItem itemWithTitle:@"Create 1 Random Contact" + actionBlock:^{ + [DebugUIContacts createRandomContacts:1]; + }], + [OWSTableItem itemWithTitle:@"Create 100 Random Contacts" + actionBlock:^{ + [DebugUIContacts createRandomContacts:100]; + }], + [OWSTableItem itemWithTitle:@"Delete Random Contacts" + actionBlock:^{ + [DebugUIContacts deleteRandomContacts]; + }], + ]]; } + (NSString *)randomFirstName @@ -1296,63 +1206,6 @@ NS_ASSUME_NONNULL_BEGIN }]; } -+ (void)sendTextMessage:(int)counter - thread:(TSThread *)thread { - OWSMessageSender *messageSender = [Environment getCurrent].messageSender; - if (counter < 1) { - return; - } - [ThreadUtil - sendMessageWithText:[[@(counter) description] - stringByAppendingString:@" Lorem ipsum dolor sit amet, consectetur adipiscing elit. " - @"Suspendisse rutrum, nulla vitae pretium hendrerit, tellus " - @"turpis pharetra libero, vitae sodales tortor ante vel sem."] - inThread:thread - messageSender:messageSender]; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) 1.f * NSEC_PER_SEC), - dispatch_get_main_queue(), ^{ - [self sendTextMessage:counter - 1 thread:thread]; - }); -} - -+ (void)sendOversizeTextMessage:(TSThread *)thread { - OWSMessageSender *messageSender = [Environment getCurrent].messageSender; - NSMutableString *message = [NSMutableString new]; - for (int i=0; i < 32; i++) { - [message appendString:@"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse rutrum, nulla vitae pretium hendrerit, tellus turpis pharetra libero, vitae sodales tortor ante vel sem. Fusce sed nisl a lorem gravida tincidunt. Suspendisse efficitur non quam ac sodales. Aenean ut velit maximus, posuere sem a, accumsan nunc. Donec ullamcorper turpis lorem. Quisque dignissim purus eu placerat ultricies. Proin at urna eget mi semper congue. Aenean non elementum ex. Praesent pharetra quam at sem vestibulum, vestibulum ornare dolor elementum. Vestibulum massa tortor, scelerisque sit amet pulvinar a, rhoncus vitae nisl. Sed mi nunc, tempus at varius in, malesuada vitae dui. Vivamus efficitur pulvinar erat vitae congue. Proin vehicula turpis non felis congue facilisis. Nullam aliquet dapibus ligula ac mollis. Etiam sit amet posuere lorem, in rhoncus nisi."]; - } - - SignalAttachment *attachment = [SignalAttachment attachmentWithData:[message dataUsingEncoding:NSUTF8StringEncoding] - dataUTI:SignalAttachment.kOversizeTextAttachmentUTI - filename:nil]; - [ThreadUtil sendMessageWithAttachment:attachment - inThread:thread - messageSender:messageSender]; -} - -+ (NSData*)createRandomNSDataOfSize:(size_t)size -{ - OWSAssert(size % 4 == 0); - - NSMutableData* data = [NSMutableData dataWithCapacity:size]; - for (size_t i = 0; i < size / 4; ++i) - { - u_int32_t randomBits = arc4random(); - [data appendBytes:(void *)&randomBits length:4]; - } - return data; -} - -+ (void)sendRandomAttachment:(TSThread *)thread - uti:(NSString *)uti { - OWSMessageSender *messageSender = [Environment getCurrent].messageSender; - SignalAttachment *attachment = - [SignalAttachment attachmentWithData:[self createRandomNSDataOfSize:256] dataUTI:uti filename:nil]; - [ThreadUtil sendMessageWithAttachment:attachment - inThread:thread - messageSender:messageSender]; -} - @end NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.h b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.h new file mode 100644 index 000000000..118dda4a9 --- /dev/null +++ b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.h @@ -0,0 +1,17 @@ +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// + +#import "OWSTableViewController.h" + +NS_ASSUME_NONNULL_BEGIN + +@class TSThread; + +@interface DebugUIMessages : NSObject + ++ (OWSTableSection *)sectionForThread:(TSThread *)thread; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m new file mode 100644 index 000000000..ff1d2c683 --- /dev/null +++ b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m @@ -0,0 +1,497 @@ +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// + +#import "DebugUIMessages.h" +#import "Environment.h" +#import "Signal-Swift.h" +#import "ThreadUtil.h" +#import +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +@implementation DebugUIMessages + +#pragma mark - Logging + ++ (NSString *)tag +{ + return [NSString stringWithFormat:@"[%@]", self.class]; +} + +- (NSString *)tag +{ + return self.class.tag; +} + +#pragma mark - Factory Methods + ++ (OWSTableSection *)sectionForThread:(TSThread *)thread +{ + OWSAssert(thread); + + return [OWSTableSection + sectionWithTitle:@"Messages" + items:@[ + [OWSTableItem itemWithTitle:@"Send 10 messages (1/sec.)" + actionBlock:^{ + [DebugUIMessages sendTextMessage:10 thread:thread]; + }], + [OWSTableItem itemWithTitle:@"Send 100 messages (1/sec.)" + actionBlock:^{ + [DebugUIMessages sendTextMessage:100 thread:thread]; + }], + [OWSTableItem itemWithTitle:@"Send 1,000 messages (1/sec.)" + actionBlock:^{ + [DebugUIMessages sendTextMessage:1000 thread:thread]; + }], + [OWSTableItem itemWithTitle:@"Send text/x-signal-plain" + actionBlock:^{ + [DebugUIMessages sendOversizeTextMessage:thread]; + }], + [OWSTableItem itemWithTitle:@"Send unknown mimetype" + actionBlock:^{ + [DebugUIMessages + sendRandomAttachment:thread + uti:SignalAttachment.kUnknownTestAttachmentUTI]; + }], + [OWSTableItem itemWithTitle:@"Send pdf" + actionBlock:^{ + [DebugUIMessages sendRandomAttachment:thread uti:(NSString *)kUTTypePDF]; + }], + [OWSTableItem itemWithTitle:@"Send 1 Random GIF (1/sec.)" + actionBlock:^{ + [DebugUIMessages sendRandomGifs:1 thread:thread]; + }], + [OWSTableItem itemWithTitle:@"Send 10 Random GIF (1/sec.)" + actionBlock:^{ + [DebugUIMessages sendRandomGifs:10 thread:thread]; + }], + [OWSTableItem itemWithTitle:@"Send 100 Random GIF (1/sec.)" + actionBlock:^{ + [DebugUIMessages sendRandomGifs:100 thread:thread]; + }], + [OWSTableItem itemWithTitle:@"Send 1 Random JPEG (1/sec.)" + actionBlock:^{ + [DebugUIMessages sendRandomJpegs:1 thread:thread]; + }], + [OWSTableItem itemWithTitle:@"Send 10 Random JPEG (1/sec.)" + actionBlock:^{ + [DebugUIMessages sendRandomJpegs:10 thread:thread]; + }], + [OWSTableItem itemWithTitle:@"Send 100 Random JPEG (1/sec.)" + actionBlock:^{ + [DebugUIMessages sendRandomJpegs:100 thread:thread]; + }], + [OWSTableItem itemWithTitle:@"Send 1 Random Mp3 (1/sec.)" + actionBlock:^{ + [DebugUIMessages sendRandomMp3s:1 thread:thread]; + }], + [OWSTableItem itemWithTitle:@"Send 10 Random Mp3 (1/sec.)" + actionBlock:^{ + [DebugUIMessages sendRandomMp3s:10 thread:thread]; + }], + [OWSTableItem itemWithTitle:@"Send 100 Random Mp3 (1/sec.)" + actionBlock:^{ + [DebugUIMessages sendRandomMp3s:100 thread:thread]; + }], + [OWSTableItem itemWithTitle:@"Send 1 Random Mp4 (1/sec.)" + actionBlock:^{ + [DebugUIMessages sendRandomMp4s:1 thread:thread]; + }], + [OWSTableItem itemWithTitle:@"Send 10 Random Mp4 (1/sec.)" + actionBlock:^{ + [DebugUIMessages sendRandomMp4s:10 thread:thread]; + }], + [OWSTableItem itemWithTitle:@"Send 100 Random Mp4 (1/sec.)" + actionBlock:^{ + [DebugUIMessages sendRandomMp4s:100 thread:thread]; + }], + [OWSTableItem itemWithTitle:@"Send 10 media (1/sec.)" + actionBlock:^{ + [DebugUIMessages sendMediaAttachments:10 thread:thread]; + }], + [OWSTableItem itemWithTitle:@"Send 100 media (1/sec.)" + actionBlock:^{ + [DebugUIMessages sendMediaAttachments:100 thread:thread]; + }], + ]]; +} + ++ (void)sendTextMessage:(int)counter thread:(TSThread *)thread +{ + OWSMessageSender *messageSender = [Environment getCurrent].messageSender; + if (counter < 1) { + return; + } + [ThreadUtil + sendMessageWithText:[[@(counter) description] + stringByAppendingString:@" Lorem ipsum dolor sit amet, consectetur adipiscing elit. " + @"Suspendisse rutrum, nulla vitae pretium hendrerit, tellus " + @"turpis pharetra libero, vitae sodales tortor ante vel sem."] + inThread:thread + messageSender:messageSender]; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)1.f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ + [self sendTextMessage:counter - 1 thread:thread]; + }); +} + ++ (void)ensureRandomFileWithURL:(NSString *)url + filename:(NSString *)filename + success:(nullable void (^)(NSString *filePath))success + failure:(nullable void (^)())failure +{ + NSFileManager *fileManager = [NSFileManager defaultManager]; + NSURL *documentDirectoryURL = + [[fileManager URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; + NSString *randomFilesDirectoryPath = + [[documentDirectoryURL path] stringByAppendingPathComponent:@"cached_random_files"]; + NSError *error; + if (![fileManager fileExistsAtPath:randomFilesDirectoryPath]) { + [fileManager createDirectoryAtPath:randomFilesDirectoryPath + withIntermediateDirectories:YES + attributes:nil + error:&error]; + OWSAssert(!error); + if (error) { + DDLogError(@"Error creating directory: %@", error); + failure(); + return; + } + } + NSString *filePath = [randomFilesDirectoryPath stringByAppendingPathComponent:filename]; + if ([fileManager fileExistsAtPath:filePath]) { + success(filePath); + } else { + NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; + AFHTTPSessionManager *sessionManager = + [[AFHTTPSessionManager alloc] initWithSessionConfiguration:configuration]; + sessionManager.responseSerializer = [AFHTTPResponseSerializer serializer]; + OWSAssert(sessionManager.responseSerializer); + [sessionManager GET:url + parameters:nil + progress:nil + success:^(NSURLSessionDataTask *task, NSData *_Nullable responseObject) { + if ([responseObject writeToFile:filePath atomically:YES]) { + success(filePath); + } else { + DDLogError(@"Error write url response [%@]: %@", url, filePath); + OWSAssert(0); + failure(); + } + } + failure:^(NSURLSessionDataTask *_Nullable task, NSError *requestError) { + DDLogError(@"Error downloading url[%@]: %@", url, requestError); + OWSAssert(0); + failure(); + }]; + } +} + ++ (void)sendAttachment:(NSString *)filePath + thread:(TSThread *)thread + success:(nullable void (^)())success + failure:(nullable void (^)())failure +{ + OWSAssert(filePath); + OWSAssert(thread); + + OWSMessageSender *messageSender = [Environment getCurrent].messageSender; + NSString *filename = [filePath lastPathComponent]; + NSString *utiType = [MIMETypeUtil utiTypeForFileExtension:filename.pathExtension]; + NSData *data = [NSData dataWithContentsOfFile:filePath]; + OWSAssert(data); + if (!data) { + DDLogError(@"Couldn't read attachment: %@", filePath); + failure(); + return; + } + SignalAttachment *attachment = [SignalAttachment attachmentWithData:data dataUTI:utiType filename:filename]; + OWSAssert(attachment); + if ([attachment hasError]) { + DDLogError(@"attachment[%@]: %@", [attachment filename], [attachment errorName]); + [DDLog flushLog]; + } + OWSAssert(![attachment hasError]); + [ThreadUtil sendMessageWithAttachment:attachment inThread:thread messageSender:messageSender]; + success(); +} + ++ (void)ensureRandomGifWithSuccess:(nullable void (^)(NSString *filePath))success failure:(nullable void (^)())failure +{ + [self ensureRandomFileWithURL:@"https://s3.amazonaws.com/ows-data/example_attachment_media/random-gif.gif" + filename:@"random-gif.gif" + success:success + failure:failure]; +} + ++ (void)sendRandomGifInThread:(TSThread *)thread + success:(nullable void (^)())success + failure:(nullable void (^)())failure +{ + [self ensureRandomGifWithSuccess:^(NSString *filePath) { + [self sendAttachment:filePath thread:thread success:success failure:failure]; + } + failure:failure]; +} + ++ (void)sendRandomGifs:(int)count thread:(TSThread *)thread +{ + OWSAssert(count > 0); + [self ensureRandomGifWithSuccess:^(NSString *filePath) { + [self + sendAttachment:filePath + thread:thread + success:^{ + if (count <= 1) { + return; + } + dispatch_after( + dispatch_time(DISPATCH_TIME_NOW, (int64_t)1.f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ + [self sendRandomGifs:count - 1 thread:thread]; + }); + } + failure:^{ + }]; + } + failure:^{ + }]; +} + ++ (void)ensureRandomJpegWithSuccess:(nullable void (^)(NSString *filePath))success failure:(nullable void (^)())failure +{ + [self ensureRandomFileWithURL:@"https://s3.amazonaws.com/ows-data/example_attachment_media/random-jpg.JPG" + filename:@"random-jpg.jpg" + success:success + failure:failure]; +} + ++ (void)sendRandomJpegInThread:(TSThread *)thread + success:(nullable void (^)())success + failure:(nullable void (^)())failure +{ + [self ensureRandomJpegWithSuccess:^(NSString *filePath) { + [self sendAttachment:filePath thread:thread success:success failure:failure]; + } + failure:failure]; +} + ++ (void)sendRandomJpegs:(int)count thread:(TSThread *)thread +{ + OWSAssert(count > 0); + [self ensureRandomJpegWithSuccess:^(NSString *filePath) { + [self + sendAttachment:filePath + thread:thread + success:^{ + if (count <= 1) { + return; + } + dispatch_after( + dispatch_time(DISPATCH_TIME_NOW, (int64_t)1.f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ + [self sendRandomJpegs:count - 1 thread:thread]; + }); + } + failure:^{ + }]; + } + failure:^{ + }]; +} + ++ (void)ensureRandomMp3WithSuccess:(nullable void (^)(NSString *filePath))success failure:(nullable void (^)())failure +{ + [self ensureRandomFileWithURL:@"https://s3.amazonaws.com/ows-data/example_attachment_media/random-mp3.mp3" + filename:@"random-mp3.mp3" + success:success + failure:failure]; +} + ++ (void)sendRandomMp3InThread:(TSThread *)thread + success:(nullable void (^)())success + failure:(nullable void (^)())failure +{ + [self ensureRandomMp3WithSuccess:^(NSString *filePath) { + [self sendAttachment:filePath thread:thread success:success failure:failure]; + } + failure:failure]; +} + ++ (void)sendRandomMp3s:(int)count thread:(TSThread *)thread +{ + OWSAssert(count > 0); + [self ensureRandomMp3WithSuccess:^(NSString *filePath) { + [self + sendAttachment:filePath + thread:thread + success:^{ + if (count <= 1) { + return; + } + dispatch_after( + dispatch_time(DISPATCH_TIME_NOW, (int64_t)1.f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ + [self sendRandomMp3s:count - 1 thread:thread]; + }); + } + failure:^{ + }]; + } + failure:^{ + }]; +} + ++ (void)ensureRandomMp4WithSuccess:(nullable void (^)(NSString *filePath))success failure:(nullable void (^)())failure +{ + [self ensureRandomFileWithURL:@"https://s3.amazonaws.com/ows-data/example_attachment_media/random-mp4.mp4" + filename:@"random-mp4.mp4" + success:success + failure:failure]; +} + ++ (void)sendRandomMp4InThread:(TSThread *)thread + success:(nullable void (^)())success + failure:(nullable void (^)())failure +{ + [self ensureRandomMp4WithSuccess:^(NSString *filePath) { + [self sendAttachment:filePath thread:thread success:success failure:failure]; + } + failure:failure]; +} + ++ (void)sendRandomMp4s:(int)count thread:(TSThread *)thread +{ + OWSAssert(count > 0); + [self ensureRandomMp4WithSuccess:^(NSString *filePath) { + [self + sendAttachment:filePath + thread:thread + success:^{ + if (count <= 1) { + return; + } + dispatch_after( + dispatch_time(DISPATCH_TIME_NOW, (int64_t)1.f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ + [self sendRandomMp4s:count - 1 thread:thread]; + }); + } + failure:^{ + }]; + } + failure:^{ + }]; +} + ++ (void)sendMediaAttachments:(int)count thread:(TSThread *)thread +{ + OWSAssert(count > 0); + + void (^success)() = ^{ + if (count <= 1) { + return; + } + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)1.f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ + [self sendMediaAttachments:count - 1 thread:thread]; + }); + }; + + switch (arc4random_uniform(4)) { + case 0: { + [self ensureRandomGifWithSuccess:^(NSString *filePath) { + [self sendAttachment:filePath + thread:thread + success:success + failure:^{ + }]; + } + failure:^{ + }]; + break; + } + case 1: { + [self ensureRandomJpegWithSuccess:^(NSString *filePath) { + [self sendAttachment:filePath + thread:thread + success:success + failure:^{ + }]; + } + failure:^{ + }]; + break; + } + case 2: { + [self ensureRandomMp3WithSuccess:^(NSString *filePath) { + [self sendAttachment:filePath + thread:thread + success:success + failure:^{ + }]; + } + failure:^{ + }]; + break; + } + case 3: { + [self ensureRandomMp4WithSuccess:^(NSString *filePath) { + [self sendAttachment:filePath + thread:thread + success:success + failure:^{ + }]; + } + failure:^{ + }]; + break; + } + } +} + ++ (void)sendOversizeTextMessage:(TSThread *)thread +{ + OWSMessageSender *messageSender = [Environment getCurrent].messageSender; + NSMutableString *message = [NSMutableString new]; + for (int i = 0; i < 32; i++) { + [message appendString:@"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse rutrum, nulla " + @"vitae pretium hendrerit, tellus turpis pharetra libero, vitae sodales tortor ante vel " + @"sem. Fusce sed nisl a lorem gravida tincidunt. Suspendisse efficitur non quam ac " + @"sodales. Aenean ut velit maximus, posuere sem a, accumsan nunc. Donec ullamcorper " + @"turpis lorem. Quisque dignissim purus eu placerat ultricies. Proin at urna eget mi " + @"semper congue. Aenean non elementum ex. Praesent pharetra quam at sem vestibulum, " + @"vestibulum ornare dolor elementum. Vestibulum massa tortor, scelerisque sit amet " + @"pulvinar a, rhoncus vitae nisl. Sed mi nunc, tempus at varius in, malesuada vitae " + @"dui. Vivamus efficitur pulvinar erat vitae congue. Proin vehicula turpis non felis " + @"congue facilisis. Nullam aliquet dapibus ligula ac mollis. Etiam sit amet posuere " + @"lorem, in rhoncus nisi."]; + } + + SignalAttachment *attachment = [SignalAttachment attachmentWithData:[message dataUsingEncoding:NSUTF8StringEncoding] + dataUTI:SignalAttachment.kOversizeTextAttachmentUTI + filename:nil]; + [ThreadUtil sendMessageWithAttachment:attachment inThread:thread messageSender:messageSender]; +} + ++ (NSData *)createRandomNSDataOfSize:(size_t)size +{ + OWSAssert(size % 4 == 0); + + NSMutableData *data = [NSMutableData dataWithCapacity:size]; + for (size_t i = 0; i < size / 4; ++i) { + u_int32_t randomBits = arc4random(); + [data appendBytes:(void *)&randomBits length:4]; + } + return data; +} + ++ (void)sendRandomAttachment:(TSThread *)thread uti:(NSString *)uti +{ + OWSMessageSender *messageSender = [Environment getCurrent].messageSender; + SignalAttachment *attachment = + [SignalAttachment attachmentWithData:[self createRandomNSDataOfSize:256] dataUTI:uti filename:nil]; + [ThreadUtil sendMessageWithAttachment:attachment inThread:thread messageSender:messageSender]; +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/DebugUITableViewController.h b/Signal/src/ViewControllers/DebugUI/DebugUITableViewController.h similarity index 66% rename from Signal/src/ViewControllers/DebugUITableViewController.h rename to Signal/src/ViewControllers/DebugUI/DebugUITableViewController.h index fa2412759..b44a189ce 100644 --- a/Signal/src/ViewControllers/DebugUITableViewController.h +++ b/Signal/src/ViewControllers/DebugUI/DebugUITableViewController.h @@ -10,8 +10,7 @@ NS_ASSUME_NONNULL_BEGIN @interface DebugUITableViewController : OWSTableViewController -+ (void)presentDebugUIForThread:(TSThread *)thread - fromViewController:(UIViewController *)fromViewController; ++ (void)presentDebugUIForThread:(TSThread *)thread fromViewController:(UIViewController *)fromViewController; @end diff --git a/Signal/src/ViewControllers/DebugUI/DebugUITableViewController.m b/Signal/src/ViewControllers/DebugUI/DebugUITableViewController.m new file mode 100644 index 000000000..aa1602024 --- /dev/null +++ b/Signal/src/ViewControllers/DebugUI/DebugUITableViewController.m @@ -0,0 +1,91 @@ +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// + +#import "DebugUITableViewController.h" +#import "DebugUIContacts.h" +#import "DebugUIMessages.h" +#import "Signal-Swift.h" +#import +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +@implementation DebugUITableViewController + +#pragma mark - Logging + ++ (NSString *)tag +{ + return [NSString stringWithFormat:@"[%@]", self.class]; +} + +- (NSString *)tag +{ + return self.class.tag; +} + +#pragma mark - Factory Methods + ++ (void)presentDebugUIForThread:(TSThread *)thread fromViewController:(UIViewController *)fromViewController +{ + OWSAssert(thread); + OWSAssert(fromViewController); + + OWSTableContents *contents = [OWSTableContents new]; + contents.title = @"Debug: Conversation"; + + [contents addSection:[DebugUIMessages sectionForThread:thread]]; + + [contents + addSection:[OWSTableSection + sectionWithTitle:@"Session State" + items:@[ + [OWSTableItem itemWithTitle:@"Print all sessions" + actionBlock:^{ + dispatch_async([OWSDispatch sessionStoreQueue], ^{ + [[TSStorageManager sharedManager] printAllSessions]; + }); + }], + [OWSTableItem + itemWithTitle:@"Delete session (Contact Thread Only)" + actionBlock:^{ + if (![thread isKindOfClass:[TSContactThread class]]) { + DDLogError(@"Refusing to delete session for group thread."); + OWSAssert(NO); + return; + } + TSContactThread *contactThread = (TSContactThread *)thread; + dispatch_async([OWSDispatch sessionStoreQueue], ^{ + [[TSStorageManager sharedManager] + deleteAllSessionsForContact:contactThread.contactIdentifier]; + }); + }], + [OWSTableItem + itemWithTitle:@"Send session reset (Contact Thread Only)" + actionBlock:^{ + if (![thread isKindOfClass:[TSContactThread class]]) { + DDLogError(@"Refusing to reset session for group thread."); + OWSAssert(NO); + return; + } + TSContactThread *contactThread = (TSContactThread *)thread; + [OWSSessionResetJob + runWithContactThread:contactThread + messageSender:[Environment getCurrent].messageSender + storageManager:[TSStorageManager sharedManager]]; + }] + + ]]]; + + [contents addSection:[DebugUIContacts section]]; + + DebugUITableViewController *viewController = [DebugUITableViewController new]; + viewController.contents = contents; + [viewController presentFromViewController:fromViewController]; +} + +@end + +NS_ASSUME_NONNULL_END