Show session restore banner

This commit is contained in:
Mikunj 2019-12-10 10:57:15 +11:00
parent e38976b082
commit 58a260aac5
2 changed files with 39 additions and 6 deletions

View File

@ -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<NSString *> *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) {

View File

@ -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];