Skip to content

Commit

Permalink
Merge pull request #71 from loki-project/session-restore
Browse files Browse the repository at this point in the history
Session restore
  • Loading branch information
nielsandriesse committed Jan 24, 2020
2 parents 52dda93 + a433d13 commit 8209fa1
Show file tree
Hide file tree
Showing 27 changed files with 396 additions and 70 deletions.
2 changes: 1 addition & 1 deletion Pods
Submodule Pods updated from 80b9ef to 3a470c
4 changes: 4 additions & 0 deletions Signal.xcodeproj/project.pbxproj
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
2400888E239F30A600305217 /* SessionRestorationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2400888D239F30A600305217 /* SessionRestorationView.swift */; };
241C6314231F64C000B4198E /* JazzIcon.swift in Sources */ = {isa = PBXBuildFile; fileRef = 241C630E231F5AAC00B4198E /* JazzIcon.swift */; };
241C6315231F64CE00B4198E /* CGFloat+Rounding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 241C6312231F5F1D00B4198E /* CGFloat+Rounding.swift */; };
241C6316231F64CE00B4198E /* UIColor+Helper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 241C6310231F5C4400B4198E /* UIColor+Helper.swift */; };
Expand Down Expand Up @@ -709,6 +710,7 @@
0F94C85CB0B235DA37F68ED0 /* Pods_SignalShareExtension.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SignalShareExtension.framework; sourceTree = BUILT_PRODUCTS_DIR; };
1C93CF3971B64E8B6C1F9AC1 /* Pods-SignalShareExtension.test.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SignalShareExtension.test.xcconfig"; path = "Pods/Target Support Files/Pods-SignalShareExtension/Pods-SignalShareExtension.test.xcconfig"; sourceTree = "<group>"; };
1CE3CD5C23334683BDD3D78C /* Pods-Signal.test.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Signal.test.xcconfig"; path = "Pods/Target Support Files/Pods-Signal/Pods-Signal.test.xcconfig"; sourceTree = "<group>"; };
2400888D239F30A600305217 /* SessionRestorationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionRestorationView.swift; sourceTree = "<group>"; };
241C630E231F5AAC00B4198E /* JazzIcon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JazzIcon.swift; sourceTree = "<group>"; };
241C6310231F5C4400B4198E /* UIColor+Helper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Helper.swift"; sourceTree = "<group>"; };
241C6312231F5F1D00B4198E /* CGFloat+Rounding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CGFloat+Rounding.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2783,6 +2785,7 @@
B85357BE23A1AE0800AAF6CD /* SeedReminderView.swift */,
B85357C023A1B81900AAF6CD /* SeedReminderViewDelegate.swift */,
B8BB82B82394911B00BA5194 /* Separator.swift */,
2400888D239F30A600305217 /* SessionRestorationView.swift */,
B8CCF638239721E20091D419 /* TabBar.swift */,
B8BB82B423947F2D00BA5194 /* TextField.swift */,
);
Expand Down Expand Up @@ -3980,6 +3983,7 @@
B8162F0322891AD600D46544 /* FriendRequestView.swift in Sources */,
458E38371D668EBF0094BD24 /* OWSDeviceProvisioningURLParser.m in Sources */,
34B6A905218B4C91007C4606 /* TypingIndicatorInteraction.swift in Sources */,
2400888E239F30A600305217 /* SessionRestorationView.swift in Sources */,
B886B4A72398B23E00211ABE /* QRCodeVC.swift in Sources */,
4517642B1DE939FD00EDB8B9 /* ContactCell.swift in Sources */,
34EA69402194933900702471 /* MediaDownloadView.swift in Sources */,
Expand Down
14 changes: 7 additions & 7 deletions Signal/src/Loki/Components/FriendRequestView.swift
Expand Up @@ -114,10 +114,10 @@ final class FriendRequestView : UIView {
let format: String = {
switch (message.friendRequestStatus) {
case .none, .sendingOrFailed: preconditionFailure()
case .pending: return NSLocalizedString("%@ sent you a message request", comment: "")
case .accepted: return NSLocalizedString("You've accepted %@'s message request", comment: "")
case .declined: return NSLocalizedString("You've declined %@'s message request", comment: "")
case .expired: return NSLocalizedString("%@'s message request has expired", comment: "")
case .pending: return NSLocalizedString("%@ sent you a session request", comment: "")
case .accepted: return NSLocalizedString("You've accepted %@'s session request", comment: "")
case .declined: return NSLocalizedString("You've declined %@'s session request", comment: "")
case .expired: return NSLocalizedString("%@'s session request has expired", comment: "")
default: preconditionFailure()
}
}()
Expand All @@ -130,10 +130,10 @@ final class FriendRequestView : UIView {
switch (message.friendRequestStatus) {
case .none: preconditionFailure()
case .sendingOrFailed: return nil
case .pending: return NSLocalizedString("You've sent %@ a message request", comment: "")
case .accepted: return NSLocalizedString("%@ accepted your message request", comment: "")
case .pending: return NSLocalizedString("You've sent %@ a session request", comment: "")
case .accepted: return NSLocalizedString("%@ accepted your session request", comment: "")
case .declined: preconditionFailure()
case .expired: return NSLocalizedString("Your message request to %@ has expired", comment: "")
case .expired: return NSLocalizedString("Your session request to %@ has expired", comment: "")
default: preconditionFailure()
}
}()
Expand Down
84 changes: 84 additions & 0 deletions Signal/src/Loki/Components/SessionRestorationView.swift
@@ -0,0 +1,84 @@

@objc(LKSessionRestorationView)
final class SessionRestorationView : UIView {
private let thread: TSThread
@objc public var onRestore: (() -> Void)?
@objc public var onDismiss: (() -> Void)?

// MARK: Lifecycle
@objc init(thread: TSThread) {
self.thread = thread;
super.init(frame: CGRect.zero)
initialize()
}

required init?(coder: NSCoder) { fatalError("Using SessionRestorationView.init(coder:) isn't allowed. Use SessionRestorationView.init(thread:) instead.") }
override init(frame: CGRect) { fatalError("Using SessionRestorationView.init(frame:) isn't allowed. Use SessionRestorationView.init(thread:) instead.") }

private func initialize() {
// Set up background
backgroundColor = Colors.modalBackground
layer.cornerRadius = Values.modalCornerRadius
layer.masksToBounds = false
layer.borderColor = Colors.modalBorder.cgColor
layer.borderWidth = Values.borderThickness
layer.shadowColor = UIColor.black.cgColor
layer.shadowRadius = 8
layer.shadowOpacity = 0.64
// Set up title label
let titleLabel = UILabel()
titleLabel.textColor = Colors.text
titleLabel.font = .boldSystemFont(ofSize: Values.mediumFontSize)
titleLabel.text = NSLocalizedString("Session Out of Sync", comment: "")
titleLabel.numberOfLines = 0
titleLabel.lineBreakMode = .byWordWrapping
titleLabel.textAlignment = .center
// Set up explanation label
let explanationLabel = UILabel()
explanationLabel.textColor = Colors.text
explanationLabel.font = .systemFont(ofSize: Values.smallFontSize)
explanationLabel.text = NSLocalizedString("Would you like to restore your session?", comment: "")
explanationLabel.numberOfLines = 0
explanationLabel.textAlignment = .center
explanationLabel.lineBreakMode = .byWordWrapping
// Set up restore button
let restoreButton = UIButton()
restoreButton.set(.height, to: Values.mediumButtonHeight)
restoreButton.layer.cornerRadius = Values.modalButtonCornerRadius
restoreButton.backgroundColor = Colors.accent
restoreButton.titleLabel!.font = .systemFont(ofSize: Values.smallFontSize)
restoreButton.setTitleColor(Colors.text, for: UIControl.State.normal)
restoreButton.setTitle(NSLocalizedString("Restore", comment: ""), for: UIControl.State.normal)
restoreButton.addTarget(self, action: #selector(restore), for: UIControl.Event.touchUpInside)
// Set up dismiss button
let dismissButton = UIButton()
dismissButton.set(.height, to: Values.mediumButtonHeight)
dismissButton.layer.cornerRadius = Values.modalButtonCornerRadius
dismissButton.backgroundColor = Colors.buttonBackground
dismissButton.titleLabel!.font = .systemFont(ofSize: Values.smallFontSize)
dismissButton.setTitleColor(Colors.text, for: UIControl.State.normal)
dismissButton.setTitle(NSLocalizedString("Dismiss", comment: ""), for: UIControl.State.normal)
dismissButton.addTarget(self, action: #selector(dismiss), for: UIControl.Event.touchUpInside)
// Set up button stack view
let buttonStackView = UIStackView(arrangedSubviews: [ dismissButton, restoreButton ])
buttonStackView.axis = .horizontal
buttonStackView.spacing = Values.mediumSpacing
buttonStackView.distribution = .fillEqually
// Set up main stack view
let mainStackView = UIStackView(arrangedSubviews: [ titleLabel, explanationLabel, buttonStackView ])
mainStackView.axis = .vertical
mainStackView.spacing = Values.smallSpacing
addSubview(mainStackView)
mainStackView.pin(to: self, withInset: Values.mediumSpacing)
// Update explanation label if possible
if let contactID = thread.contactIdentifier() {
let displayName = DisplayNameUtilities.getPrivateChatDisplayName(for: contactID) ?? contactID
explanationLabel.text = String(format: NSLocalizedString("Would you like to restore your session with %@?", comment: ""), displayName)
}
}

// MARK: Interaction
@objc private func restore() { onRestore?() }

@objc private func dismiss() { onDismiss?() }
}
1 change: 1 addition & 0 deletions Signal/src/Loki/View Controllers/RestoreVC.swift
Expand Up @@ -176,6 +176,7 @@ final class RestoreVC : UIViewController {
databaseConnection.setObject(seed.toHexString(), forKey: "LKLokiSeed", inCollection: OWSPrimaryStorageIdentityKeyStoreCollection)
databaseConnection.setObject(keyPair, forKey: OWSPrimaryStorageIdentityKeyStoreIdentityKey, inCollection: OWSPrimaryStorageIdentityKeyStoreCollection)
TSAccountManager.sharedInstance().phoneNumberAwaitingVerification = keyPair.hexEncodedPublicKey
OWSPrimaryStorage.shared().setRestorationTime(Date().timeIntervalSince1970)
mnemonicTextField.resignFirstResponder()
Timer.scheduledTimer(withTimeInterval: 0.25, repeats: false) { _ in
let displayNameVC = DisplayNameVC()
Expand Down
Expand Up @@ -431,12 +431,8 @@ - (nullable SystemMessageAction *)actionForErrorMessage:(TSErrorMessage *)messag
}];
case TSErrorMessageMissingKeyId:
case TSErrorMessageNoSession:
return nil;
case TSErrorMessageInvalidMessage:
return [SystemMessageAction actionWithTitle:NSLocalizedString(@"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON", @"")
block:^{
[weakSelf.delegate tappedCorruptedMessage:message];
}];
return nil;
case TSErrorMessageDuplicateMessage:
case TSErrorMessageInvalidVersion:
return nil;
Expand Down

0 comments on commit 8209fa1

Please sign in to comment.