Fix the pinned identity banner to always show the user ID regardless of ambiguity. (#3415)

This commit is contained in:
Doug
2024-10-16 14:51:29 +01:00
committed by GitHub
parent 6078398ad3
commit 5a89219f9a
15 changed files with 59 additions and 17 deletions
@@ -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.";
+8
View File
@@ -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.
@@ -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)
@@ -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")
}
}