Merge pull request #912 from vector-im/feature/e2e_opt_out

e2e opt in when creating room (not DM)
This commit is contained in:
Benoit Marty 2020-01-29 10:29:33 +01:00 committed by GitHub
commit 73bb4bb785
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 39 additions and 3 deletions

View File

@ -3,6 +3,7 @@ Changes in RiotX 0.14.0 (2020-XX-XX)
Features ✨: Features ✨:
- Enable encryption in unencrypted rooms, from the room settings (#212) - Enable encryption in unencrypted rooms, from the room settings (#212)
- Enable e2e by default when creating DM, and give the possibility to enable encryption when creating room (#837)
Improvements 🙌: Improvements 🙌:
- Sharing things to RiotX: sort list by recent room first (#771) - Sharing things to RiotX: sort list by recent room first (#771)

View File

@ -44,6 +44,12 @@ abstract class FormSwitchItem : VectorEpoxyModel<FormSwitchItem.Holder>() {
var summary: String? = null var summary: String? = null
override fun bind(holder: Holder) { override fun bind(holder: Holder) {
holder.view.setOnClickListener {
if (enabled) {
holder.switchView.toggle()
}
}
holder.titleView.text = title holder.titleView.text = title
holder.summaryView.setTextOrHide(summary) holder.summaryView.setTextOrHide(summary)

View File

@ -22,5 +22,6 @@ sealed class CreateRoomAction : VectorViewModelAction {
data class SetName(val name: String) : CreateRoomAction() data class SetName(val name: String) : CreateRoomAction()
data class SetIsPublic(val isPublic: Boolean) : CreateRoomAction() data class SetIsPublic(val isPublic: Boolean) : CreateRoomAction()
data class SetIsInRoomDirectory(val isInRoomDirectory: Boolean) : CreateRoomAction() data class SetIsInRoomDirectory(val isInRoomDirectory: Boolean) : CreateRoomAction()
data class SetIsEncrypted(val isEncrypted: Boolean) : CreateRoomAction()
object Create : CreateRoomAction() object Create : CreateRoomAction()
} }

View File

@ -39,9 +39,7 @@ class CreateRoomController @Inject constructor(private val stringProvider: Strin
var index = 0 var index = 0
override fun buildModels(viewState: CreateRoomViewState) { override fun buildModels(viewState: CreateRoomViewState) {
val asyncCreateRoom = viewState.asyncCreateRoomRequest when (val asyncCreateRoom = viewState.asyncCreateRoomRequest) {
when (asyncCreateRoom) {
is Success -> { is Success -> {
// Nothing to display, the screen will be closed // Nothing to display, the screen will be closed
} }
@ -101,12 +99,24 @@ class CreateRoomController @Inject constructor(private val stringProvider: Strin
listener?.setIsInRoomDirectory(value) listener?.setIsInRoomDirectory(value)
} }
} }
formSwitchItem {
id("encryption")
enabled(enableFormElement)
title(stringProvider.getString(R.string.create_room_encryption_title))
summary(stringProvider.getString(R.string.create_room_encryption_description))
switchChecked(viewState.isEncrypted)
listener { value ->
listener?.setIsEncrypted(value)
}
}
} }
interface Listener { interface Listener {
fun onNameChange(newName: String) fun onNameChange(newName: String)
fun setIsPublic(isPublic: Boolean) fun setIsPublic(isPublic: Boolean)
fun setIsInRoomDirectory(isInRoomDirectory: Boolean) fun setIsInRoomDirectory(isInRoomDirectory: Boolean)
fun setIsEncrypted(isEncrypted: Boolean)
fun retry() fun retry()
} }
} }

View File

@ -85,6 +85,10 @@ class CreateRoomFragment @Inject constructor(private val createRoomController: C
viewModel.handle(CreateRoomAction.SetIsInRoomDirectory(isInRoomDirectory)) viewModel.handle(CreateRoomAction.SetIsInRoomDirectory(isInRoomDirectory))
} }
override fun setIsEncrypted(isEncrypted: Boolean) {
viewModel.handle(CreateRoomAction.SetIsEncrypted(isEncrypted))
}
override fun retry() { override fun retry() {
Timber.v("Retry") Timber.v("Retry")
viewModel.handle(CreateRoomAction.Create) viewModel.handle(CreateRoomAction.Create)

View File

@ -31,6 +31,7 @@ import im.vector.matrix.android.api.session.room.model.RoomDirectoryVisibility
import im.vector.matrix.android.api.session.room.model.create.CreateRoomParams import im.vector.matrix.android.api.session.room.model.create.CreateRoomParams
import im.vector.matrix.android.api.session.room.model.create.CreateRoomPreset import im.vector.matrix.android.api.session.room.model.create.CreateRoomPreset
import im.vector.riotx.core.platform.EmptyViewEvents import im.vector.riotx.core.platform.EmptyViewEvents
import im.vector.matrix.android.internal.crypto.MXCRYPTO_ALGORITHM_MEGOLM
import im.vector.riotx.core.platform.VectorViewModel import im.vector.riotx.core.platform.VectorViewModel
import im.vector.riotx.features.roomdirectory.RoomDirectoryActivity import im.vector.riotx.features.roomdirectory.RoomDirectoryActivity
@ -62,6 +63,7 @@ class CreateRoomViewModel @AssistedInject constructor(@Assisted initialState: Cr
is CreateRoomAction.SetName -> setName(action) is CreateRoomAction.SetName -> setName(action)
is CreateRoomAction.SetIsPublic -> setIsPublic(action) is CreateRoomAction.SetIsPublic -> setIsPublic(action)
is CreateRoomAction.SetIsInRoomDirectory -> setIsInRoomDirectory(action) is CreateRoomAction.SetIsInRoomDirectory -> setIsInRoomDirectory(action)
is CreateRoomAction.SetIsEncrypted -> setIsEncrypted(action)
is CreateRoomAction.Create -> doCreateRoom() is CreateRoomAction.Create -> doCreateRoom()
} }
} }
@ -72,6 +74,8 @@ class CreateRoomViewModel @AssistedInject constructor(@Assisted initialState: Cr
private fun setIsInRoomDirectory(action: CreateRoomAction.SetIsInRoomDirectory) = setState { copy(isInRoomDirectory = action.isInRoomDirectory) } private fun setIsInRoomDirectory(action: CreateRoomAction.SetIsInRoomDirectory) = setState { copy(isInRoomDirectory = action.isInRoomDirectory) }
private fun setIsEncrypted(action: CreateRoomAction.SetIsEncrypted) = setState { copy(isEncrypted = action.isEncrypted) }
private fun doCreateRoom() = withState { state -> private fun doCreateRoom() = withState { state ->
if (state.asyncCreateRoomRequest is Loading || state.asyncCreateRoomRequest is Success) { if (state.asyncCreateRoomRequest is Loading || state.asyncCreateRoomRequest is Success) {
return@withState return@withState
@ -89,6 +93,11 @@ class CreateRoomViewModel @AssistedInject constructor(@Assisted initialState: Cr
// Public room // Public room
preset = if (state.isPublic) CreateRoomPreset.PRESET_PUBLIC_CHAT else CreateRoomPreset.PRESET_PRIVATE_CHAT preset = if (state.isPublic) CreateRoomPreset.PRESET_PUBLIC_CHAT else CreateRoomPreset.PRESET_PRIVATE_CHAT
// Encryption
if (state.isEncrypted) {
enableEncryptionWithAlgorithm(MXCRYPTO_ALGORITHM_MEGOLM)
}
} }
session.createRoom(createRoomParams, object : MatrixCallback<String> { session.createRoom(createRoomParams, object : MatrixCallback<String> {

View File

@ -24,5 +24,6 @@ data class CreateRoomViewState(
val roomName: String = "", val roomName: String = "",
val isPublic: Boolean = false, val isPublic: Boolean = false,
val isInRoomDirectory: Boolean = false, val isInRoomDirectory: Boolean = false,
val isEncrypted: Boolean = false,
val asyncCreateRoomRequest: Async<String> = Uninitialized val asyncCreateRoomRequest: Async<String> = Uninitialized
) : MvRxState ) : MvRxState

View File

@ -5,6 +5,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?riotx_background" android:background="?riotx_background"
android:foreground="?attr/selectableItemBackground"
android:minHeight="@dimen/item_form_min_height"> android:minHeight="@dimen/item_form_min_height">
<TextView <TextView

View File

@ -3,6 +3,9 @@
<!-- Strings not defined in Riot --> <!-- Strings not defined in Riot -->
<string name="create_room_encryption_title">"Enable encryption"</string>
<string name="create_room_encryption_description">"Once enabled, encryption cannot be disabled."</string>
<string name="login_error_threepid_denied">Your email domain is not authorized to register on this server</string> <string name="login_error_threepid_denied">Your email domain is not authorized to register on this server</string>
<string name="room_profile_not_encrypted_subtitle">Messages in this room are not end-to-end encrypted.</string> <string name="room_profile_not_encrypted_subtitle">Messages in this room are not end-to-end encrypted.</string>