Skip to content

Commit

Permalink
Fix the pinned identity banner to always show the user ID regardless …
Browse files Browse the repository at this point in the history
…of ambiguity. (#3415)
  • Loading branch information
pixlwave authored Oct 16, 2024
1 parent 6078398 commit 5a89219
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 17 deletions.
2 changes: 2 additions & 0 deletions ElementX/Resources/Localizations/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@
"confirm_recovery_key_banner_title" = "Enter your recovery key";
"crash_detection_dialog_content" = "%1$@ crashed the last time it was used. Would you like to share a crash report with us?";
"crypto_identity_change_pin_violation" = "%1$@'s identity appears to have changed. %2$@";
"crypto_identity_change_pin_violation_new" = "%1$@’s %2$@ identity appears to have changed. %3$@";
"crypto_identity_change_pin_violation_new_user_id" = "(%1$@)";
"dialog_permission_camera" = "In order to let the application use the camera, please grant the permission in the system settings.";
"dialog_permission_generic" = "Please grant the permission in the system settings.";
"dialog_permission_location_description_ios" = "Grant access in Settings -> Location.";
Expand Down
8 changes: 8 additions & 0 deletions ElementX/Sources/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,14 @@ internal enum L10n {
internal static func cryptoIdentityChangePinViolation(_ p1: Any, _ p2: Any) -> String {
return L10n.tr("Localizable", "crypto_identity_change_pin_violation", String(describing: p1), String(describing: p2))
}
/// %1$@’s %2$@ identity appears to have changed. %3$@
internal static func cryptoIdentityChangePinViolationNew(_ p1: Any, _ p2: Any, _ p3: Any) -> String {
return L10n.tr("Localizable", "crypto_identity_change_pin_violation_new", String(describing: p1), String(describing: p2), String(describing: p3))
}
/// (%1$@)
internal static func cryptoIdentityChangePinViolationNewUserId(_ p1: Any) -> String {
return L10n.tr("Localizable", "crypto_identity_change_pin_violation_new_user_id", String(describing: p1))
}
/// In order to let the application use the camera, please grant the permission in the system settings.
internal static var dialogPermissionCamera: String { return L10n.tr("Localizable", "dialog_permission_camera") }
/// Please grant the permission in the system settings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ struct RoomScreenFooterView: View {
avatarSize: .user(on: .timeline),
mediaProvider: mediaProvider)

Text(pinViolationDescriptionWithLearnMoreLink(displayName: member.disambiguatedDisplayName ?? member.userID,
Text(pinViolationDescriptionWithLearnMoreLink(displayName: member.displayName,
userID: member.userID,
url: learnMoreURL))
.font(.compound.bodyMD)
.foregroundColor(.compound.textPrimary)
Expand All @@ -59,20 +60,39 @@ struct RoomScreenFooterView: View {
.padding(.bottom, 8)
}

private func pinViolationDescriptionWithLearnMoreLink(displayName: String, url: URL) -> AttributedString {
private func pinViolationDescriptionWithLearnMoreLink(displayName: String?, userID: String, url: URL) -> AttributedString {
let userIDPlaceholder = "{mxid}"
let linkPlaceholder = "{link}"
var description = AttributedString(L10n.cryptoIdentityChangePinViolation(displayName, linkPlaceholder))
let displayName = displayName ?? fallbackDisplayName(userID)
var description = AttributedString(L10n.cryptoIdentityChangePinViolationNew(displayName, userIDPlaceholder, linkPlaceholder))

var userIDString = AttributedString(L10n.cryptoIdentityChangePinViolationNewUserId(userID))
userIDString.bold()
description.replace(userIDPlaceholder, with: userIDString)

var linkString = AttributedString(L10n.actionLearnMore)
linkString.link = url
linkString.bold()
description.replace(linkPlaceholder, with: linkString)
return description
}

private func fallbackDisplayName(_ userID: String) -> String {
guard let localpart = userID.components(separatedBy: ":").first else { return userID }
return String(localpart.trimmingPrefix("@"))
}
}

struct RoomScreenFooterView_Previews: PreviewProvider, TestablePreview {
static let bobDetails: RoomScreenFooterViewDetails = .pinViolation(member: RoomMemberProxyMock.mockBob,
learnMoreURL: "https://element.io/")
static let noNameDetails: RoomScreenFooterViewDetails = .pinViolation(member: RoomMemberProxyMock.mockNoName,
learnMoreURL: "https://element.io/")

static var previews: some View {
RoomScreenFooterView(details: .pinViolation(member: RoomMemberProxyMock.mockBob, learnMoreURL: "https://element.io/"),
mediaProvider: MediaProviderMock(configuration: .init())) { _ in }
RoomScreenFooterView(details: bobDetails, mediaProvider: MediaProviderMock(configuration: .init())) { _ in }
.previewDisplayName("With displayname")
RoomScreenFooterView(details: noNameDetails, mediaProvider: MediaProviderMock(configuration: .init())) { _ in }
.previewDisplayName("Without displayname")
}
}

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5a89219

Please sign in to comment.