diff --git a/Podfile.lock b/Podfile.lock index 2cab539fe..bf1a2e860 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -134,7 +134,7 @@ CHECKOUT OPTIONS: :commit: 7054e4b13ee5bcd6d524adb6dc9a726e8c466308 :git: https://github.com/WhisperSystems/JSQMessagesViewController.git SignalServiceKit: - :commit: 7379e6a679ce0b21b2c8dbeace0b6d97c7807a88 + :commit: 26e6aab071d9982e20b05d75d1a0576614f6a029 :git: https://github.com/WhisperSystems/SignalServiceKit.git SocketRocket: :commit: 877ac7438be3ad0b45ef5ca3969574e4b97112bf diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index c7eaa4f03..7d1596299 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -197,9 +197,10 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; [[UIStoryboard storyboardWithName:@"Launch Screen" bundle:nil] instantiateInitialViewController]; BOOL shouldShowUpgradeLabel = NO; - NSString *previousVersion = AppVersion.instance.lastAppVersion; + NSString *previousVersion = AppVersion.instance.lastCompletedLaunchAppVersion; // We added a number of database views in v2.13.0. - if ([VersionMigrations isVersion:previousVersion atLeast:@"2.0.0" andLessThan:@"2.13.0"]) { + if ([TSAccountManager isRegistered] && + [VersionMigrations isVersion:previousVersion atLeast:@"2.0.0" andLessThan:@"2.13.0"]) { shouldShowUpgradeLabel = YES; } if (shouldShowUpgradeLabel) { @@ -214,14 +215,30 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; if (!iconView) { OWSFail(@"Database view registration overlay has unexpected contents."); } else { - UILabel *label = [UILabel new]; - label.text = NSLocalizedString( - @"DATABASE_VIEW_OVERLAY_TITLE", @"Indicates that the app is updating its database."); - label.font = [UIFont ows_mediumFontWithSize:18.f]; - label.textColor = [UIColor whiteColor]; - [rootView addSubview:label]; - [label autoHCenterInSuperview]; - [label autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:iconView withOffset:25.f]; + UILabel *bottomLabel = [UILabel new]; + bottomLabel.text = NSLocalizedString( + @"DATABASE_VIEW_OVERLAY_SUBTITLE", @"Subtitle shown while the app is updating its database."); + bottomLabel.font = [UIFont ows_mediumFontWithSize:16.f]; + bottomLabel.textColor = [UIColor whiteColor]; + bottomLabel.numberOfLines = 0; + bottomLabel.lineBreakMode = NSLineBreakByWordWrapping; + bottomLabel.textAlignment = NSTextAlignmentCenter; + [rootView addSubview:bottomLabel]; + + UILabel *topLabel = [UILabel new]; + topLabel.text = NSLocalizedString( + @"DATABASE_VIEW_OVERLAY_TITLE", @"Title shown while the app is updating its database."); + topLabel.font = [UIFont ows_mediumFontWithSize:20.f]; + topLabel.textColor = [UIColor whiteColor]; + topLabel.numberOfLines = 0; + topLabel.lineBreakMode = NSLineBreakByWordWrapping; + topLabel.textAlignment = NSTextAlignmentCenter; + [rootView addSubview:topLabel]; + + [bottomLabel autoPinWidthToSuperviewWithMargin:20.f]; + [topLabel autoPinWidthToSuperviewWithMargin:20.f]; + [bottomLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:topLabel withOffset:10.f]; + [iconView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:bottomLabel withOffset:40.f]; } } @@ -719,6 +736,8 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; { DDLogInfo(@"databaseViewRegistrationComplete"); + [AppVersion.instance appLaunchDidComplete]; + [self ensureRootViewController]; } diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m index ee86986df..8661dd57c 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m @@ -53,13 +53,29 @@ NS_ASSUME_NONNULL_BEGIN actionBlock:^{ [DebugUIMessages sendTextMessages:1000 thread:thread]; }], + [OWSTableItem itemWithTitle:@"Send 10 tiny attachments" + actionBlock:^{ + [DebugUIMessages sendTinyAttachments:10 thread:thread]; + }], + [OWSTableItem itemWithTitle:@"Send 100 tiny attachments" + actionBlock:^{ + [DebugUIMessages sendTinyAttachments:100 thread:thread]; + }], + [OWSTableItem itemWithTitle:@"Send 1,000 tiny attachments" + actionBlock:^{ + [DebugUIMessages sendTinyAttachments:1000 thread:thread]; + }], + [OWSTableItem itemWithTitle:@"Create 10 fake messages" + actionBlock:^{ + [DebugUIMessages sendFakeMessages:10 thread:thread]; + }], [OWSTableItem itemWithTitle:@"Create 1k fake messages" actionBlock:^{ - [DebugUIMessages sendFakeTextMessage:1000 thread:thread]; + [DebugUIMessages sendFakeMessages:1000 thread:thread]; }], [OWSTableItem itemWithTitle:@"Create 10k fake messages" actionBlock:^{ - [DebugUIMessages sendFakeTextMessage:10 * 1000 thread:thread]; + [DebugUIMessages sendFakeMessages:10 * 1000 thread:thread]; }], [OWSTableItem itemWithTitle:@"Send text/x-signal-plain" actionBlock:^{ @@ -517,13 +533,17 @@ NS_ASSUME_NONNULL_BEGIN } + (void)sendRandomAttachment:(TSThread *)thread uti:(NSString *)uti +{ + [self sendRandomAttachment:thread uti:uti length:256]; +} + ++ (void)sendRandomAttachment:(TSThread *)thread uti:(NSString *)uti length:(NSUInteger)length { OWSMessageSender *messageSender = [Environment getCurrent].messageSender; SignalAttachment *attachment = - [SignalAttachment attachmentWithData:[self createRandomNSDataOfSize:256] dataUTI:uti filename:nil]; - [ThreadUtil sendMessageWithAttachment:attachment inThread:thread messageSender:messageSender]; + [SignalAttachment attachmentWithData:[self createRandomNSDataOfSize:length] dataUTI:uti filename:nil]; + [ThreadUtil sendMessageWithAttachment:attachment inThread:thread messageSender:messageSender ignoreErrors:YES]; } - + (OWSSignalServiceProtosEnvelope *)createEnvelopeForThread:(TSThread *)thread { OWSAssert(thread); @@ -760,31 +780,102 @@ NS_ASSUME_NONNULL_BEGIN return randomText; } -+ (void)sendFakeTextMessage:(int)counter thread:(TSThread *)thread -{ - NSMutableArray *messages = [NSMutableArray new]; - for (int i = 0; i < counter; i++) { - NSString *randomText = [self randomText]; - BOOL isIncoming = arc4random_uniform(2) == 0; - if (isIncoming) { - [messages addObject:[[TSIncomingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] - inThread:thread - authorId:@"+19174054215" - sourceDeviceId:0 - messageBody:randomText]]; - } else { - [messages addObject:[[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] - inThread:thread - messageBody:randomText]]; - } - } ++ (void)sendFakeMessages:(int)counter thread:(TSThread *)thread +{ [TSStorageManager.sharedManager.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { - for (TSMessage *message in messages) { - [message saveWithTransaction:transaction]; + for (int i = 0; i < counter; i++) { + NSString *randomText = [self randomText]; + switch (arc4random_uniform(4)) { + case 0: { + TSIncomingMessage *message = + [[TSIncomingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] + inThread:thread + authorId:@"+19174054215" + sourceDeviceId:0 + messageBody:randomText]; + [message markAsReadWithTransaction:transaction sendReadReceipt:NO updateExpiration:NO]; + break; + } + case 1: { + TSOutgoingMessage *message = + [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] + inThread:thread + messageBody:randomText]; + [message saveWithTransaction:transaction]; + break; + } + case 2: { + TSAttachmentPointer *pointer = + [[TSAttachmentPointer alloc] initWithServerId:237391539706350548 + key:[self createRandomNSDataOfSize:64] + digest:nil + contentType:@"audio/mp3" + relay:@"" + sourceFilename:@"test.mp3" + attachmentType:TSAttachmentTypeDefault]; + [pointer saveWithTransaction:transaction]; + TSIncomingMessage *message = + [[TSIncomingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] + inThread:thread + authorId:@"+19174054215" + sourceDeviceId:0 + messageBody:nil + attachmentIds:@[ + pointer.uniqueId, + ] + expiresInSeconds:0]; + [message markAsReadWithTransaction:transaction sendReadReceipt:NO updateExpiration:NO]; + break; + } + case 3: { + TSOutgoingMessage *message = + [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] + inThread:thread + isVoiceMessage:NO + expiresInSeconds:0]; + + NSString *filename = @"test.mp3"; + TSAttachmentStream *attachmentStream = + [[TSAttachmentStream alloc] initWithContentType:@"audio/mp3" sourceFilename:filename]; + + NSError *error; + [attachmentStream writeData:[self createRandomNSDataOfSize:16] error:&error]; + OWSAssert(!error); + + [attachmentStream saveWithTransaction:transaction]; + [message.attachmentIds addObject:attachmentStream.uniqueId]; + if (filename) { + message.attachmentFilenameMap[attachmentStream.uniqueId] = filename; + } + [message saveWithTransaction:transaction]; + break; + } + } } }]; } ++ (void)sendTinyAttachments:(int)counter thread:(TSThread *)thread +{ + if (counter < 1) { + return; + } + + NSArray *utis = @[ + (NSString *)kUTTypePDF, + (NSString *)kUTTypeMP3, + (NSString *)kUTTypeGIF, + (NSString *)kUTTypeMPEG4, + (NSString *)kUTTypeJPEG, + ]; + NSString *uti = utis[(NSUInteger)arc4random_uniform((uint32_t)utis.count)]; + [self sendRandomAttachment:thread uti:uti length:16]; + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)1.f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ + [self sendTinyAttachments:counter - 1 thread:thread]; + }); +} + @end NS_ASSUME_NONNULL_END diff --git a/Signal/src/util/ThreadUtil.h b/Signal/src/util/ThreadUtil.h index 1c4fd2b71..a79199b57 100644 --- a/Signal/src/util/ThreadUtil.h +++ b/Signal/src/util/ThreadUtil.h @@ -54,6 +54,12 @@ NS_ASSUME_NONNULL_BEGIN inThread:(TSThread *)thread messageSender:(OWSMessageSender *)messageSender; +// We only should set ignoreErrors in debug or test code. ++ (TSOutgoingMessage *)sendMessageWithAttachment:(SignalAttachment *)attachment + inThread:(TSThread *)thread + messageSender:(OWSMessageSender *)messageSender + ignoreErrors:(BOOL)ignoreErrors; + // This method will create and/or remove any offers and indicators // necessary for this thread. This includes: // diff --git a/Signal/src/util/ThreadUtil.m b/Signal/src/util/ThreadUtil.m index 0739759d8..e3ea27574 100644 --- a/Signal/src/util/ThreadUtil.m +++ b/Signal/src/util/ThreadUtil.m @@ -60,14 +60,21 @@ NS_ASSUME_NONNULL_BEGIN return message; } ++ (TSOutgoingMessage *)sendMessageWithAttachment:(SignalAttachment *)attachment + inThread:(TSThread *)thread + messageSender:(OWSMessageSender *)messageSender +{ + return [self sendMessageWithAttachment:attachment inThread:thread messageSender:messageSender ignoreErrors:NO]; +} + (TSOutgoingMessage *)sendMessageWithAttachment:(SignalAttachment *)attachment inThread:(TSThread *)thread messageSender:(OWSMessageSender *)messageSender + ignoreErrors:(BOOL)ignoreErrors { OWSAssert([NSThread isMainThread]); OWSAssert(attachment); - OWSAssert(![attachment hasError]); + OWSAssert(ignoreErrors || ![attachment hasError]); OWSAssert([attachment mimeType].length > 0); OWSAssert(thread); OWSAssert(messageSender); diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index bacb91fc5..d263bb96c 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -328,7 +328,10 @@ /* Accessibility label for the create group new group button */ "CREATE_NEW_GROUP" = "Create new group"; -/* Indicates that the app is updating its database. */ +/* Subtitle shown while the app is updating its database. */ +"DATABASE_VIEW_OVERLAY_SUBTITLE" = "This can take a few minutes."; + +/* Title shown while the app is updating its database. */ "DATABASE_VIEW_OVERLAY_TITLE" = "Updating Database"; /* {{number of days}} embedded in strings, e.g. 'Alice updated disappearing messages expiration to {{5 days}}'. See other *_TIME_AMOUNT strings */