Show session restore banner

pull/71/head
Mikunj 5 years ago
parent e38976b082
commit 58a260aac5

@ -162,6 +162,7 @@ typedef enum : NSUInteger {
@property (nonatomic) NSCache *cellMediaCache; @property (nonatomic) NSCache *cellMediaCache;
@property (nonatomic) ConversationHeaderView *headerView; @property (nonatomic) ConversationHeaderView *headerView;
@property (nonatomic, nullable) UIView *bannerView; @property (nonatomic, nullable) UIView *bannerView;
@property (nonatomic, nullable) UIView *restoreSessionBannerView;
@property (nonatomic, nullable) OWSDisappearingMessagesConfiguration *disappearingMessagesConfiguration; @property (nonatomic, nullable) OWSDisappearingMessagesConfiguration *disappearingMessagesConfiguration;
// Back Button Unread Count // Back Button Unread Count
@ -506,7 +507,7 @@ typedef enum : NSUInteger {
// Ensure thread instance is up to date // Ensure thread instance is up to date
[self.thread reload]; [self.thread reload];
// Update UI // Update UI
// TODO: Show banner here [self updateSessionRestoreBanner];
} }
- (void)peekSetup - (void)peekSetup
@ -960,17 +961,37 @@ typedef enum : NSUInteger {
return [result copy]; 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 - (void)ensureBannerState
{ {
// This method should be called rarely, so it's simplest to discard and // This method should be called rarely, so it's simplest to discard and
// rebuild the indicator view every time. // rebuild the indicator view every time.
[self.bannerView removeFromSuperview]; [self.bannerView removeFromSuperview];
self.bannerView = nil; self.bannerView = nil;
if (self.userHasScrolled) { if (self.userHasScrolled) {
return; return;
} }
NSArray<NSString *> *noLongerVerifiedRecipientIds = [self noLongerVerifiedRecipientIds]; NSArray<NSString *> *noLongerVerifiedRecipientIds = [self noLongerVerifiedRecipientIds];
if (noLongerVerifiedRecipientIds.count > 0) { 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 - (void)noLongerVerifiedBannerViewWasTapped:(UIGestureRecognizer *)sender
{ {
if (sender.state == UIGestureRecognizerStateRecognized) { if (sender.state == UIGestureRecognizerStateRecognized) {

@ -689,13 +689,14 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
NSString *masterHexEncodedPublicKey = [LKDatabaseUtilities getMasterHexEncodedPublicKeyFor:envelope.source in: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 // Trigger a session restore prompt if we get specific errors
if (errorMessage.errorType == TSErrorMessageNoSession || if (errorMessage.errorType == TSErrorMessageNoSession ||
errorMessage.errorType == TSErrorMessageInvalidMessage || errorMessage.errorType == TSErrorMessageInvalidMessage ||
errorMessage.errorType == TSErrorMessageInvalidKeyException) { 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 transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
NSString *masterHexEncodedPublicKey = [LKDatabaseUtilities getMasterHexEncodedPublicKeyFor:envelope.source in: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 [SSKEnvironment.shared.notificationsManager notifyUserForErrorMessage:errorMessage
thread:contactThread thread:contactThread
transaction:transaction]; transaction:transaction];

Loading…
Cancel
Save