prevent infinite loop if errors occur when automatically resetting the session

pull/248/head
Ryan ZHAO 5 years ago
parent 528f930a98
commit 8c565c7c5a

@ -164,14 +164,15 @@ public final class SessionManagementProtocol : NSObject {
// MARK: - Receiving
@objc(handleDecryptionError:forPublicKey:transaction:)
public static func handleDecryptionError(_ rawValue: Int32, for publicKey: String, using transaction: YapDatabaseReadWriteTransaction) {
let type = TSErrorMessageType(rawValue: rawValue)
public static func handleDecryptionError(_ errorMessage: TSErrorMessage, for publicKey: String, using transaction: YapDatabaseReadWriteTransaction) {
let type = errorMessage.errorType
let masterPublicKey = storage.getMasterHexEncodedPublicKey(for: publicKey, in: transaction) ?? publicKey
let thread = TSContactThread.getOrCreateThread(withContactId: masterPublicKey, transaction: transaction)
let restorationTimeInMs = UInt64(storage.getRestorationTime() * 1000)
// Show the session reset prompt upon certain errors
switch type {
case .noSession, .invalidMessage, .invalidKeyException:
if storage.getRestorationTime() > 0 {
if restorationTimeInMs > errorMessage.timestamp {
// Automatically rebuild session after restoration
sendSessionRequestIfNeeded(to: publicKey, using: transaction)
} else {

@ -690,7 +690,7 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes
OWSAssertDebug(errorMessage);
if (errorMessage != nil) {
[LKSessionManagementProtocol handleDecryptionError:errorMessage.errorType forPublicKey:envelope.source transaction:transaction];
[LKSessionManagementProtocol handleDecryptionError:errorMessage forPublicKey:envelope.source transaction:transaction];
if (![LKSessionMetaProtocol isErrorMessageBeforeRestoration:errorMessage]) {
[errorMessage saveWithTransaction:transaction];
[self notifyUserForErrorMessage:errorMessage envelope:envelope transaction:transaction];

Loading…
Cancel
Save