Code review

This commit is contained in:
Valere 2021-09-24 18:11:28 +02:00
parent 91ba17f71b
commit 0acf90d8cd
10 changed files with 68 additions and 69 deletions

View File

@ -202,6 +202,8 @@ internal class DefaultIdentityService @Inject constructor(
identityStore.setUrl(urlCandidate)
identityStore.setToken(token)
// could we remember if it was previously given?
identityStore.setUserConsent(false)
updateIdentityAPI(urlCandidate)
updateAccountData(urlCandidate)

View File

@ -20,6 +20,7 @@ import android.content.Context
import android.webkit.WebView
import android.webkit.WebViewClient
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import im.vector.app.R
/**
* Open a web view above the current activity.
@ -38,3 +39,14 @@ fun Context.displayInWebView(url: String) {
.setPositiveButton(android.R.string.ok, null)
.show()
}
fun Context.showIdentityServerConsentDialog(configuredIdentityServer: String?, consentCallBack: (() -> Unit)) {
MaterialAlertDialogBuilder(this)
.setTitle(R.string.identity_server_consent_dialog_title)
.setMessage(getString(R.string.identity_server_consent_dialog_content, configuredIdentityServer ?: ""))
.setPositiveButton(R.string.yes) { _, _ ->
consentCallBack?.invoke()
}
.setNegativeButton(R.string.no, null)
.show()
}

View File

@ -23,14 +23,13 @@ import android.view.ViewGroup
import androidx.core.view.isVisible
import com.airbnb.mvrx.activityViewModel
import com.airbnb.mvrx.withState
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.jakewharton.rxbinding3.widget.checkedChanges
import com.jakewharton.rxbinding3.widget.textChanges
import im.vector.app.R
import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.configureWith
import im.vector.app.core.extensions.hideKeyboard
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.utils.showIdentityServerConsentDialog
import im.vector.app.databinding.FragmentContactsBookBinding
import im.vector.app.features.userdirectory.PendingSelection
import im.vector.app.features.userdirectory.UserListAction
@ -76,14 +75,9 @@ class ContactsBookFragment @Inject constructor(
private fun setupConsentView() {
views.phoneBookSearchForMatrixContacts.setOnClickListener {
withState(contactsBookViewModel) { state ->
MaterialAlertDialogBuilder(requireActivity())
.setTitle(R.string.identity_server_consent_dialog_title)
.setMessage(getString(R.string.identity_server_consent_dialog_content, state.identityServerUrl ?: ""))
.setPositiveButton(R.string.yes) { _, _ ->
contactsBookViewModel.handle(ContactsBookAction.UserConsentGranted)
}
.setNegativeButton(R.string.no, null)
.show()
requireContext().showIdentityServerConsentDialog(state.identityServerUrl) {
contactsBookViewModel.handle(ContactsBookAction.UserConsentGranted)
}
}
}
}

View File

@ -32,6 +32,7 @@ import im.vector.app.core.extensions.observeEvent
import im.vector.app.core.extensions.registerStartForActivityResult
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.utils.ensureProtocol
import im.vector.app.core.utils.showIdentityServerConsentDialog
import im.vector.app.databinding.FragmentGenericRecyclerBinding
import im.vector.app.features.discovery.change.SetIdentityServerFragment
import im.vector.app.features.settings.VectorSettingsActivity
@ -179,14 +180,9 @@ class DiscoverySettingsFragment @Inject constructor(
override fun onTapUpdateUserConsent(newValue: Boolean) {
if (newValue) {
withState(viewModel) { state ->
MaterialAlertDialogBuilder(requireActivity())
.setTitle(R.string.identity_server_consent_dialog_title)
.setMessage(getString(R.string.identity_server_consent_dialog_content, state.identityServer.invoke()))
.setPositiveButton(R.string.yes) { _, _ ->
viewModel.handle(DiscoverySettingsAction.UpdateUserConsent(true))
}
.setNegativeButton(R.string.no, null)
.show()
requireContext().showIdentityServerConsentDialog(state.identityServer.invoke()) {
viewModel.handle(DiscoverySettingsAction.UpdateUserConsent(true))
}
}
} else {
viewModel.handle(DiscoverySettingsAction.UpdateUserConsent(false))

View File

@ -65,7 +65,7 @@ class DiscoverySettingsViewModel @AssistedInject constructor(
setState {
copy(
identityServer = Success(identityServerUrl),
userConsent = false
userConsent = identityService.getUserConsent()
)
}
if (currentIS != identityServerUrl) retrieveBinding()

View File

@ -28,7 +28,7 @@ import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.features.home.AvatarRenderer
@EpoxyModelClass(layout = R.layout.item_invite_by_mail)
abstract class FoundThreePidItem : VectorEpoxyModel<FoundThreePidItem.Holder>() {
abstract class InviteByEmailItem : VectorEpoxyModel<InviteByEmailItem.Holder>() {
@EpoxyAttribute lateinit var avatarRenderer: AvatarRenderer
@EpoxyAttribute lateinit var foundItem: ThreePidUser

View File

@ -93,45 +93,46 @@ class UserListController @Inject constructor(private val session: Session,
when (val matchingEmail = currentState.matchingEmail) {
is Success -> {
userListHeaderItem {
id("is_matching")
header(host.stringProvider.getString(R.string.discovery_section, currentState.configuredIdentityServer ?: ""))
}
val invoke = matchingEmail()
val isSelected = currentState.pendingSelections.indexOfFirst { pendingSelection ->
when (pendingSelection) {
is PendingSelection.ThreePidPendingSelection -> {
when (pendingSelection.threePid) {
is ThreePid.Email -> pendingSelection.threePid.email == invoke?.email
is ThreePid.Msisdn -> false
matchingEmail()?.let { threePidUser ->
userListHeaderItem {
id("identity_server_result_header")
header(host.stringProvider.getString(R.string.discovery_section, currentState.configuredIdentityServer ?: ""))
}
val isSelected = currentState.pendingSelections.any { pendingSelection ->
when (pendingSelection) {
is PendingSelection.ThreePidPendingSelection -> {
when (pendingSelection.threePid) {
is ThreePid.Email -> pendingSelection.threePid.email == threePidUser.email
is ThreePid.Msisdn -> false
}
}
is PendingSelection.UserPendingSelection -> {
threePidUser.user != null && threePidUser.user.userId == pendingSelection.user.userId
}
}
is PendingSelection.UserPendingSelection -> {
invoke?.user != null && invoke.user.userId == pendingSelection.user.userId
}
}
} != -1
if (invoke?.user == null) {
foundThreePidItem {
id("email_${invoke?.email}")
foundItem(invoke!!)
selected(isSelected)
clickListener {
host.callback?.onThreePidClick(ThreePid.Email(invoke.email))
if (threePidUser.user == null) {
inviteByEmailItem {
id("email_${threePidUser.email}")
foundItem(threePidUser)
selected(isSelected)
clickListener {
host.callback?.onThreePidClick(ThreePid.Email(threePidUser.email))
}
}
}
} else {
userDirectoryUserItem {
id(invoke.user.userId)
selected(isSelected)
matrixItem(invoke.user.toMatrixItem().let {
it.copy(
displayName = "${it.displayName} [${invoke.email}]"
)
})
avatarRenderer(host.avatarRenderer)
clickListener {
host.callback?.onItemClick(invoke.user)
} else {
userDirectoryUserItem {
id(threePidUser.user.userId)
selected(isSelected)
matrixItem(threePidUser.user.toMatrixItem().let {
it.copy(
displayName = "${it.getBestName()} [${threePidUser.email}]"
)
})
avatarRenderer(host.avatarRenderer)
clickListener {
host.callback?.onItemClick(threePidUser.user)
}
}
}
}
@ -191,7 +192,7 @@ class UserListController @Inject constructor(private val session: Session,
}
is Loading -> {
userListHeaderItem {
id("is_matching")
id("identity_server_result_header_loading")
header(host.stringProvider.getString(R.string.discovery_section, currentState.configuredIdentityServer ?: ""))
}
loadingItem {

View File

@ -31,7 +31,6 @@ import com.airbnb.mvrx.args
import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import com.google.android.material.chip.Chip
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.jakewharton.rxbinding3.widget.textChanges
import im.vector.app.R
import im.vector.app.core.extensions.cleanup
@ -40,6 +39,7 @@ import im.vector.app.core.extensions.hideKeyboard
import im.vector.app.core.extensions.setupAsSearch
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.utils.DimensionConverter
import im.vector.app.core.utils.showIdentityServerConsentDialog
import im.vector.app.core.utils.startSharePlainTextIntent
import im.vector.app.databinding.FragmentUserListBinding
import im.vector.app.features.homeserver.HomeServerCapabilitiesViewModel
@ -228,14 +228,9 @@ class UserListFragment @Inject constructor(
override fun giveIdentityServerConsent() {
withState(viewModel) { state ->
MaterialAlertDialogBuilder(requireActivity())
.setTitle(R.string.identity_server_consent_dialog_title)
.setMessage(getString(R.string.identity_server_consent_dialog_content, state.configuredIdentityServer ?: ""))
.setPositiveButton(R.string.yes) { _, _ ->
viewModel.handle(UserListAction.UpdateUserConsent(true))
}
.setNegativeButton(R.string.no, null)
.show()
requireContext().showIdentityServerConsentDialog(state.configuredIdentityServer) {
viewModel.handle(UserListAction.UpdateUserConsent(true))
}
}
}

View File

@ -1,6 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
@ -13,7 +11,7 @@
android:padding="8dp">
<FrameLayout
android:id="@+id/knownUserAvatarContainer"
android:id="@+id/iconContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
@ -58,7 +56,7 @@
app:layout_constraintBottom_toTopOf="@+id/itemDescription"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/knownUserAvatarContainer"
app:layout_constraintStart_toEndOf="@+id/iconContainer"
app:layout_constraintTop_toTopOf="parent"
tools:text="foo@example.com" />

View File

@ -3483,6 +3483,7 @@
<string name="finish_setting_up_discovery">Finish setting up discovery.</string>
<string name="discovery_invite">Invite by email, find contacts and more…</string>
<string name="finish_setup">Finish setup</string>
<!-- %s will be replaced by the user identity server domain, e.g vector.im -->
<string name="discovery_section">Discovery (%s)</string>