From f893980468f8d4c0dc9062f803ea9f20b3e0de7c Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 2 Nov 2018 09:45:12 -0400 Subject: [PATCH] Add debug UI function to make group with unregistered users. --- .../ViewControllers/DebugUI/DebugUIStress.m | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIStress.m b/Signal/src/ViewControllers/DebugUI/DebugUIStress.m index fe9a9417c..a13bd9f87 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIStress.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUIStress.m @@ -14,6 +14,7 @@ #import #import #import +#import #import #import @@ -43,6 +44,11 @@ NS_ASSUME_NONNULL_BEGIN return SSKEnvironment.shared.primaryStorage.dbReadWriteConnection; } ++ (TSAccountManager *)tsAccountManager +{ + return TSAccountManager.sharedInstance; +} + #pragma mark - Factory Methods - (NSString *)name @@ -457,6 +463,11 @@ NS_ASSUME_NONNULL_BEGIN }]]; } + [items addObject:[OWSTableItem itemWithTitle:@"Make group w. unregistered users" + actionBlock:^{ + [DebugUIStress makeUnregisteredGroup]; + }]]; + #endif return [OWSTableSection sectionWithTitle:self.name items:items]; @@ -531,6 +542,33 @@ NS_ASSUME_NONNULL_BEGIN [SignalApp.sharedApp presentConversationForThread:thread animated:YES]; } ++ (void)makeUnregisteredGroup +{ + NSMutableArray *recipientIds = [NSMutableArray new]; + for (int i = 0; i < 3; i++) { + NSMutableString *recipientId = [@"+1999" mutableCopy]; + for (int j = 0; j < 3; j++) { + uint32_t digit = arc4random_uniform(10); + [recipientId appendFormat:@"%d", (int)digit]; + } + [recipientIds addObject:recipientId]; + } + [recipientIds addObject:self.tsAccountManager.localNumber]; + + __block TSGroupThread *thread; + [OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^( + YapDatabaseReadWriteTransaction *_Nonnull transaction) { + TSGroupModel *groupModel = [[TSGroupModel alloc] initWithTitle:NSUUID.UUID.UUIDString + memberIds:recipientIds + image:nil + groupId:[Randomness generateRandomBytes:kGroupIdLength]]; + thread = [TSGroupThread getOrCreateThreadWithGroupModel:groupModel transaction:transaction]; + }]; + OWSAssertDebug(thread); + + [SignalApp.sharedApp presentConversationForThread:thread animated:YES]; +} + #endif @end