From 58a260aac50e241419d81b9fa884cdec4944e3eb Mon Sep 17 00:00:00 2001 From: Mikunj Date: Tue, 10 Dec 2019 10:57:15 +1100 Subject: [PATCH] Show session restore banner --- .../ConversationViewController.m | 37 +++++++++++++++++-- .../src/Messages/OWSMessageDecrypter.m | 8 ++-- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index c43e40d74..58554ad63 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -162,6 +162,7 @@ typedef enum : NSUInteger { @property (nonatomic) NSCache *cellMediaCache; @property (nonatomic) ConversationHeaderView *headerView; @property (nonatomic, nullable) UIView *bannerView; +@property (nonatomic, nullable) UIView *restoreSessionBannerView; @property (nonatomic, nullable) OWSDisappearingMessagesConfiguration *disappearingMessagesConfiguration; // Back Button Unread Count @@ -506,7 +507,7 @@ typedef enum : NSUInteger { // Ensure thread instance is up to date [self.thread reload]; // Update UI - // TODO: Show banner here + [self updateSessionRestoreBanner]; } - (void)peekSetup @@ -960,17 +961,37 @@ typedef enum : NSUInteger { return [result copy]; } +- (void)updateSessionRestoreBanner { + BOOL isContactThread = [self.thread isKindOfClass:[TSContactThread class]]; + BOOL shouldRemoveBanner = !isContactThread; + if (isContactThread) { + TSContactThread *thread = (TSContactThread *)self.thread; + if (thread.sessionRestoreDevices.count > 0) { + if (self.restoreSessionBannerView) { + // TODO: Create banner here + } + } else { + shouldRemoveBanner = true; + } + } + + if (shouldRemoveBanner && self.restoreSessionBannerView) { + [self.restoreSessionBannerView removeFromSuperview]; + self.restoreSessionBannerView = nil; + } +} + - (void)ensureBannerState { // This method should be called rarely, so it's simplest to discard and // rebuild the indicator view every time. [self.bannerView removeFromSuperview]; self.bannerView = nil; - + if (self.userHasScrolled) { return; } - + NSArray *noLongerVerifiedRecipientIds = [self noLongerVerifiedRecipientIds]; if (noLongerVerifiedRecipientIds.count > 0) { @@ -1131,6 +1152,16 @@ typedef enum : NSUInteger { }]; } +- (void)restoreSession { + if ([self.thread isKindOfClass:[TSContactThread class]]) { + TSContactThread *thread = (TSContactThread *)self.thread; + NSArray *devices = thread.sessionRestoreDevices; + // TODO: Send session restore to all devices + // TODO: Add message saying session restore was sent + [thread removeAllRessionRestoreDevicesWithTransaction:nil]; + } +} + - (void)noLongerVerifiedBannerViewWasTapped:(UIGestureRecognizer *)sender { if (sender.state == UIGestureRecognizerStateRecognized) { diff --git a/SignalServiceKit/src/Messages/OWSMessageDecrypter.m b/SignalServiceKit/src/Messages/OWSMessageDecrypter.m index 1cdc95153..78cadcd99 100644 --- a/SignalServiceKit/src/Messages/OWSMessageDecrypter.m +++ b/SignalServiceKit/src/Messages/OWSMessageDecrypter.m @@ -689,13 +689,14 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes transaction:(YapDatabaseReadWriteTransaction *)transaction { NSString *masterHexEncodedPublicKey = [LKDatabaseUtilities getMasterHexEncodedPublicKeyFor:envelope.source in:transaction]; - TSThread *contactThread = [TSContactThread getOrCreateThreadWithContactId:masterHexEncodedPublicKey transaction:transaction]; + NSString *hexEncodedPublicKey = masterHexEncodedPublicKey ?: envelope.source; + TSThread *contactThread = [TSContactThread getOrCreateThreadWithContactId:hexEncodedPublicKey transaction:transaction]; // Trigger a session restore prompt if we get specific errors if (errorMessage.errorType == TSErrorMessageNoSession || errorMessage.errorType == TSErrorMessageInvalidMessage || errorMessage.errorType == TSErrorMessageInvalidKeyException) { - [((TSContactThread *) contactThread) addSessionRestoreDevice:masterHexEncodedPublicKey transaction:transaction]; + [((TSContactThread *) contactThread) addSessionRestoreDevice:hexEncodedPublicKey transaction:transaction]; } } @@ -704,7 +705,8 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes transaction:(YapDatabaseReadWriteTransaction *)transaction { NSString *masterHexEncodedPublicKey = [LKDatabaseUtilities getMasterHexEncodedPublicKeyFor:envelope.source in:transaction]; - TSThread *contactThread = [TSContactThread getOrCreateThreadWithContactId:masterHexEncodedPublicKey transaction:transaction]; + NSString *hexEncodedPublicKey = masterHexEncodedPublicKey ?: envelope.source; + TSThread *contactThread = [TSContactThread getOrCreateThreadWithContactId:hexEncodedPublicKey transaction:transaction]; [SSKEnvironment.shared.notificationsManager notifyUserForErrorMessage:errorMessage thread:contactThread transaction:transaction];