From 99229800a1d2e4c9cc785803cc653f623de7b913 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 4 Sep 2020 10:07:05 +1000 Subject: [PATCH 1/2] Add manual session reset button --- .../ConversationViewController.m | 8 +++-- .../OWSConversationSettingsViewController.m | 29 +++++++++++++++++++ .../src/Messages/OWSMessageDecrypter.m | 2 +- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index d0319c386..64a75c45a 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -1236,11 +1236,15 @@ typedef enum : NSUInteger { } - (void)restoreSession { + if (![self.thread isKindOfClass:TSContactThread.class]) { return; } + TSContactThread *thread = (TSContactThread *)self.thread; + __weak ConversationViewController *weakSelf = self; dispatch_async(dispatch_get_main_queue(), ^{ [LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { - [LKSessionManagementProtocol startSessionResetInThread:self.thread transaction:transaction]; + [thread addSessionRestoreDevice:thread.contactIdentifier transaction:transaction]; + [LKSessionManagementProtocol startSessionResetInThread:thread transaction:transaction]; } error:nil]; - [self updateSessionRestoreBanner]; + [weakSelf updateSessionRestoreBanner]; }); } diff --git a/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m b/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m index 5e7eb4304..8246b2536 100644 --- a/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m +++ b/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m @@ -860,6 +860,15 @@ const CGFloat kIconViewLength = 24; return cell; } actionBlock:nil]]; + + [mainSection addItem: + [OWSTableItem itemWithCustomCellBlock:^{ + NSString *title = @"Reset Secure Session"; + NSString *accessibilityIdentifier = ACCESSIBILITY_IDENTIFIER_WITH_NAME(OWSConversationSettingsViewController, @"reset_secure_session"); + return [weakSelf disclosureCellWithName:title iconName:@"system_message_security" accessibilityIdentifier:accessibilityIdentifier]; + } + actionBlock:^{ [weakSelf resetSecureSession]; }] + ]; } self.contents = contents; @@ -1421,6 +1430,26 @@ const CGFloat kIconViewLength = 24; [self.conversationSettingsViewDelegate conversationSettingsDidRequestConversationSearch:self]; } +- (void)resetSecureSession +{ + if (![self.thread isKindOfClass:TSContactThread.class]) { return; } + TSContactThread *thread = (TSContactThread *)self.thread; + __weak OWSConversationSettingsViewController *weakSelf = self; + NSString *message = @"This may help if you're having encryption problems in this conversation. Your messages will be kept."; + UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Reset Secure Session?" message:message preferredStyle:UIAlertControllerStyleAlert]; + [alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"TXT_CANCEL_TITLE", @"") style:UIAlertActionStyleDefault handler:nil]]; + [alert addAction:[UIAlertAction actionWithTitle:@"Reset" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + dispatch_async(dispatch_get_main_queue(), ^{ + [LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { + [thread addSessionRestoreDevice:thread.contactIdentifier transaction:transaction]; + [LKSessionManagementProtocol startSessionResetInThread:thread transaction:transaction]; + } error:nil]; + [weakSelf.navigationController popViewControllerAnimated:YES]; + }); + }]]; + [self presentViewController:alert animated:YES completion:nil]; +} + #pragma mark - Notifications - (void)identityStateDidChange:(NSNotification *)notification diff --git a/SignalServiceKit/src/Messages/OWSMessageDecrypter.m b/SignalServiceKit/src/Messages/OWSMessageDecrypter.m index 3a84b0f80..9c676640e 100644 --- a/SignalServiceKit/src/Messages/OWSMessageDecrypter.m +++ b/SignalServiceKit/src/Messages/OWSMessageDecrypter.m @@ -581,7 +581,7 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes return; } - // FIXME: This is a temporary patch for bad mac issues. At least with this people will be able to message again. We have to figure out the root cause of the issue though. + // Attempt to recover automatically if ([decryptError userInfo][NSUnderlyingErrorKey] != nil) { NSDictionary *underlyingErrorUserInfo = [[decryptError userInfo][NSUnderlyingErrorKey] userInfo]; if (underlyingErrorUserInfo[SCKExceptionWrapperUnderlyingExceptionKey] != nil) { From c98eb5fca04aca4aa452aeaebb56c92ace832d4a Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 4 Sep 2020 10:15:33 +1000 Subject: [PATCH 2/2] Add version number to settings --- Signal/src/Loki/View Controllers/SettingsVC.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Signal/src/Loki/View Controllers/SettingsVC.swift b/Signal/src/Loki/View Controllers/SettingsVC.swift index d59257085..4ea1833b8 100644 --- a/Signal/src/Loki/View Controllers/SettingsVC.swift +++ b/Signal/src/Loki/View Controllers/SettingsVC.swift @@ -120,8 +120,18 @@ final class SettingsVC : BaseVC, AvatarViewHelperDelegate { getSettingButtons().forEach { settingButtonOrSeparator in settingButtonsStackView.addArrangedSubview(settingButtonOrSeparator) } + // Set up version label + let versionLabel = UILabel() + versionLabel.textColor = Colors.text.withAlphaComponent(Values.unimportantElementOpacity) + versionLabel.font = .systemFont(ofSize: Values.verySmallFontSize) + versionLabel.numberOfLines = 0 + versionLabel.textAlignment = .center + versionLabel.lineBreakMode = .byCharWrapping + let version = Bundle.main.infoDictionary!["CFBundleShortVersionString"]! + let buildNumber = Bundle.main.infoDictionary!["CFBundleVersion"]! + versionLabel.text = "Version \(version) (\(buildNumber))" // Set up stack view - let stackView = UIStackView(arrangedSubviews: [ topStackView, settingButtonsStackView ]) + let stackView = UIStackView(arrangedSubviews: [ topStackView, settingButtonsStackView, versionLabel ]) stackView.axis = .vertical stackView.spacing = Values.largeSpacing stackView.alignment = .fill