Skip to content

Commit

Permalink
feat: connection request warning badge and conversation started sys m…
Browse files Browse the repository at this point in the history
…essage warning (WPB-2266) (#2357)
  • Loading branch information
yamilmedina committed Oct 25, 2023
1 parent 3d8626b commit 1385f09
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 12 deletions.
Expand Up @@ -70,6 +70,7 @@ class SystemMessageContentMapper @Inject constructor(
is MessageContent.ConversationVerifiedProteus -> mapConversationVerified(Conversation.Protocol.PROTEUS)
is MessageContent.FederationStopped -> mapFederationMessage(content)
is MessageContent.ConversationProtocolChanged -> mapConversationProtocolChanged(content)
is MessageContent.ConversationStartedUnverifiedWarning -> mapConversationCreatedUnverifiedWarning()
}

private fun mapConversationCreated(senderUserId: UserId, date: String, userList: List<User>): UIMessageContent.SystemMessage {
Expand All @@ -85,6 +86,10 @@ class SystemMessageContentMapper @Inject constructor(
)
}

private fun mapConversationCreatedUnverifiedWarning(): UIMessageContent.SystemMessage {
return UIMessageContent.SystemMessage.ConversationMessageCreatedUnverifiedWarning
}

private fun mapConversationTimerChanged(
senderUserId: UserId,
content: MessageContent.ConversationMessageTimerChanged,
Expand Down Expand Up @@ -246,12 +251,16 @@ class SystemMessageContentMapper @Inject constructor(

private fun mapConversationHistoryLost(): UIMessageContent.SystemMessage =
UIMessageContent.SystemMessage.HistoryLost

private fun mapMLSWrongEpochWarning(): UIMessageContent.SystemMessage =
UIMessageContent.SystemMessage.MLSWrongEpochWarning()

private fun mapConversationHistoryListProtocolChanged(): UIMessageContent.SystemMessage =
UIMessageContent.SystemMessage.HistoryLostProtocolChanged

private fun mapConversationDegraded(protocol: Conversation.Protocol): UIMessageContent.SystemMessage =
UIMessageContent.SystemMessage.ConversationDegraded(protocol)

private fun mapConversationVerified(protocol: Conversation.Protocol): UIMessageContent.SystemMessage =
UIMessageContent.SystemMessage.ConversationVerified(protocol)

Expand Down
Expand Up @@ -265,6 +265,7 @@ private fun getColorFilter(message: SystemMessage): ColorFilter? {
is SystemMessage.ConversationMessageTimerDeactivated,
is SystemMessage.FederationMemberRemoved,
is SystemMessage.FederationStopped,
is SystemMessage.ConversationMessageCreatedUnverifiedWarning,
is SystemMessage.MLSWrongEpochWarning -> ColorFilter.tint(colorsScheme().onBackground)
}
}
Expand Down Expand Up @@ -495,6 +496,7 @@ private val SystemMessage.expandable
is SystemMessage.ConversationDegraded -> false
is SystemMessage.ConversationVerified -> false
is SystemMessage.FederationStopped -> false
is SystemMessage.ConversationMessageCreatedUnverifiedWarning -> false
}

private fun List<String>.toUserNamesListString(res: Resources): String = when {
Expand Down Expand Up @@ -581,6 +583,7 @@ fun SystemMessage.annotatedString(
)

is SystemMessage.FederationStopped -> domainList.toTypedArray()
is SystemMessage.ConversationMessageCreatedUnverifiedWarning -> arrayOf()
}

return res.annotatedText(stringResId, normalStyle, boldStyle, normalColor, boldColor, errorColor, isErrorString, *args)
Expand Down
Expand Up @@ -423,7 +423,8 @@ sealed class UIMessageContent {
object HistoryLost : SystemMessage(
R.drawable.ic_info,
R.string.label_system_message_conversation_history_lost,
true)
true
)

object HistoryLostProtocolChanged : SystemMessage(
R.drawable.ic_info,
Expand Down Expand Up @@ -476,6 +477,11 @@ sealed class UIMessageContent {
if (protocol == Conversation.Protocol.MLS) R.string.label_system_message_conversation_verified_mls
else R.string.label_system_message_conversation_verified_proteus
)

data object ConversationMessageCreatedUnverifiedWarning : SystemMessage(
R.drawable.ic_info,
R.string.label_system_message_conversation_started_sensitive_information
)
}
}

Expand Down
Expand Up @@ -58,16 +58,8 @@ fun OtherUserConnectionStatusInfo(connectionStatus: ConnectionState, membership:
style = MaterialTheme.wireTypography.title02
)
}
val descriptionResource = when (connectionStatus) {
ConnectionState.PENDING, ConnectionState.IGNORED -> R.string.connection_label_accepting_request_description
ConnectionState.ACCEPTED, ConnectionState.BLOCKED -> null
else -> if (membership == Membership.None) {
R.string.connection_label_member_not_conneted
} else {
R.string.connection_label_member_not_belongs_to_team
}
}
descriptionResource?.let {

descriptionResourceForConnectionAndMembership(connectionStatus, membership)?.let {
Text(
text = stringResource(it),
textAlign = TextAlign.Center,
Expand All @@ -80,6 +72,20 @@ fun OtherUserConnectionStatusInfo(connectionStatus: ConnectionState, membership:
}
}

@Composable
private fun descriptionResourceForConnectionAndMembership(
connectionStatus: ConnectionState,
membership: Membership
) = when (connectionStatus) {
ConnectionState.PENDING, ConnectionState.IGNORED -> R.string.connection_label_accepting_request_description
ConnectionState.ACCEPTED, ConnectionState.BLOCKED -> null
else -> if (membership == Membership.None) {
R.string.connection_label_member_not_conneted
} else {
R.string.connection_label_member_not_belongs_to_team
}
}

@Composable
@Preview
fun PreviewOtherUserConnectionStatusInfo() {
Expand Down
@@ -0,0 +1,79 @@
/*
* Wire
* Copyright (C) 2023 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*
*/

package com.wire.android.ui.userprofile.other

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import com.wire.android.R
import com.wire.android.ui.common.dimensions
import com.wire.android.ui.common.spacers.VerticalSpace
import com.wire.android.ui.theme.wireColorScheme
import com.wire.android.ui.theme.wireTypography
import com.wire.kalium.logic.data.user.ConnectionState

@Composable
fun OtherUserConnectionUnverifiedWarning(
userName: String,
connectionStatus: ConnectionState
) {
Box(
Modifier
.fillMaxWidth()
.wrapContentHeight()
.padding(start = dimensions().spacing32x, end = dimensions().spacing32x)
) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
unverifiedDescriptionResource(connectionStatus)?.let {
Text(
text = stringResource(it, userName),
textAlign = TextAlign.Center,
color = MaterialTheme.wireColorScheme.error,
style = MaterialTheme.wireTypography.body01
)
VerticalSpace.x24()
}
}
}
}

@Composable
private fun unverifiedDescriptionResource(connectionStatus: ConnectionState) = when (connectionStatus) {
ConnectionState.PENDING, ConnectionState.IGNORED -> R.string.connection_label_received_unverified_warning
ConnectionState.ACCEPTED, ConnectionState.BLOCKED -> null
else -> R.string.connection_label_send_unverified_warning
}

@Composable
@Preview
fun PreviewOtherUserConnectionUnverifiedWarning() {
OtherUserConnectionUnverifiedWarning("Bob", ConnectionState.NOT_CONNECTED)
}
Expand Up @@ -447,6 +447,7 @@ private fun Content(
Column {
if (!state.isDataLoading) {
OtherUserConnectionStatusInfo(state.connectionState, state.membership)
OtherUserConnectionUnverifiedWarning(state.fullName, state.connectionState)
}
when {
state.isDataLoading || state.botService != null -> Box {} // no content visible while loading
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Expand Up @@ -607,6 +607,7 @@
<string name="label_system_message_conversation_degraded">This conversation is no longer verified, as some user uses at least one device without a valid end-to-end identity certificate.</string>
<string name="label_system_message_conversation_verified_mls">All devices are verified (end-to-end identity)</string>
<string name="label_system_message_conversation_verified_proteus">All fingerprints are verified (Proteus)</string>
<string name="label_system_message_conversation_started_sensitive_information">Communication in Wire is always end-to-end encrypted. Everything you send and receive in this conversation is only accessible to you and other group participants.\n**Please still be careful with who you share sensitive information.**</string>
<!-- Last messages -->
<plurals name="last_message_self_added_users">
<item quantity="one">You added 1 person to the conversation</item>
Expand Down Expand Up @@ -823,6 +824,8 @@
<string name="connection_label_accepting_request_description">If you accept their request, they will be added as a contact and you two can communicate directly.</string>
<string name="connection_label_accept">Accept</string>
<string name="connection_label_ignore">Ignore</string>
<string name="connection_label_send_unverified_warning">Get certainty about the identity of %s\'s before connecting.</string>
<string name="connection_label_received_unverified_warning">Please verify the person\'s identity before accepting the connection request.</string>
<!-- Gallery -->
<string name="media_gallery_default_title_name">Media Gallery</string>
<string name="media_gallery_on_image_downloaded">Saved to Downloads folder</string>
Expand Down
2 changes: 1 addition & 1 deletion kalium
Submodule kalium updated 46 files
+1 βˆ’1 .github/workflows/codestyle.yml
+1 βˆ’1 .github/workflows/generate-changelog.yml
+1 βˆ’1 .github/workflows/generate-dokka.yml
+1 βˆ’1 .github/workflows/gradle-android-instrumented-tests.yml
+1 βˆ’1 .github/workflows/gradle-android-unit-tests.yml
+1 βˆ’1 .github/workflows/gradle-ios-tests.yml
+1 βˆ’1 .github/workflows/gradle-jvm-tests.yml
+1 βˆ’1 .github/workflows/semantic-commit-lint.yml
+3 βˆ’0 cryptography/build.gradle.kts
+9 βˆ’1 cryptography/src/appleMain/kotlin/com/wire/kalium/cryptography/MLSClientImpl.kt
+58 βˆ’12 cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/MLSClientImpl.kt
+25 βˆ’3 cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/IDs.kt
+29 βˆ’2 cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/MLSClient.kt
+5 βˆ’5 cryptography/src/commonTest/kotlin/com/wire/kalium/cryptography/E2EIClientTest.kt
+3 βˆ’2 cryptography/src/commonTest/kotlin/com/wire/kalium/cryptography/E2EIQualifiedIDTest.kt
+9 βˆ’1 cryptography/src/jsMain/kotlin/com/wire/kalium/cryptography/MLSClientImpl.kt
+19 βˆ’8 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/E2EIClientProvider.kt
+6 βˆ’0 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/ConversationGroupRepository.kt
+8 βˆ’2 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/ConversationMapper.kt
+1 βˆ’4 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepository.kt
+16 βˆ’0 .../src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/NewGroupConversationSystemMessagesCreator.kt
+14 βˆ’14 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/e2ei/E2EIRepository.kt
+4 βˆ’0 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/Message.kt
+2 βˆ’0 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageContent.kt
+3 βˆ’0 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageMapper.kt
+1 βˆ’0 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/PersistMessageUseCase.kt
+1 βˆ’1 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt
+8 βˆ’6 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt
+8 βˆ’2 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/connection/AcceptConnectionRequestUseCase.kt
+5 βˆ’2 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/connection/ConnectionScope.kt
+8 βˆ’2 logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/UserEventReceiver.kt
+1 βˆ’0 logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/NewConversationEventHandler.kt
+142 βˆ’0 logic/src/commonTest/kotlin/com/wire/kalium/logic/client/E2EIClientProviderTest.kt
+44 βˆ’0 logic/src/commonTest/kotlin/com/wire/kalium/logic/data/conversation/ConversationGroupRepositoryTest.kt
+24 βˆ’5 logic/src/commonTest/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepositoryTest.kt
+21 βˆ’0 .../commonTest/kotlin/com/wire/kalium/logic/data/conversation/NewGroupConversationSystemMessagesCreatorTest.kt
+2 βˆ’12 logic/src/commonTest/kotlin/com/wire/kalium/logic/data/e2ei/E2EIRepositoryTest.kt
+9 βˆ’3 logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/connection/AcceptConnectionRequestUseCaseTest.kt
+1 βˆ’1 logic/src/commonTest/kotlin/com/wire/kalium/logic/framework/TestUser.kt
+34 βˆ’18 logic/src/commonTest/kotlin/com/wire/kalium/logic/sync/receiver/UserEventReceiverTest.kt
+16 βˆ’1 ...c/src/commonTest/kotlin/com/wire/kalium/logic/sync/receiver/conversation/NewConversationEventHandlerTest.kt
+48 βˆ’0 ...onTest/kotlin/com/wire/kalium/logic/util/arrangement/NewGroupConversationSystemMessageCreatorArrangement.kt
+102 βˆ’0 logic/src/commonTest/kotlin/com/wire/kalium/logic/util/arrangement/provider/E2EIClientProviderArrangement.kt
+2 βˆ’1 persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/MessageEntity.kt
+6 βˆ’0 persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/MessageInsertExtension.kt
+3 βˆ’0 persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/MessageMapper.kt

0 comments on commit 1385f09

Please sign in to comment.