Skip to content

Commit

Permalink
Add unencrypted room type (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
yostyle authored Jan 2, 2025
1 parent e487802 commit 80498d9
Show file tree
Hide file tree
Showing 30 changed files with 197 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class CreateRoomDataStore @Inject constructor(
config.copy(
roomVisibility = when (visibility) {
RoomVisibilityItem.Private -> RoomVisibilityState.Private
RoomVisibilityItem.PrivateNotEncrypted -> RoomVisibilityState.PrivateNotEncrypted // TCHAP room type
RoomVisibilityItem.Public -> {
val roomAliasName = roomAliasHelper.roomAliasNameFromRoomDisplayName(config.roomName.orEmpty())
RoomVisibilityState.Public(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,30 +185,45 @@ class ConfigureRoomPresenter @Inject constructor(
) = launch {
suspend {
val avatarUrl = config.avatarUri?.let { uploadAvatar(it) }
val params = if (config.roomVisibility is RoomVisibilityState.Public) {
CreateRoomParameters(
name = config.roomName,
topic = config.topic,
isEncrypted = false,
isDirect = false,
visibility = RoomVisibility.PUBLIC,
joinRuleOverride = config.roomVisibility.roomAccess.toJoinRule(),
preset = RoomPreset.PUBLIC_CHAT,
invite = config.invites.map { it.userId },
avatar = avatarUrl,
roomAliasName = config.roomVisibility.roomAddress()
)
} else {
CreateRoomParameters(
name = config.roomName,
topic = config.topic,
isEncrypted = config.roomVisibility is RoomVisibilityState.Private,
isDirect = false,
visibility = RoomVisibility.PRIVATE,
preset = RoomPreset.PRIVATE_CHAT,
invite = config.invites.map { it.userId },
avatar = avatarUrl,
)
val params = when (config.roomVisibility) {
is RoomVisibilityState.Public -> {
CreateRoomParameters(
name = config.roomName,
topic = config.topic,
isEncrypted = false,
isDirect = false,
visibility = RoomVisibility.PUBLIC,
joinRuleOverride = config.roomVisibility.roomAccess.toJoinRule(),
preset = RoomPreset.PUBLIC_CHAT,
invite = config.invites.map { it.userId },
avatar = avatarUrl,
roomAliasName = config.roomVisibility.roomAddress()
)
}
is RoomVisibilityState.Private -> {
CreateRoomParameters(
name = config.roomName,
topic = config.topic,
isEncrypted = true,
isDirect = false,
visibility = RoomVisibility.PRIVATE,
preset = RoomPreset.PRIVATE_CHAT,
invite = config.invites.map { it.userId },
avatar = avatarUrl,
)
}
is RoomVisibilityState.PrivateNotEncrypted -> { // TCHAP room type
CreateRoomParameters(
name = config.roomName,
topic = config.topic,
isEncrypted = false,
isDirect = false,
visibility = RoomVisibility.PRIVATE,
preset = RoomPreset.PRIVATE_CHAT,
invite = config.invites.map { it.userId },
avatar = avatarUrl,
)
}
}
matrixClient.createRoom(params)
.onFailure { failure ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@ data class ConfigureRoomState(
val eventSink: (ConfigureRoomEvents) -> Unit
) {
val isValid: Boolean = config.roomName?.isNotEmpty() == true &&
(config.roomVisibility is RoomVisibilityState.Private || roomAddressValidity == RoomAddressValidity.Valid)
(config.roomVisibility is RoomVisibilityState.Private ||
config.roomVisibility is RoomVisibilityState.PrivateNotEncrypted || // TCHAP room type
roomAddressValidity == RoomAddressValidity.Valid)
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ fun ConfigureRoomView(
RoomVisibilityOptions(
selected = when (state.config.roomVisibility) {
is RoomVisibilityState.Private -> RoomVisibilityItem.Private
is RoomVisibilityState.PrivateNotEncrypted -> RoomVisibilityItem.PrivateNotEncrypted // TCHAP room type
is RoomVisibilityState.Public -> RoomVisibilityItem.Public
},
onOptionClick = {
Expand Down Expand Up @@ -275,7 +276,7 @@ private fun RoomVisibilityOptions(
modifier: Modifier = Modifier,
) {
ConfigureRoomOptions(
title = stringResource(R.string.screen_create_room_room_visibility_section_title),
title = stringResource(R.string.tchap_screen_create_room_room_access_encryption_section_title),
modifier = modifier,
) {
RoomVisibilityItem.entries.forEach { item ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,20 @@ enum class RoomVisibilityItem(
@StringRes val title: Int,
@StringRes val description: Int
) {
// TCHAP room type
Private(
icon = CompoundDrawables.ic_compound_lock,
title = R.string.tchap_screen_create_room_private_encrypted_option_title,
description = R.string.tchap_screen_create_room_private_encrypted_option_description,
),
PrivateNotEncrypted(
icon = CompoundDrawables.ic_compound_lock_off,
title = R.string.screen_create_room_private_option_title,
description = R.string.screen_create_room_private_option_description,
description = R.string.tchap_screen_create_room_private_not_encrypted_option_description,
),
Public(
icon = CompoundDrawables.ic_compound_public,
title = R.string.screen_create_room_public_option_title,
description = R.string.screen_create_room_public_option_description,
description = R.string.tchap_screen_create_room_public_option_description,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ import java.util.Optional
sealed interface RoomVisibilityState {
data object Private : RoomVisibilityState

data object PrivateNotEncrypted : RoomVisibilityState // TCHAP room type

data class Public(
val roomAddress: RoomAddress,
val roomAccess: RoomAccess,
) : RoomVisibilityState

fun roomAddress(): Optional<String> {
return when (this) {
is PrivateNotEncrypted, // TCHAP room type
is Private -> Optional.empty()
is Public -> Optional.of(roomAddress.value)
}
Expand Down
37 changes: 37 additions & 0 deletions features/createroom/impl/src/main/res/values-fr/strings_tchap.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ MIT License
~
~ Copyright (c) 2024. DINUM
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is
~ furnished to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
~ EXPRESS OR IMPLIED, INCLUDING BUT NOgit T LIMITED TO THE WARRANTIES OF
~ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
~ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
~ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
~ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
~ OR OTHER DEALINGS IN THE SOFTWARE.
-->

<resources>
<string name="tchap_screen_create_room_room_access_encryption_section_title">"Sécurité et accès du salon"</string>
<string name="tchap_screen_create_room_private_encrypted_option_description">"• Messages chiffrés
• Accessible sur invitation
• Limité à 500 membres."</string>
<string name="tchap_screen_create_room_private_encrypted_option_title">"Salon privé sécurisé"</string>
<string name="tchap_screen_create_room_private_not_encrypted_option_description">"• Messages non‑chiffrés
• Accessible sur invitation
• Nombre de membres illimité."</string>
<string name="tchap_screen_create_room_public_option_description">"• Messages non‑chiffrés
• Accessible à tous les agents depuis la liste des salons publics
• Nombre de membres illimité."</string>
</resources>
37 changes: 37 additions & 0 deletions features/createroom/impl/src/main/res/values/strings_tchap.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ MIT License
~
~ Copyright (c) 2024. DINUM
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is
~ furnished to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
~ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
~ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
~ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
~ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
~ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
~ OR OTHER DEALINGS IN THE SOFTWARE.
-->

<resources>
<string name="tchap_screen_create_room_room_access_encryption_section_title">"Room Access and Security"</string>
<string name="tchap_screen_create_room_private_encrypted_option_description">"• Encrypted messages
• Access by invite
• Limited to 500 members"</string>
<string name="tchap_screen_create_room_private_encrypted_option_title">"Secure private room"</string>
<string name="tchap_screen_create_room_private_not_encrypted_option_description">"• Not encrypted messages
• Access by invite
• Unlimited members"</string>
<string name="tchap_screen_create_room_public_option_description">"• Not encrypted messages
• Accessible to all agents from public rooms directory
• Unlimited members"</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ private fun MessagesViewComposerBottomSheetContents(
if (state.composerState.suggestions.isEmpty() &&
state.composerState.textEditorState is TextEditorState.Markdown) {
IdentityChangeStateView(
isDebugBuild = state.isDebugBuild,
state = state.identityChangeState,
onLinkClick = onLinkClick,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import io.element.android.libraries.ui.strings.CommonStrings

@Composable
fun IdentityChangeStateView(
isDebugBuild: Boolean,
state: IdentityChangeState,
onLinkClick: (String) -> Unit,
modifier: Modifier = Modifier,
Expand All @@ -45,21 +46,31 @@ fun IdentityChangeStateView(
CommonStrings.crypto_identity_change_pin_violation_new_user_id,
pinViolationIdentityChange.identityRoomMember.userId,
)
val fullText = stringResource(
id = CommonStrings.crypto_identity_change_pin_violation_new,
displayName,
userIdStr,
learnMoreStr,
)
val fullText = if (isDebugBuild) { // TCHAP hide the Matrix Id in release mode
stringResource(
id = CommonStrings.crypto_identity_change_pin_violation_new,
displayName,
userIdStr,
learnMoreStr,
)
} else {
stringResource(
id = CommonStrings.crypto_identity_change_pin_violation,
displayName,
learnMoreStr,
)
}
append(fullText)
val userIdStartIndex = fullText.indexOf(userIdStr)
addStyle(
style = SpanStyle(
fontWeight = FontWeight.Bold,
),
start = userIdStartIndex,
end = userIdStartIndex + userIdStr.length,
)
if (isDebugBuild) { // TCHAP hide the Matrix Id in release mode
val userIdStartIndex = fullText.indexOf(userIdStr)
addStyle(
style = SpanStyle(
fontWeight = FontWeight.Bold,
),
start = userIdStartIndex,
end = userIdStartIndex + userIdStr.length,
)
}
val learnMoreStartIndex = fullText.lastIndexOf(learnMoreStr)
addStyle(
style = SpanStyle(
Expand Down Expand Up @@ -92,6 +103,7 @@ internal fun IdentityChangeStateViewPreview(
@PreviewParameter(IdentityChangeStateProvider::class) state: IdentityChangeState,
) = ElementPreview {
IdentityChangeStateView(
isDebugBuild = false,
state = state,
onLinkClick = {},
)
Expand Down
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.
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.
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.
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.
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

0 comments on commit 80498d9

Please sign in to comment.