Skip to content

Commit

Permalink
Add (unused) examples of encryption shields.
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Jul 29, 2024
1 parent c003c91 commit 9450429
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
/* Used for testing */
"untranslated" = "Untranslated";

// MARK: - Shields

"send_info_not_encrypted" = "Not encrypted";

// MARK: - Soft logout

"soft_logout_signin_title" = "Sign in";
Expand Down
2 changes: 2 additions & 0 deletions ElementX/Sources/Generated/Strings+Untranslated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import Foundation
// swiftlint:disable explicit_type_interface function_parameter_count identifier_name line_length
// swiftlint:disable nesting type_body_length type_name vertical_whitespace_opening_braces
internal enum UntranslatedL10n {
/// Not encrypted
internal static var sendInfoNotEncrypted: String { return UntranslatedL10n.tr("Untranslated", "send_info_not_encrypted") }
/// Clear all data currently stored on this device?
/// Sign in again to access your account data and messages.
internal static var softLogoutClearDataDialogContent: String { return UntranslatedL10n.tr("Untranslated", "soft_logout_clear_data_dialog_content") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@ private struct TimelineItemSendInfoModifier: ViewModifier {
private struct TimelineItemSendInfoLabel: View {
let sendInfo: TimelineItemSendInfo

var statusIcon: KeyPath<CompoundIcons, Image>? {
switch sendInfo.status {
case .sendingFailed: \.error
case .unverifiedSession, .authenticityUnknown: \.admin
case .unencrypted: \.keyOff
case .none: nil
}
}

var statusIconAccessibilityLabel: String? {
switch sendInfo.status {
case .sendingFailed: L10n.commonSendingFailed
case .none: nil
// Temporary testing strings.
case .unverifiedSession: L10n.eventShieldReasonUnsignedDevice
case .authenticityUnknown: L10n.eventShieldReasonAuthenticityNotGuaranteed
case .unencrypted: UntranslatedL10n.sendInfoNotEncrypted
}
}

var body: some View {
switch sendInfo.layoutType {
case .overlay(capsuleStyle: true):
Expand All @@ -79,9 +99,9 @@ private struct TimelineItemSendInfoLabel: View {
HStack(spacing: 4) {
Text(sendInfo.localizedString)

if sendInfo.adjustedDeliveryStatus == .sendingFailed {
CompoundIcon(\.error, size: .xSmall, relativeTo: .compound.bodyXS)
.accessibilityLabel(L10n.commonSendingFailed)
if let statusIcon, let statusIconAccessibilityLabel {
CompoundIcon(statusIcon, size: .xSmall, relativeTo: .compound.bodyXS)
.accessibilityLabel(statusIconAccessibilityLabel)
}
}
.font(.compound.bodyXS)
Expand All @@ -91,9 +111,7 @@ private struct TimelineItemSendInfoLabel: View {

/// All the data needed to render a timeline item's send info label.
private struct TimelineItemSendInfo {
let localizedString: String
let layoutType: LayoutType
var adjustedDeliveryStatus: TimelineItemDeliveryStatus?
enum Status { case sendingFailed, unverifiedSession, authenticityUnknown, unencrypted }

/// Describes how the content and the send info should be arranged inside a bubble
enum LayoutType {
Expand All @@ -102,14 +120,30 @@ private struct TimelineItemSendInfo {
case overlay(capsuleStyle: Bool)
}

let localizedString: String
var status: Status?
let layoutType: LayoutType

var foregroundStyle: Color {
adjustedDeliveryStatus == .sendingFailed ? .compound.textCriticalPrimary : .compound.textSecondary
switch status {
case .sendingFailed, .unverifiedSession:
.compound.textCriticalPrimary
case .authenticityUnknown, .unencrypted, .none:
.compound.textSecondary
}
}
}

private extension TimelineItemSendInfo {
init(timelineItem: EventBasedTimelineItemProtocol, adjustedDeliveryStatus: TimelineItemDeliveryStatus?) {
localizedString = timelineItem.localizedSendInfo

status = if adjustedDeliveryStatus == .sendingFailed {
.sendingFailed
} else {
nil
}

layoutType = switch timelineItem {
case is TextBasedRoomTimelineItem:
.overlay(capsuleStyle: false)
Expand All @@ -124,7 +158,6 @@ private extension TimelineItemSendInfo {
default:
.horizontal()
}
self.adjustedDeliveryStatus = adjustedDeliveryStatus
}
}

Expand All @@ -136,8 +169,17 @@ struct TimelineItemSendInfoLabel_Previews: PreviewProvider, TestablePreview {
TimelineItemSendInfoLabel(sendInfo: .init(localizedString: "09:47 AM",
layoutType: .horizontal()))
TimelineItemSendInfoLabel(sendInfo: .init(localizedString: "09:47 AM",
layoutType: .horizontal(),
adjustedDeliveryStatus: .sendingFailed))
status: .sendingFailed,
layoutType: .horizontal()))
TimelineItemSendInfoLabel(sendInfo: .init(localizedString: "09:47 AM",
status: .unverifiedSession,
layoutType: .horizontal()))
TimelineItemSendInfoLabel(sendInfo: .init(localizedString: "09:47 AM",
status: .authenticityUnknown,
layoutType: .horizontal()))
TimelineItemSendInfoLabel(sendInfo: .init(localizedString: "09:47 AM",
status: .unencrypted,
layoutType: .horizontal()))
}
}
}
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.
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 9450429

Please sign in to comment.