Merge pull request #912 from vector-im/feature/e2e_opt_out
e2e opt in when creating room (not DM)
This commit is contained in:
commit
73bb4bb785
|
@ -3,6 +3,7 @@ Changes in RiotX 0.14.0 (2020-XX-XX)
|
|||
|
||||
Features ✨:
|
||||
- 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 🙌:
|
||||
- Sharing things to RiotX: sort list by recent room first (#771)
|
||||
|
|
|
@ -44,6 +44,12 @@ abstract class FormSwitchItem : VectorEpoxyModel<FormSwitchItem.Holder>() {
|
|||
var summary: String? = null
|
||||
|
||||
override fun bind(holder: Holder) {
|
||||
holder.view.setOnClickListener {
|
||||
if (enabled) {
|
||||
holder.switchView.toggle()
|
||||
}
|
||||
}
|
||||
|
||||
holder.titleView.text = title
|
||||
holder.summaryView.setTextOrHide(summary)
|
||||
|
||||
|
|
|
@ -22,5 +22,6 @@ sealed class CreateRoomAction : VectorViewModelAction {
|
|||
data class SetName(val name: String) : CreateRoomAction()
|
||||
data class SetIsPublic(val isPublic: Boolean) : CreateRoomAction()
|
||||
data class SetIsInRoomDirectory(val isInRoomDirectory: Boolean) : CreateRoomAction()
|
||||
data class SetIsEncrypted(val isEncrypted: Boolean) : CreateRoomAction()
|
||||
object Create : CreateRoomAction()
|
||||
}
|
||||
|
|
|
@ -39,9 +39,7 @@ class CreateRoomController @Inject constructor(private val stringProvider: Strin
|
|||
var index = 0
|
||||
|
||||
override fun buildModels(viewState: CreateRoomViewState) {
|
||||
val asyncCreateRoom = viewState.asyncCreateRoomRequest
|
||||
|
||||
when (asyncCreateRoom) {
|
||||
when (val asyncCreateRoom = viewState.asyncCreateRoomRequest) {
|
||||
is Success -> {
|
||||
// Nothing to display, the screen will be closed
|
||||
}
|
||||
|
@ -101,12 +99,24 @@ class CreateRoomController @Inject constructor(private val stringProvider: Strin
|
|||
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 {
|
||||
fun onNameChange(newName: String)
|
||||
fun setIsPublic(isPublic: Boolean)
|
||||
fun setIsInRoomDirectory(isInRoomDirectory: Boolean)
|
||||
fun setIsEncrypted(isEncrypted: Boolean)
|
||||
fun retry()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,6 +85,10 @@ class CreateRoomFragment @Inject constructor(private val createRoomController: C
|
|||
viewModel.handle(CreateRoomAction.SetIsInRoomDirectory(isInRoomDirectory))
|
||||
}
|
||||
|
||||
override fun setIsEncrypted(isEncrypted: Boolean) {
|
||||
viewModel.handle(CreateRoomAction.SetIsEncrypted(isEncrypted))
|
||||
}
|
||||
|
||||
override fun retry() {
|
||||
Timber.v("Retry")
|
||||
viewModel.handle(CreateRoomAction.Create)
|
||||
|
|
|
@ -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.CreateRoomPreset
|
||||
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.features.roomdirectory.RoomDirectoryActivity
|
||||
|
||||
|
@ -62,6 +63,7 @@ class CreateRoomViewModel @AssistedInject constructor(@Assisted initialState: Cr
|
|||
is CreateRoomAction.SetName -> setName(action)
|
||||
is CreateRoomAction.SetIsPublic -> setIsPublic(action)
|
||||
is CreateRoomAction.SetIsInRoomDirectory -> setIsInRoomDirectory(action)
|
||||
is CreateRoomAction.SetIsEncrypted -> setIsEncrypted(action)
|
||||
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 setIsEncrypted(action: CreateRoomAction.SetIsEncrypted) = setState { copy(isEncrypted = action.isEncrypted) }
|
||||
|
||||
private fun doCreateRoom() = withState { state ->
|
||||
if (state.asyncCreateRoomRequest is Loading || state.asyncCreateRoomRequest is Success) {
|
||||
return@withState
|
||||
|
@ -89,6 +93,11 @@ class CreateRoomViewModel @AssistedInject constructor(@Assisted initialState: Cr
|
|||
|
||||
// Public room
|
||||
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> {
|
||||
|
|
|
@ -24,5 +24,6 @@ data class CreateRoomViewState(
|
|||
val roomName: String = "",
|
||||
val isPublic: Boolean = false,
|
||||
val isInRoomDirectory: Boolean = false,
|
||||
val isEncrypted: Boolean = false,
|
||||
val asyncCreateRoomRequest: Async<String> = Uninitialized
|
||||
) : MvRxState
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?riotx_background"
|
||||
android:foreground="?attr/selectableItemBackground"
|
||||
android:minHeight="@dimen/item_form_min_height">
|
||||
|
||||
<TextView
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
|
||||
<!-- 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="room_profile_not_encrypted_subtitle">Messages in this room are not end-to-end encrypted.</string>
|
||||
|
|
Loading…
Reference in New Issue