mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 10:33:45 +00:00
Display a badge for messages decrypted using shared keys. (#4937)
* feat: Show info badge for messages decrypted with shared keys * tests: Add snapshots and tests for forwarder icon. * fix: Update `EventBasedTimelineItemProtocol.hasStatusIcon` * fix: Address review comments. * fix: Use two translations for key forwarded dialog content. * refactor: Rename `TimelineItemForwarder` to `TimelineItemKeyForwarder`. Additionally adds a `[weak self]` guard to `encryptionForwarder` alert handler. * tests: Add `previewLayout` directive to `encryptionForwarder` previews * refactor: Remove unused translations, use short-circuiting condition.
This commit is contained in:
@@ -15,7 +15,8 @@ extension View {
|
||||
adjustedDeliveryStatus: TimelineItemDeliveryStatus?,
|
||||
context: TimelineViewModel.Context) -> some View {
|
||||
modifier(TimelineItemSendInfoModifier(sendInfo: .init(timelineItem: timelineItem,
|
||||
adjustedDeliveryStatus: adjustedDeliveryStatus),
|
||||
adjustedDeliveryStatus: adjustedDeliveryStatus,
|
||||
enableKeyShareOnInvite: context.viewState.enableKeyShareOnInvite),
|
||||
context: context))
|
||||
}
|
||||
}
|
||||
@@ -60,6 +61,7 @@ private struct TimelineItemSendInfoLabel: View {
|
||||
switch sendInfo.status {
|
||||
case .sendingFailed: \.errorSolid
|
||||
case .encryptionAuthenticity(let authenticity): authenticity.icon
|
||||
case .encryptionForwarder: \.info
|
||||
case .none: nil
|
||||
}
|
||||
}
|
||||
@@ -68,6 +70,7 @@ private struct TimelineItemSendInfoLabel: View {
|
||||
switch sendInfo.status {
|
||||
case .sendingFailed: L10n.commonSendingFailed
|
||||
case .encryptionAuthenticity(let authenticity): authenticity.message
|
||||
case .encryptionForwarder(let forwarder): forwarder.message
|
||||
case .none: nil
|
||||
}
|
||||
}
|
||||
@@ -111,7 +114,11 @@ private struct TimelineItemSendInfoLabel: View {
|
||||
|
||||
/// All the data needed to render a timeline item's send info label.
|
||||
private struct TimelineItemSendInfo {
|
||||
enum Status { case sendingFailed, encryptionAuthenticity(EncryptionAuthenticity) }
|
||||
enum Status {
|
||||
case sendingFailed
|
||||
case encryptionAuthenticity(EncryptionAuthenticity)
|
||||
case encryptionForwarder(TimelineItemKeyForwarder)
|
||||
}
|
||||
|
||||
/// Describes how the content and the send info should be arranged inside a bubble
|
||||
enum LayoutType {
|
||||
@@ -131,6 +138,8 @@ private struct TimelineItemSendInfo {
|
||||
.compound.textCriticalPrimary
|
||||
case .encryptionAuthenticity(let authenticity):
|
||||
authenticity.foregroundStyle
|
||||
case .encryptionForwarder:
|
||||
.compound.textSecondary
|
||||
case .none:
|
||||
.compound.textSecondary
|
||||
}
|
||||
@@ -138,7 +147,7 @@ private struct TimelineItemSendInfo {
|
||||
}
|
||||
|
||||
private extension TimelineItemSendInfo {
|
||||
init(timelineItem: EventBasedTimelineItemProtocol, adjustedDeliveryStatus: TimelineItemDeliveryStatus?) {
|
||||
init(timelineItem: EventBasedTimelineItemProtocol, adjustedDeliveryStatus: TimelineItemDeliveryStatus?, enableKeyShareOnInvite: Bool) {
|
||||
itemID = timelineItem.id
|
||||
localizedString = timelineItem.localizedSendInfo
|
||||
|
||||
@@ -146,6 +155,8 @@ private extension TimelineItemSendInfo {
|
||||
.sendingFailed
|
||||
} else if let authenticity = timelineItem.properties.encryptionAuthenticity {
|
||||
.encryptionAuthenticity(authenticity)
|
||||
} else if enableKeyShareOnInvite, let forwarder = timelineItem.properties.encryptionForwarder {
|
||||
.encryptionForwarder(forwarder)
|
||||
} else {
|
||||
nil
|
||||
}
|
||||
@@ -184,6 +195,12 @@ private extension EncryptionAuthenticity {
|
||||
}
|
||||
}
|
||||
|
||||
private extension TimelineItemKeyForwarder {
|
||||
static var test: TimelineItemKeyForwarder {
|
||||
TimelineItemKeyForwarder(id: "@alice:matrix.org", displayName: "alice")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
struct TimelineItemSendInfoLabel_Previews: PreviewProvider, TestablePreview {
|
||||
@@ -208,6 +225,10 @@ struct TimelineItemSendInfoLabel_Previews: PreviewProvider, TestablePreview {
|
||||
localizedString: "09:47 AM",
|
||||
status: .encryptionAuthenticity(.sentInClear(color: .red)),
|
||||
layoutType: .horizontal()))
|
||||
TimelineItemSendInfoLabel(sendInfo: .init(itemID: .randomEvent,
|
||||
localizedString: "09:47 AM",
|
||||
status: .encryptionForwarder(.test),
|
||||
layoutType: .horizontal()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user