From 75ccff0e4f38341b80a3812101a50b24cb9b3b9a Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 16 Jun 2017 10:39:01 -0400 Subject: [PATCH 1/7] =?UTF-8?q?Improve=20debug=20tools=20for=20creating=20?= =?UTF-8?q?=E2=80=9Cfake=E2=80=9D=20and=20=E2=80=9Ctiny=20attachment?= =?UTF-8?q?=E2=80=9D=20messages.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit // FREEBIE --- .../ViewControllers/DebugUI/DebugUIMessages.m | 148 ++++++++++++++---- Signal/src/util/ThreadUtil.h | 5 + Signal/src/util/ThreadUtil.m | 9 +- 3 files changed, 134 insertions(+), 28 deletions(-) diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m index ee86986df..26adc680a 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:@"Create 1k fake messages" + [OWSTableItem itemWithTitle:@"Send 10 tiny attachments" actionBlock:^{ - [DebugUIMessages sendFakeTextMessage:1000 thread:thread]; + [DebugUIMessages sendTinyAttachments:10 thread:thread]; }], - [OWSTableItem itemWithTitle:@"Create 10k fake messages" + [OWSTableItem itemWithTitle:@"Send 100 tiny attachments" actionBlock:^{ - [DebugUIMessages sendFakeTextMessage:10 * 1000 thread:thread]; + [DebugUIMessages sendTinyAttachments:100 thread:thread]; + }], + [OWSTableItem itemWithTitle:@"Send 1,000 tiny attachments" + actionBlock:^{ + [DebugUIMessages sendTinyAttachments:1000 thread:thread]; + }], + [OWSTableItem itemWithTitle:@"Send fake 10 messages" + actionBlock:^{ + [DebugUIMessages sendFakeMessages:10 thread:thread]; + }], + [OWSTableItem itemWithTitle:@"Send fake 1k messages" + actionBlock:^{ + [DebugUIMessages sendFakeMessages:1000 thread:thread]; + }], + [OWSTableItem itemWithTitle:@"Send fake 10k messages" + actionBlock:^{ + [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,105 @@ 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: { + OWSDisappearingMessagesConfiguration *configuration = + [OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:thread.uniqueId + transaction:transaction]; + TSOutgoingMessage *message = [[TSOutgoingMessage alloc] + initWithTimestamp:[NSDate ows_millisecondTimeStamp] + inThread:thread + isVoiceMessage:NO + expiresInSeconds:(configuration.isEnabled ? configuration.durationSeconds : 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..544803394 100644 --- a/Signal/src/util/ThreadUtil.h +++ b/Signal/src/util/ThreadUtil.h @@ -54,6 +54,11 @@ NS_ASSUME_NONNULL_BEGIN inThread:(TSThread *)thread messageSender:(OWSMessageSender *)messageSender; ++ (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); From cf3101226bab25ee722466d8df0d6270010a8db4 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 16 Jun 2017 10:39:51 -0400 Subject: [PATCH 2/7] Improve the upgrade screen. // FREEBIE --- Signal/src/AppDelegate.m | 32 ++++++++++++++----- .../translations/en.lproj/Localizable.strings | 5 ++- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index c7eaa4f03..943aa713b 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -214,14 +214,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]; } } diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index bacb91fc5..71b85b25d 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 couple of minutes. Please be patient."; + +/* 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 */ From f9fcbad1aae7ef8ce87e9664edfc5cbf1adbb1e4 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 16 Jun 2017 10:52:36 -0400 Subject: [PATCH 3/7] =?UTF-8?q?Add=20a=20=E2=80=9Clast=20app=20completed?= =?UTF-8?q?=20launch=E2=80=9D=20version.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit // FREEBIE --- Signal/src/AppDelegate.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 943aa713b..5c57b5b7f 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -197,7 +197,7 @@ 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"]) { shouldShowUpgradeLabel = YES; @@ -735,6 +735,8 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; { DDLogInfo(@"databaseViewRegistrationComplete"); + [AppVersion.instance appLaunchDidComplete]; + [self ensureRootViewController]; } From 3e389675903213292b1609a83d3e051e629599b4 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 16 Jun 2017 11:00:20 -0400 Subject: [PATCH 4/7] Do not show database upgrade screen for unregistered users. // FREEBIE --- Signal/src/AppDelegate.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 5c57b5b7f..7d1596299 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -199,7 +199,8 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; BOOL shouldShowUpgradeLabel = NO; 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) { From d340c3262d54c9d6f9757e47aebb84a0660b2ae8 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 16 Jun 2017 11:16:46 -0400 Subject: [PATCH 5/7] Tweak the database upgrade copy. // FREEBIE --- Signal/translations/en.lproj/Localizable.strings | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index 71b85b25d..d263bb96c 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -329,7 +329,7 @@ "CREATE_NEW_GROUP" = "Create new group"; /* Subtitle shown while the app is updating its database. */ -"DATABASE_VIEW_OVERLAY_SUBTITLE" = "This can take a couple of minutes. Please be patient."; +"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"; From 3c28f15dbdf805675205558818ecbb5269a23e44 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 16 Jun 2017 11:59:35 -0400 Subject: [PATCH 6/7] Respond to CR. // FREEBIE --- .../ViewControllers/DebugUI/DebugUIMessages.m | 19 ++++++++----------- Signal/src/util/ThreadUtil.h | 1 + 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m index 26adc680a..8661dd57c 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m @@ -65,15 +65,15 @@ NS_ASSUME_NONNULL_BEGIN actionBlock:^{ [DebugUIMessages sendTinyAttachments:1000 thread:thread]; }], - [OWSTableItem itemWithTitle:@"Send fake 10 messages" + [OWSTableItem itemWithTitle:@"Create 10 fake messages" actionBlock:^{ [DebugUIMessages sendFakeMessages:10 thread:thread]; }], - [OWSTableItem itemWithTitle:@"Send fake 1k messages" + [OWSTableItem itemWithTitle:@"Create 1k fake messages" actionBlock:^{ [DebugUIMessages sendFakeMessages:1000 thread:thread]; }], - [OWSTableItem itemWithTitle:@"Send fake 10k messages" + [OWSTableItem itemWithTitle:@"Create 10k fake messages" actionBlock:^{ [DebugUIMessages sendFakeMessages:10 * 1000 thread:thread]; }], @@ -828,14 +828,11 @@ NS_ASSUME_NONNULL_BEGIN break; } case 3: { - OWSDisappearingMessagesConfiguration *configuration = - [OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:thread.uniqueId - transaction:transaction]; - TSOutgoingMessage *message = [[TSOutgoingMessage alloc] - initWithTimestamp:[NSDate ows_millisecondTimeStamp] - inThread:thread - isVoiceMessage:NO - expiresInSeconds:(configuration.isEnabled ? configuration.durationSeconds : 0)]; + TSOutgoingMessage *message = + [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] + inThread:thread + isVoiceMessage:NO + expiresInSeconds:0]; NSString *filename = @"test.mp3"; TSAttachmentStream *attachmentStream = diff --git a/Signal/src/util/ThreadUtil.h b/Signal/src/util/ThreadUtil.h index 544803394..a79199b57 100644 --- a/Signal/src/util/ThreadUtil.h +++ b/Signal/src/util/ThreadUtil.h @@ -54,6 +54,7 @@ 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 From 6444754cbb8518dcf83d35f03f7a3e69b049f548 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 16 Jun 2017 12:06:19 -0400 Subject: [PATCH 7/7] =?UTF-8?q?[SSK]=20Cache=20the=20attachments=20folder?= =?UTF-8?q?=20in=20TSAttachmentStream.=20Add=20isFirstLaunch=20method=20to?= =?UTF-8?q?=20AppVersion.=20Add=20a=20=E2=80=9Clast=20app=20completed=20la?= =?UTF-8?q?unch=E2=80=9D=20version.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit // FREEBIE --- Podfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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