Show display name and profile picture in slave mode

This commit is contained in:
Niels Andriesse 2019-11-22 14:22:43 +11:00
parent 56b0916a1b
commit 4baba50fa9
6 changed files with 67 additions and 29 deletions

View File

@ -108,7 +108,7 @@ final class DeviceLinkingModal : Modal, DeviceLinkingSessionDelegate {
mnemonicLabel.isHidden = (mode == .master)
if mode == .slave {
let hexEncodedPublicKey = OWSIdentityManager.shared().identityKeyPair()!.hexEncodedPublicKey.removing05PrefixIfNeeded()
mnemonicLabel.text = Mnemonic.encode(hexEncodedString: hexEncodedPublicKey).split(separator: " ")[0..<3].joined(separator: " ")
mnemonicLabel.text = Mnemonic.hash(hexEncodedString: hexEncodedPublicKey)
}
let buttonHeight = cancelButton.button.titleLabel!.font.pointSize * 48 / 17
authorizeButton.set(.height, to: buttonHeight)
@ -130,7 +130,7 @@ final class DeviceLinkingModal : Modal, DeviceLinkingSessionDelegate {
titleLabel.text = NSLocalizedString("Linking Request Received", comment: "")
subtitleLabel.text = NSLocalizedString("Please check that the words below match the ones shown on your other device", comment: "")
let hexEncodedPublicKey = deviceLink.slave.hexEncodedPublicKey.removing05PrefixIfNeeded()
mnemonicLabel.text = Mnemonic.encode(hexEncodedString: hexEncodedPublicKey).split(separator: " ")[0..<3].joined(separator: " ")
mnemonicLabel.text = Mnemonic.hash(hexEncodedString: hexEncodedPublicKey)
mnemonicLabel.isHidden = false
authorizeButton.isHidden = false
}

View File

@ -206,7 +206,7 @@ private extension DeviceLinksVC {
// MARK: Updating
private func update() {
titleLabel.text = device.displayName
subtitleLabel.text = Mnemonic.encode(hexEncodedString: device.hexEncodedPublicKey.removing05PrefixIfNeeded()).split(separator: " ")[0..<3].joined(separator: " ")
subtitleLabel.text = Mnemonic.hash(hexEncodedString: device.hexEncodedPublicKey.removing05PrefixIfNeeded())
}
}
}

View File

@ -125,15 +125,13 @@
#endif
OWSTableSection *section = [OWSTableSection new];
if (isMasterDevice) {
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{
return [weakSelf profileHeaderCell];
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{
return [weakSelf profileHeaderCell];
} customRowHeight:100.f actionBlock:^{
if (isMasterDevice) {
[weakSelf showProfile];
}
customRowHeight:100.f
actionBlock:^{
[weakSelf showProfile];
}]];
}
}]];
if (OWSSignalService.sharedInstance.isCensorshipCircumventionActive) {
[section
@ -313,6 +311,9 @@
- (UITableViewCell *)profileHeaderCell
{
NSString *masterDeviceHexEncodedPublicKey = [NSUserDefaults.standardUserDefaults stringForKey:@"masterDeviceHexEncodedPublicKey"];
BOOL isMasterDevice = (masterDeviceHexEncodedPublicKey == nil);
UITableViewCell *cell = [OWSTableItem newCell];
cell.preservesSuperviewLayoutMargins = YES;
cell.contentView.preservesSuperviewLayoutMargins = YES;
@ -331,7 +332,7 @@
[avatarView autoSetDimension:ALDimensionHeight toSize:kLargeAvatarSize];
avatarView.contactID = OWSIdentityManager.sharedManager.identityKeyPair.hexEncodedPublicKey;
if (!localProfileAvatarImage) {
if (isMasterDevice && !localProfileAvatarImage) {
UIImage *cameraImage = [UIImage imageNamed:@"settings-avatar-camera"];
UIImageView *cameraImageView = [[UIImageView alloc] initWithImage:cameraImage];
[cell.contentView addSubview:cameraImageView];
@ -350,11 +351,13 @@
titleLabel.text = localProfileName;
titleLabel.textColor = [Theme primaryColor];
titleLabel.font = [UIFont ows_dynamicTypeTitle2Font];
} else {
} else if (isMasterDevice) {
titleLabel.text = NSLocalizedString(
@"APP_SETTINGS_EDIT_PROFILE_NAME_PROMPT", @"Text prompting user to edit their profile name.");
titleLabel.textColor = [UIColor ows_materialBlueColor];
titleLabel.font = [UIFont ows_dynamicTypeHeadlineFont];
} else {
titleLabel.hidden = YES;
}
titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
[nameView addSubview:titleLabel];
@ -365,27 +368,43 @@
UILabel *subtitleLabel = [UILabel new];
subtitleLabel.textColor = [Theme secondaryColor];
subtitleLabel.font = [UIFont ows_regularFontWithSize:kSubtitlePointSize];
subtitleLabel.attributedText = [[NSAttributedString alloc]
initWithString:[PhoneNumber bestEffortFormatPartialUserSpecifiedTextToLookLikeAPhoneNumber:[TSAccountManager
localNumber]]];
NSString *hexEncodedPublicKey = masterDeviceHexEncodedPublicKey ?: TSAccountManager.localNumber;
subtitleLabel.attributedText = [[NSAttributedString alloc] initWithString:hexEncodedPublicKey];
subtitleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
[nameView addSubview:subtitleLabel];
[subtitleLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:titleLabel];
[subtitleLabel autoPinLeadingToSuperviewMargin];
[subtitleLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom];
if (isMasterDevice) {
[subtitleLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom];
}
[subtitleLabel autoPinWidthToSuperview];
if (!isMasterDevice) {
UILabel *linkedDeviceLabel = [UILabel new];
linkedDeviceLabel.textColor = [Theme secondaryColor];
linkedDeviceLabel.font = [UIFont ows_regularFontWithSize:12.f];
NSString *shortID = [LKMnemonic hashHexEncodedString:[TSAccountManager.localNumber removing05PrefixIfNeeded]];
linkedDeviceLabel.attributedText = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"Linked device (%@)", ""), shortID]];
linkedDeviceLabel.lineBreakMode = NSLineBreakByTruncatingTail;
[nameView addSubview:linkedDeviceLabel];
[linkedDeviceLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:subtitleLabel];
[linkedDeviceLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom];
[linkedDeviceLabel autoPinWidthToSuperview];
[nameView autoPinTrailingToSuperviewMargin];
}
UIImage *disclosureImage = [UIImage imageNamed:(CurrentAppContext().isRTL ? @"NavBarBack" : @"NavBarBackRTL")];
OWSAssertDebug(disclosureImage);
UIImageView *disclosureButton =
[[UIImageView alloc] initWithImage:[disclosureImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
disclosureButton.tintColor = [UIColor colorWithRGBHex:0xcccccc];
[cell.contentView addSubview:disclosureButton];
[disclosureButton autoVCenterInSuperview];
[disclosureButton autoPinTrailingToSuperviewMargin];
[disclosureButton autoPinLeadingToTrailingEdgeOfView:nameView offset:16.f];
[disclosureButton setContentCompressionResistancePriority:(UILayoutPriorityDefaultHigh + 1)
forAxis:UILayoutConstraintAxisHorizontal];
if (isMasterDevice) {
UIImage *disclosureImage = [UIImage imageNamed:(CurrentAppContext().isRTL ? @"NavBarBack" : @"NavBarBackRTL")];
OWSAssertDebug(disclosureImage);
UIImageView *disclosureButton =
[[UIImageView alloc] initWithImage:[disclosureImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
disclosureButton.tintColor = [UIColor colorWithRGBHex:0xcccccc];
[cell.contentView addSubview:disclosureButton];
[disclosureButton autoVCenterInSuperview];
[disclosureButton autoPinTrailingToSuperviewMargin];
[disclosureButton autoPinLeadingToTrailingEdgeOfView:nameView offset:16.f];
[disclosureButton setContentCompressionResistancePriority:(UILayoutPriorityDefaultHigh + 1)
forAxis:UILayoutConstraintAxisHorizontal];
}
cell.accessibilityIdentifier = ACCESSIBILITY_IDENTIFIER_WITH_NAME(self, @"profile");

View File

@ -2671,3 +2671,4 @@
"Device Unlinked" = "Device Unlinked";
"Your device was unlinked successfully" = "Your device was unlinked successfully";
"Unnamed Device" = "Unnamed Device";
"Linked device (%@)" = "Linked device (%@)";

View File

@ -58,6 +58,10 @@ public enum Mnemonic {
}
}
public static func hash(hexEncodedString string: String, language: Language = .english) -> String {
return encode(hexEncodedString: string).split(separator: " ")[0..<3].joined(separator: " ")
}
public static func encode(hexEncodedString string: String, language: Language = .english) -> String {
var string = string
let wordSet = language.loadWordSet()
@ -146,6 +150,11 @@ public final class ObjCMnemonic : NSObject {
override private init() { }
@objc(hashHexEncodedString:)
public static func hash(hexEncodedString string: String) -> String {
return Mnemonic.hash(hexEncodedString: string)
}
@objc(encodeHexEncodedString:)
public static func encode(hexEncodedString string: String) -> String {
return Mnemonic.encode(hexEncodedString: string)

View File

@ -7,3 +7,12 @@ public extension String {
return result
}
}
@objc extension NSString {
@objc public func removing05PrefixIfNeeded() -> NSString {
var result = self as String
if result.count == 66 && result.hasPrefix("05") { result.removeFirst(2) }
return result as NSString
}
}