From 80690326cb421aa3860fe6f76162851b201e47f1 Mon Sep 17 00:00:00 2001 From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Date: Mon, 11 Mar 2024 16:36:59 +0400 Subject: [PATCH] multiplatform: e2e information chat items (#3891) --- apps/ios/Shared/Views/Chat/ChatItemView.swift | 4 +-- .../chat/simplex/common/model/ChatModel.kt | 16 ++++----- .../common/views/chat/item/ChatItemView.kt | 33 ++++++++++++++++--- .../commonMain/resources/MR/base/strings.xml | 6 ++-- 4 files changed, 42 insertions(+), 17 deletions(-) diff --git a/apps/ios/Shared/Views/Chat/ChatItemView.swift b/apps/ios/Shared/Views/Chat/ChatItemView.swift index 177bbbe1c4..da9dc523e1 100644 --- a/apps/ios/Shared/Views/Chat/ChatItemView.swift +++ b/apps/ios/Shared/Views/Chat/ChatItemView.swift @@ -110,11 +110,11 @@ struct ChatItemContentView: View { case .sndModerated: deletedItemView() case .rcvModerated: deletedItemView() case .rcvBlocked: deletedItemView() - case let .invalidJSON(json): CIInvalidJSONView(json: json) case let .sndDirectE2EEInfo(e2eeInfo): CIEventView(eventText: directE2EEInfoText(e2eeInfo)) case let .rcvDirectE2EEInfo(e2eeInfo): CIEventView(eventText: directE2EEInfoText(e2eeInfo)) case .sndGroupE2EEInfo: CIEventView(eventText: e2eeInfoNoPQText()) case .rcvGroupE2EEInfo: CIEventView(eventText: e2eeInfoNoPQText()) + case let .invalidJSON(json): CIInvalidJSONView(json: json) } } @@ -177,7 +177,7 @@ struct ChatItemContentView: View { private func directE2EEInfoText(_ info: E2EEInfo) -> Text { info.pqEnabled - ? Text("Messages, files and calls are protected by **quantum resistant e2e encryption**. It has perfect forward secrecy, repudiation and break-in recovery.") + ? Text("Messages, files and calls are protected by **quantum resistant e2e encryption** with perfect forward secrecy, repudiation and break-in recovery.") .font(.caption) .foregroundColor(.secondary) .fontWeight(.light) diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt index df1dec330d..b5f00e75aa 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt @@ -2328,10 +2328,10 @@ sealed class CIContent: ItemContent { is SndModerated -> generalGetString(MR.strings.moderated_description) is RcvModerated -> generalGetString(MR.strings.moderated_description) is RcvBlocked -> generalGetString(MR.strings.blocked_by_admin_item_description) - is SndDirectE2EEInfo -> directE2EEInfoToText(e2eeInfo) - is RcvDirectE2EEInfo -> directE2EEInfoToText(e2eeInfo) - is SndGroupE2EEInfo -> e2eeInfoNoPQText - is RcvGroupE2EEInfo -> e2eeInfoNoPQText + is SndDirectE2EEInfo -> directE2EEInfoStr(e2eeInfo) + is RcvDirectE2EEInfo -> directE2EEInfoStr(e2eeInfo) + is SndGroupE2EEInfo -> e2eeInfoNoPQStr + is RcvGroupE2EEInfo -> e2eeInfoNoPQStr is InvalidJSON -> "invalid data" } @@ -2350,14 +2350,14 @@ sealed class CIContent: ItemContent { } companion object { - fun directE2EEInfoToText(e2EEInfo: E2EEInfo): String = + fun directE2EEInfoStr(e2EEInfo: E2EEInfo): String = if (e2EEInfo.pqEnabled) { - generalGetString(MR.strings.e2ee_info_pq) + generalGetString(MR.strings.e2ee_info_pq_short) } else { - e2eeInfoNoPQText + e2eeInfoNoPQStr } - private val e2eeInfoNoPQText: String = generalGetString(MR.strings.e2ee_info_no_pq) + private val e2eeInfoNoPQStr: String = generalGetString(MR.strings.e2ee_info_no_pq_short) fun featureText(feature: Feature, enabled: String, param: Int?): String = if (feature.hasParam) { diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/ChatItemView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/ChatItemView.kt index cce4307d1f..64741f7466 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/ChatItemView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/ChatItemView.kt @@ -379,6 +379,30 @@ fun ChatItemView( } } + @Composable + fun E2EEInfoNoPQText() { + Text( + buildAnnotatedString { + withStyle(chatEventStyle) { append(annotatedStringResource(MR.strings.e2ee_info_no_pq)) } + }, + Modifier.padding(horizontal = 6.dp, vertical = 6.dp) + ) + } + + @Composable + fun DirectE2EEInfoText(e2EEInfo: E2EEInfo) { + if (e2EEInfo.pqEnabled) { + Text( + buildAnnotatedString { + withStyle(chatEventStyle) { append(annotatedStringResource(MR.strings.e2ee_info_pq)) } + }, + Modifier.padding(horizontal = 6.dp, vertical = 6.dp) + ) + } else { + E2EEInfoNoPQText() + } + } + when (val c = cItem.content) { is CIContent.SndMsgContent -> ContentItem() is CIContent.RcvMsgContent -> ContentItem() @@ -452,11 +476,10 @@ fun ChatItemView( is CIContent.SndModerated -> DeletedItem() is CIContent.RcvModerated -> DeletedItem() is CIContent.RcvBlocked -> DeletedItem() - // TODO proper items - is CIContent.SndDirectE2EEInfo -> CIEventView(buildAnnotatedString { append(cItem.content.text) }) - is CIContent.RcvDirectE2EEInfo -> CIEventView(buildAnnotatedString { append(cItem.content.text) }) - is CIContent.SndGroupE2EEInfo -> CIEventView(buildAnnotatedString { append(cItem.content.text) }) - is CIContent.RcvGroupE2EEInfo -> CIEventView(buildAnnotatedString { append(cItem.content.text) }) + is CIContent.SndDirectE2EEInfo -> DirectE2EEInfoText(c.e2eeInfo) + is CIContent.RcvDirectE2EEInfo -> DirectE2EEInfoText(c.e2eeInfo) + is CIContent.SndGroupE2EEInfo -> E2EEInfoNoPQText() + is CIContent.RcvGroupE2EEInfo -> E2EEInfoNoPQText() is CIContent.InvalidJSON -> CIInvalidJSONView(c.json) } } diff --git a/apps/multiplatform/common/src/commonMain/resources/MR/base/strings.xml b/apps/multiplatform/common/src/commonMain/resources/MR/base/strings.xml index 49552a592d..d074530a5e 100644 --- a/apps/multiplatform/common/src/commonMain/resources/MR/base/strings.xml +++ b/apps/multiplatform/common/src/commonMain/resources/MR/base/strings.xml @@ -54,8 +54,10 @@ Decryption error Encryption re-negotiation error - This conversation is protected by end-to-end encryption with perfect forward secrecy, repudiation and break-in recovery. - This conversation is protected by quantum resistant end-to-end encryption. It has perfect forward secrecy, repudiation and quantum resistant break-in recovery. + end-to-end encryption with perfect forward secrecy, repudiation and break-in recovery.]]> + quantum resistant e2e encryption with perfect forward secrecy, repudiation and break-in recovery.]]> + This chat is protected by end-to-end encryption. + This chat is protected by quantum resistant end-to-end encryption. Private notes