Multiple refinements around verification.

* Check for identity key before presenting fingerprint view.
* Show verification state in a separate subtitle in conversation view.
* Let users verify from group members view.

// FREEBIE
pull/1/head
Matthew Chen 7 years ago
parent 11ca51c95f
commit 7da28bd5dc

@ -1273,11 +1273,7 @@ typedef enum : NSUInteger {
// return from FingerprintViewController.
[self dismissKeyBoard];
FingerprintViewController *fingerprintViewController = [FingerprintViewController new];
[fingerprintViewController configureWithRecipientId:recipientId];
UINavigationController *navigationController =
[[UINavigationController alloc] initWithRootViewController:fingerprintViewController];
[self presentViewController:navigationController animated:YES completion:nil];
[FingerprintViewController showVerificationViewFromViewController:self recipientId:recipientId];
}
#pragma mark - Calls

@ -6,7 +6,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface FingerprintViewController : UIViewController
- (void)configureWithRecipientId:(NSString *)recipientId NS_SWIFT_NAME(configure(recipientId:));
+ (void)showVerificationViewFromViewController:(UIViewController *)viewController recipientId:(NSString *)recipientId;
@end

@ -89,6 +89,27 @@ typedef void (^CustomLayoutBlock)();
@implementation FingerprintViewController
+ (void)showVerificationViewFromViewController:(UIViewController *)viewController recipientId:(NSString *)recipientId
{
OWSAssert(recipientId.length > 0);
OWSRecipientIdentity *_Nullable recipientIdentity =
[[OWSIdentityManager sharedManager] recipientIdentityForRecipientId:recipientId];
if (!recipientIdentity) {
[OWSAlerts showAlertWithTitle:NSLocalizedString(@"CANT_VERIFY_IDENTITY_ALERT_TITLE",
@"Title for alert explaining that a user cannot be verified.")
message:NSLocalizedString(@"CANT_VERIFY_IDENTITY_ALERT_MESSAGE",
@"Message for alert explaining that a user cannot be verified.")];
return;
}
FingerprintViewController *fingerprintViewController = [FingerprintViewController new];
[fingerprintViewController configureWithRecipientId:recipientId];
UINavigationController *navigationController =
[[UINavigationController alloc] initWithRootViewController:fingerprintViewController];
[viewController presentViewController:navigationController animated:YES completion:nil];
}
- (instancetype)init
{
self = [super init];
@ -493,6 +514,8 @@ typedef void (^CustomLayoutBlock)();
:self.identityKey
recipientId:self.recipientId
sendSyncMessage:YES];
[self dismissViewControllerAnimated:YES completion:nil];
}
}

@ -240,15 +240,16 @@ NS_ASSUME_NONNULL_BEGIN
firstSection.customHeaderHeight = @(100.f);
if (!self.isGroupThread && self.thread.hasSafetyNumbers) {
[firstSection
addItem:[OWSTableItem itemWithCustomCellBlock:^{
return [weakSelf disclosureCellWithName:NSLocalizedString(@"VERIFY_PRIVACY",
@"table cell label in conversation settings")
iconName:@"table_ic_verify"];
}
actionBlock:^{
[weakSelf showVerificationView];
}]];
[firstSection addItem:[OWSTableItem itemWithCustomCellBlock:^{
return [weakSelf
disclosureCellWithName:
NSLocalizedString(@"VERIFY_PRIVACY",
@"Label for button or row which allows users to verify the safety number of another user.")
iconName:@"table_ic_verify"];
}
actionBlock:^{
[weakSelf showVerificationView];
}]];
}
[firstSection
@ -549,55 +550,51 @@ NS_ASSUME_NONNULL_BEGIN
[threadTitleLabel autoPinEdgeToSuperviewEdge:ALEdgeLeft];
[threadTitleLabel autoPinEdgeToSuperviewEdge:ALEdgeRight];
const CGFloat kSubtitlePointSize = 12.f;
NSMutableAttributedString *subtitle = nil;
__block UIView *lastTitleView = threadTitleLabel;
if (![self isGroupThread]) {
const CGFloat kSubtitlePointSize = 12.f;
void (^addSubtitle)(NSAttributedString *) = ^(NSAttributedString *subtitle) {
UILabel *subtitleLabel = [UILabel new];
subtitleLabel.textColor = [UIColor ows_darkGrayColor];
subtitleLabel.font = [UIFont ows_regularFontWithSize:kSubtitlePointSize];
subtitleLabel.attributedText = subtitle;
subtitleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
[threadNameView addSubview:subtitleLabel];
[subtitleLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:lastTitleView];
[subtitleLabel autoPinEdgeToSuperviewEdge:ALEdgeLeft];
lastTitleView = subtitleLabel;
};
NSString *recipientId = self.thread.contactIdentifier;
BOOL isVerified = [[OWSIdentityManager sharedManager] verificationStateForRecipientId:recipientId]
== OWSVerificationStateVerified;
BOOL hasName = ![self.thread.name isEqualToString:recipientId];
if (isVerified || hasName) {
subtitle = [NSMutableAttributedString new];
if (isVerified) {
// "checkmark"
[subtitle appendAttributedString:[[NSAttributedString alloc]
initWithString:@"\uf00c "
attributes:@{
NSFontAttributeName :
[UIFont ows_fontAwesomeFont:kSubtitlePointSize],
}]];
}
BOOL hasName = ![self.thread.name isEqualToString:recipientId];
if (hasName) {
NSAttributedString *subtitle = [[NSAttributedString alloc]
initWithString:[PhoneNumber
bestEffortFormatPartialUserSpecifiedTextToLookLikeAPhoneNumber:recipientId]];
addSubtitle(subtitle);
}
if (hasName) {
[subtitle
appendAttributedString:
[[NSAttributedString alloc]
initWithString:[PhoneNumber bestEffortFormatPartialUserSpecifiedTextToLookLikeAPhoneNumber:
recipientId]]];
} else {
[subtitle
appendAttributedString:[[NSAttributedString alloc]
initWithString:NSLocalizedString(@"PRIVACY_IDENTITY_IS_VERIFIED_BADGE",
@"Badge indicating that the user is verified.")]];
}
BOOL isVerified = [[OWSIdentityManager sharedManager] verificationStateForRecipientId:recipientId]
== OWSVerificationStateVerified;
if (isVerified) {
NSMutableAttributedString *subtitle = [NSMutableAttributedString new];
// "checkmark"
[subtitle appendAttributedString:[[NSAttributedString alloc]
initWithString:@"\uf00c "
attributes:@{
NSFontAttributeName :
[UIFont ows_fontAwesomeFont:kSubtitlePointSize],
}]];
[subtitle appendAttributedString:[[NSAttributedString alloc]
initWithString:NSLocalizedString(@"PRIVACY_IDENTITY_IS_VERIFIED_BADGE",
@"Badge indicating that the user is verified.")]];
addSubtitle(subtitle);
}
}
if (subtitle) {
UILabel *threadSubtitleLabel = [UILabel new];
threadSubtitleLabel.textColor = [UIColor ows_darkGrayColor];
threadSubtitleLabel.font = [UIFont ows_regularFontWithSize:kSubtitlePointSize];
threadSubtitleLabel.attributedText = subtitle;
threadSubtitleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
[threadNameView addSubview:threadSubtitleLabel];
[threadSubtitleLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom];
[threadSubtitleLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:threadTitleLabel];
[threadSubtitleLabel autoPinEdgeToSuperviewEdge:ALEdgeLeft];
} else {
[threadTitleLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom];
}
[lastTitleView autoPinEdgeToSuperviewEdge:ALEdgeBottom];
[firstSectionHeader
addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self
@ -679,11 +676,10 @@ NS_ASSUME_NONNULL_BEGIN
- (void)showVerificationView
{
FingerprintViewController *fingerprintViewController = [FingerprintViewController new];
[fingerprintViewController configureWithRecipientId:self.thread.contactIdentifier];
UINavigationController *navigationController =
[[UINavigationController alloc] initWithRootViewController:fingerprintViewController];
[self presentViewController:navigationController animated:YES completion:nil];
NSString *recipientId = self.thread.contactIdentifier;
OWSAssert(recipientId.length > 0);
[FingerprintViewController showVerificationViewFromViewController:self recipientId:recipientId];
}
- (void)showGroupMembersView

@ -63,7 +63,7 @@ class SafetyNumberConfirmationAlert: NSObject {
}
actionSheetController.addAction(confirmAction)
let showSafetyNumberAction = UIAlertAction(title: NSLocalizedString("VERIFY_PRIVACY", comment: "Action sheet item"), style: .default) { _ in
let showSafetyNumberAction = UIAlertAction(title: NSLocalizedString("VERIFY_PRIVACY", comment: "Label for button or row which allows users to verify the safety number of another user."), style: .default) { _ in
Logger.info("\(self.TAG) Opted to show Safety Number for identity: \(untrustedIdentity)")
self.presentSafetyNumberViewController(theirIdentityKey: untrustedIdentity.identityKey,
@ -82,10 +82,11 @@ class SafetyNumberConfirmationAlert: NSObject {
}
public func presentSafetyNumberViewController(theirIdentityKey: Data, theirRecipientId: String, theirDisplayName: String, completion: (() -> Void)? = nil) {
let fingerprintViewController = FingerprintViewController()
fingerprintViewController.configure(recipientId: theirRecipientId)
let navigationController = UINavigationController(rootViewController:fingerprintViewController)
UIApplication.shared.frontmostViewController?.present(navigationController, animated: true, completion: completion)
guard let fromViewController = UIApplication.shared.frontmostViewController else {
Logger.info("\(self.TAG) Missing frontmostViewController")
return
}
FingerprintViewController.showVerificationView(from:fromViewController, recipientId:theirRecipientId)
}
private func untrustedIdentityForSending(recipientIds: [String]) -> OWSRecipientIdentity? {

@ -274,6 +274,14 @@ NS_ASSUME_NONNULL_BEGIN
handler:^(UIAlertAction *_Nonnull action) {
[self callMember:recipientId];
}]];
[actionSheetController
addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"VERIFY_PRIVACY",
@"Label for button or row which allows users to verify the "
@"safety number of another user.")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *_Nonnull action) {
[self verifySafetyNumber:recipientId];
}]];
}
UIAlertAction *dismissAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"TXT_CANCEL_TITLE", @"")
@ -305,6 +313,13 @@ NS_ASSUME_NONNULL_BEGIN
[Environment callUserWithIdentifier:recipientId];
}
- (void)verifySafetyNumber:(NSString *)recipientId
{
OWSAssert(recipientId.length > 0);
[FingerprintViewController showVerificationViewFromViewController:self recipientId:recipientId];
}
#pragma mark - ContactsViewHelperDelegate
- (void)contactsViewHelperDidUpdateContacts

@ -226,6 +226,12 @@
/* The generic name used for calls if CallKit privacy is enabled */
"CALLKIT_ANONYMOUS_CONTACT_NAME" = "Signal User";
/* Message for alert explaining that a user cannot be verified. */
"CANT_VERIFY_IDENTITY_ALERT_MESSAGE" = "This user can't be verified until you've exchanged messages with them.";
/* Title for alert explaining that a user cannot be verified. */
"CANT_VERIFY_IDENTITY_ALERT_TITLE" = "Error";
/* Title for the 'censorship circumvention country' view. */
"CENSORSHIP_CIRCUMVENTION_COUNTRY_VIEW_TITLE" = "Select Country";
@ -1438,8 +1444,7 @@
/* Generic message indicating that verification state changed for a given user. */
"VERIFICATION_STATE_CHANGE_GENERIC" = "Verification state changed.";
/* Action sheet item
table cell label in conversation settings */
/* Label for button or row which allows users to verify the safety number of another user. */
"VERIFY_PRIVACY" = "Show Safety Number";
/* Indicates how to cancel a voice message. */

Loading…
Cancel
Save