Skip to content

Commit

Permalink
Refactor code to use new SendInfo.Status.
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Aug 5, 2024
1 parent 72daf2d commit 60918a1
Show file tree
Hide file tree
Showing 14 changed files with 165 additions and 165 deletions.
10 changes: 5 additions & 5 deletions ElementX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
02D8DF8EB7537EB4E9019DDB /* EventBasedTimelineItemProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 218AB05B4E3889731959C5F1 /* EventBasedTimelineItemProtocol.swift */; };
02F4FAE40AF63A1941FD3BBA /* NotificationCenterProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 10B7F8EE25775DE2A305CBB5 /* NotificationCenterProtocol.swift */; };
037006FB6DF1374F94E4058D /* Dictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFDCAC6CAAD65A2C24EA9C4B /* Dictionary.swift */; };
03CDCA6243F89B194E3FAD17 /* EncryptionAuthenticity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 955336CBD5ED73C792D1F580 /* EncryptionAuthenticity.swift */; };
0437765FF480249486893CC7 /* ScreenTrackerViewModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 196004E7695FBA292A7944AF /* ScreenTrackerViewModifier.swift */; };
044DD8F80231BC30570F7965 /* UserDiscoveryService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65AAD845E53B0C8B5E0812C2 /* UserDiscoveryService.swift */; };
04A16B45228F7678A027C079 /* RoomHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 422724361B6555364C43281E /* RoomHeaderView.swift */; };
Expand All @@ -45,7 +46,6 @@
06D3942496E9E0E655F14D21 /* NotificationManagerProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = A057F2FDC14866C3026A89A4 /* NotificationManagerProtocol.swift */; };
06F8EDF52E33A2D36BCC1161 /* AppLockScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D6F88FE35A0979D2821E06 /* AppLockScreen.swift */; };
071A017E415AD378F2961B11 /* URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 227AC5D71A4CE43512062243 /* URL.swift */; };
0746E133BCD0ED6BE997DC74 /* MessageShield.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B23FF90D0341B0F33A2D13E /* MessageShield.swift */; };
07756D532EFE33DD1FA258E5 /* GeoURITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A7ED2EF5BDBAD2A7DBC4636 /* GeoURITests.swift */; };
077CB230153E072C94B1E6C3 /* AppAppearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D65BCC659FD9087E49B3C25 /* AppAppearance.swift */; };
07CC13C5729C24255348CBBD /* ElementCallWidgetDriver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 309AD8BAE6437C31BA7157BF /* ElementCallWidgetDriver.swift */; };
Expand Down Expand Up @@ -1552,7 +1552,6 @@
5A2FCA3D0F239B9E911B966B /* SecureBackupRecoveryKeyScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecureBackupRecoveryKeyScreen.swift; sourceTree = "<group>"; };
5A37E2FACFD041CE466223CD /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
5AEA0B743847CFA5B3C38EE4 /* RoomMembersListScreenCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomMembersListScreenCoordinator.swift; sourceTree = "<group>"; };
5B23FF90D0341B0F33A2D13E /* MessageShield.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageShield.swift; sourceTree = "<group>"; };
5B8F0ED874DF8C9A51B0AB6F /* SettingsScreenCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsScreenCoordinator.swift; sourceTree = "<group>"; };
5C7C7CFA6B2A62A685FF6CE3 /* DeveloperOptionsScreenCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeveloperOptionsScreenCoordinator.swift; sourceTree = "<group>"; };
5CEEAE1BFAACD6C96B6DB731 /* PHGPostHogProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PHGPostHogProtocol.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1773,6 +1772,7 @@
94028A227645FA880B966211 /* WaveformSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WaveformSource.swift; sourceTree = "<group>"; };
94D670124FC3E84F23A62CCF /* APNSPayload.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APNSPayload.swift; sourceTree = "<group>"; };
9501D11B4258DFA33BA3B40F /* ServerSelectionScreenModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerSelectionScreenModels.swift; sourceTree = "<group>"; };
955336CBD5ED73C792D1F580 /* EncryptionAuthenticity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EncryptionAuthenticity.swift; sourceTree = "<group>"; };
95BAC0F6C9644336E9567EE6 /* NSRegularExpresion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSRegularExpresion.swift; sourceTree = "<group>"; };
969694F67E844FCA51F7E051 /* sv */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sv; path = sv.lproj/InfoPlist.strings; sourceTree = "<group>"; };
96C4762F8D6112E43117DB2F /* CustomStringConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomStringConvertible.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3518,7 +3518,7 @@
children = (
B858A61F2A570DFB8DE570A7 /* AggregratedReaction.swift */,
96C4762F8D6112E43117DB2F /* CustomStringConvertible.swift */,
5B23FF90D0341B0F33A2D13E /* MessageShield.swift */,
955336CBD5ED73C792D1F580 /* EncryptionAuthenticity.swift */,
314F1C79850BE46E8ABEAFCB /* ReadReceipt.swift */,
5DE8D25D6A91030175D52A20 /* RoomTimelineItemProperties.swift */,
BE89A8BD65CCE3FCC925CA14 /* TimelineItemReplyDetails.swift */,
Expand Down Expand Up @@ -6201,6 +6201,7 @@
8B1D5CE017EEC734CF5FE130 /* Encodable.swift in Sources */,
4C5A638DAA8AF64565BA4866 /* EncryptedRoomTimelineItem.swift in Sources */,
B5903E48CF43259836BF2DBF /* EncryptedRoomTimelineView.swift in Sources */,
03CDCA6243F89B194E3FAD17 /* EncryptionAuthenticity.swift in Sources */,
FBD402E3170EB1ED0D1AA672 /* EncryptionKeyProvider.swift in Sources */,
46A6DB0F78FB399BD59E2D41 /* EncryptionKeyProviderProtocol.swift in Sources */,
0C6DF318E9C8F6461E6ABDE7 /* EncryptionResetPasswordScreen.swift in Sources */,
Expand Down Expand Up @@ -6350,7 +6351,6 @@
695825D20A761C678809345D /* MessageForwardingScreenModels.swift in Sources */,
F54E2D6CAD96E1AC15BC526F /* MessageForwardingScreenViewModel.swift in Sources */,
C13128AAA787A4C2CBE4EE82 /* MessageForwardingScreenViewModelProtocol.swift in Sources */,
0746E133BCD0ED6BE997DC74 /* MessageShield.swift in Sources */,
C97325EFDCCEE457432A9E82 /* MessageText.swift in Sources */,
152AE2B8650FB23AFD2E28B9 /* MockAuthenticationServiceProxy.swift in Sources */,
B659E3A49889E749E3239EA7 /* MockMediaProvider.swift in Sources */,
Expand Down Expand Up @@ -7557,7 +7557,7 @@
repositoryURL = "https://github.com/element-hq/matrix-rust-components-swift";
requirement = {
kind = exactVersion;
version = 1.0.30;
version = 1.0.31;
};
};
701C7BEF8F70F7A83E852DCC /* XCRemoteSwiftPackageReference "GZIP" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/element-hq/matrix-rust-components-swift",
"state" : {
"revision" : "bc534e15fa0749d668b201b923ee57204afb868a",
"version" : "1.0.30"
"revision" : "8e2b4049fb492dcf5b0c796784b7aa7a3c099943",
"version" : "1.0.31"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

// MARK: - Shields

"send_info_not_encrypted" = "Not encrypted";
"event_shield_reason_sent_in_clear" = "Sent in clear";

// MARK: - Soft logout

Expand Down
4 changes: 2 additions & 2 deletions ElementX/Sources/Generated/Strings+Untranslated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +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") }
/// Sent in clear
internal static var eventShieldReasonSentInClear: String { return UntranslatedL10n.tr("Untranslated", "event_shield_reason_sent_in_clear") }
/// 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 @@ -111,14 +111,6 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
context.send(viewAction: .displayTimelineItemMenu(itemID: timelineItem.id))
}

if timelineItem.shieldPosition == .outside {
e2eeShield
.background {
RoundedRectangle(cornerRadius: 12)
.fill(timelineItem.isOutgoing ? .compound._bgBubbleOutgoing : .compound._bgBubbleIncoming)
}
}

if !timelineItem.properties.reactions.isEmpty {
TimelineReactionsView(context: context,
itemID: timelineItem.id,
Expand Down Expand Up @@ -208,48 +200,9 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
content()
.layoutPriority(TimelineBubbleLayout.Priority.regularText)
.cornerRadius(timelineItem.contentCornerRadius)

if timelineItem.shieldPosition == .inside {
e2eeShield
.padding(.horizontal, 4)
.padding(.bottom, -9) // 8 plus 1 extra for the timestamp padding.
.layoutPriority(TimelineBubbleLayout.Priority.regularText)
}
}
}

@ViewBuilder
var e2eeShield: some View {
if let shield = timelineItem.properties.shield {
Label {
Text(shield.message)
.foregroundColor(shield.color == ShieldColor.RED ? .compound.textCriticalPrimary : .compound.textSecondary)
.frame(maxWidth: 250, alignment: .leading)
.font(.compound.bodyXS)
} icon: {
if shield.color == ShieldColor.RED {
CompoundIcon(\.error, size: .xSmall, relativeTo: .compound.bodyXS)
.foregroundColor(.compound.iconCriticalPrimary)
.alignmentGuide(VerticalAlignment.top) { dimensions in
dimensions[.top]
}
} else {
CompoundIcon(\.infoSolid, size: .xSmall, relativeTo: .compound.bodyXS)
.foregroundColor(.compound.iconSecondary)
.alignmentGuide(VerticalAlignment.top) { dimensions in
dimensions[.top]
}
}
}
.labelStyle(.custom(spacing: 4, alignment: .top))
.padding(4)
.background {
RoundedRectangle(cornerRadius: 12, style: .circular)
.stroke(shield.color == ShieldColor.RED ? .compound.borderCriticalSubtle : .compound.bgSubtlePrimary)
}
}
}

private var messageBubbleTopPadding: CGFloat {
guard timelineItem.isOutgoing || isEncryptedOneToOneRoom else { return 0 }
return timelineGroupStyle == .single || timelineGroupStyle == .first ? 8 : 0
Expand Down Expand Up @@ -377,8 +330,8 @@ struct TimelineItemBubbledStylerView_Previews: PreviewProvider, TestablePreview
.previewDisplayName("Replies")
threads
.previewDisplayName("Thread decorator")
shields
.previewDisplayName("E2E Shields")
encryptionAuthenticity
.previewDisplayName("Encryption Indicators")
}

// These akwats include a reply
Expand Down Expand Up @@ -527,7 +480,7 @@ struct TimelineItemBubbledStylerView_Previews: PreviewProvider, TestablePreview
.environmentObject(viewModel.context)
}

static var shields: some View {
static var encryptionAuthenticity: some View {
VStack(spacing: 0) {
RoomTimelineItemView(viewState: .init(item: TextRoomTimelineItem(id: .init(timelineID: ""),
timestamp: "10:42",
Expand All @@ -537,8 +490,7 @@ struct TimelineItemBubbledStylerView_Previews: PreviewProvider, TestablePreview
isThreaded: false,
sender: .init(id: "whoever"),
content: .init(body: "A long message that should be on multiple lines."),
properties: RoomTimelineItemProperties(
shield: MessageShield(color: .RED, message: "Encrypted by a device not verified by its owner."))),
properties: RoomTimelineItemProperties(encryptionAuthenticity: .unsignedDevice(color: .red))),
groupStyle: .single))

RoomTimelineItemView(viewState: .init(item: TextRoomTimelineItem(id: .init(timelineID: ""),
Expand All @@ -550,7 +502,7 @@ struct TimelineItemBubbledStylerView_Previews: PreviewProvider, TestablePreview
sender: .init(id: "whoever"),
content: .init(body: "A long message that should be on multiple lines."),
properties: RoomTimelineItemProperties(isEdited: true,
shield: MessageShield(color: .RED, message: "Encrypted by a device not verified by its owner."))),
encryptionAuthenticity: .unsignedDevice(color: .red))),
groupStyle: .single))

RoomTimelineItemView(viewState: .init(item: TextRoomTimelineItem(id: .init(timelineID: ""),
Expand All @@ -561,8 +513,7 @@ struct TimelineItemBubbledStylerView_Previews: PreviewProvider, TestablePreview
isThreaded: false,
sender: .init(id: "whoever"),
content: .init(body: "Short message"),
properties: RoomTimelineItemProperties(
shield: MessageShield(color: .RED, message: "Encrypted by an unknown or deleted device."))),
properties: RoomTimelineItemProperties(encryptionAuthenticity: .unknownDevice(color: .red))),
groupStyle: .first))

RoomTimelineItemView(viewState: .init(item: TextRoomTimelineItem(id: .init(timelineID: ""),
Expand All @@ -573,8 +524,7 @@ struct TimelineItemBubbledStylerView_Previews: PreviewProvider, TestablePreview
isThreaded: false,
sender: .init(id: "whoever"),
content: .init(body: "Message goes Here"),
properties: RoomTimelineItemProperties(
shield: MessageShield(color: .GRAY, message: "The authenticity of this encrypted message can't be guaranteed on this device."))),
properties: RoomTimelineItemProperties(encryptionAuthenticity: .notGuaranteed(color: .gray))),
groupStyle: .last))

ImageRoomTimelineView(timelineItem: ImageRoomTimelineItem(id: .random,
Expand All @@ -586,8 +536,7 @@ struct TimelineItemBubbledStylerView_Previews: PreviewProvider, TestablePreview
sender: .init(id: "Bob"),
content: .init(body: "Some other image", source: MediaSourceProxy(url: .picturesDirectory, mimeType: "image/png"), thumbnailSource: nil),

properties: RoomTimelineItemProperties(
shield: MessageShield(color: .GRAY, message: "The authenticity of this encrypted message can't be guaranteed on this device."))))
properties: RoomTimelineItemProperties(encryptionAuthenticity: .notGuaranteed(color: .gray))))

VoiceMessageRoomTimelineView(timelineItem: .init(id: .init(timelineID: ""),
timestamp: "10:42",
Expand All @@ -601,8 +550,8 @@ struct TimelineItemBubbledStylerView_Previews: PreviewProvider, TestablePreview
waveform: EstimatedWaveform.mockWaveform,
source: nil,
contentType: nil),
properties: RoomTimelineItemProperties(
shield: MessageShield(color: .GRAY, message: "The authenticity of this encrypted message can't be guaranteed on this device."))), playerState: AudioPlayerState(id: .timelineItemIdentifier(.random), duration: 10, waveform: EstimatedWaveform.mockWaveform))
properties: RoomTimelineItemProperties(encryptionAuthenticity: .notGuaranteed(color: .gray))),
playerState: AudioPlayerState(id: .timelineItemIdentifier(.random), duration: 10, waveform: EstimatedWaveform.mockWaveform))
}
.environmentObject(viewModel.context)
}
Expand Down
Loading

0 comments on commit 60918a1

Please sign in to comment.