Add 3Pid to the list. Not compiling, I have to modify CreateRoomParam

This commit is contained in:
Benoit Marty 2020-07-09 11:27:45 +02:00
parent f714566200
commit 6c0bb2a949
13 changed files with 76 additions and 33 deletions

View file

@ -28,6 +28,14 @@ data class Invite3Pid(
@Json(name = "id_server") @Json(name = "id_server")
val idServer: String, val idServer: String,
/**
* Required.
* An access token previously registered with the identity server. Servers can treat this as optional to
* distinguish between r0.5-compatible clients and this specification version.
*/
@Json(name = "id_access_token")
val idAccessToken: String,
/** /**
* Required. * Required.
* The kind of address being passed in the address field, for example email. * The kind of address being passed in the address field, for example email.

View file

@ -16,9 +16,9 @@
package im.vector.riotx.features.createdirect package im.vector.riotx.features.createdirect
import im.vector.matrix.android.api.session.user.model.User
import im.vector.riotx.core.platform.VectorViewModelAction import im.vector.riotx.core.platform.VectorViewModelAction
import im.vector.riotx.features.userdirectory.PendingInvitee
sealed class CreateDirectRoomAction : VectorViewModelAction { sealed class CreateDirectRoomAction : VectorViewModelAction {
data class CreateRoomAndInviteSelectedUsers(val selectedUsers: Set<User>) : CreateDirectRoomAction() data class CreateRoomAndInviteSelectedUsers(val selectedUsers: Set<PendingInvitee>) : CreateDirectRoomAction()
} }

View file

@ -23,9 +23,9 @@ import com.squareup.inject.assisted.Assisted
import com.squareup.inject.assisted.AssistedInject import com.squareup.inject.assisted.AssistedInject
import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.Session
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.user.model.User
import im.vector.matrix.rx.rx import im.vector.matrix.rx.rx
import im.vector.riotx.core.platform.VectorViewModel import im.vector.riotx.core.platform.VectorViewModel
import im.vector.riotx.features.userdirectory.PendingInvitee
class CreateDirectRoomViewModel @AssistedInject constructor(@Assisted class CreateDirectRoomViewModel @AssistedInject constructor(@Assisted
initialState: CreateDirectRoomViewState, initialState: CreateDirectRoomViewState,
@ -52,7 +52,7 @@ class CreateDirectRoomViewModel @AssistedInject constructor(@Assisted
} }
} }
private fun createRoomAndInviteSelectedUsers(selectedUsers: Set<User>) { private fun createRoomAndInviteSelectedUsers(selectedUsers: Set<PendingInvitee>) {
val roomParams = CreateRoomParams( val roomParams = CreateRoomParams(
invitedUserIds = selectedUsers.map { it.userId } invitedUserIds = selectedUsers.map { it.userId }
) )

View file

@ -30,6 +30,7 @@ import im.vector.riotx.core.extensions.cleanup
import im.vector.riotx.core.extensions.configureWith import im.vector.riotx.core.extensions.configureWith
import im.vector.riotx.core.extensions.hideKeyboard import im.vector.riotx.core.extensions.hideKeyboard
import im.vector.riotx.core.platform.VectorBaseFragment import im.vector.riotx.core.platform.VectorBaseFragment
import im.vector.riotx.features.userdirectory.PendingInvitee
import im.vector.riotx.features.userdirectory.UserDirectoryAction import im.vector.riotx.features.userdirectory.UserDirectoryAction
import im.vector.riotx.features.userdirectory.UserDirectorySharedAction import im.vector.riotx.features.userdirectory.UserDirectorySharedAction
import im.vector.riotx.features.userdirectory.UserDirectorySharedActionViewModel import im.vector.riotx.features.userdirectory.UserDirectorySharedActionViewModel
@ -103,13 +104,13 @@ class PhoneBookFragment @Inject constructor(
override fun onMatrixIdClick(matrixId: String) { override fun onMatrixIdClick(matrixId: String) {
view?.hideKeyboard() view?.hideKeyboard()
viewModel.handle(UserDirectoryAction.SelectUser(User(matrixId))) viewModel.handle(UserDirectoryAction.SelectPendingInvitee(PendingInvitee.UserPendingInvitee(User(matrixId))))
sharedActionViewModel.post(UserDirectorySharedAction.GoBack) sharedActionViewModel.post(UserDirectorySharedAction.GoBack)
} }
override fun onThreePidClick(threePid: ThreePid) { override fun onThreePidClick(threePid: ThreePid) {
view?.hideKeyboard() view?.hideKeyboard()
viewModel.handle(UserDirectoryAction.SelectThreePid(threePid)) viewModel.handle(UserDirectoryAction.SelectPendingInvitee(PendingInvitee.ThreePidPendingInvitee(threePid)))
sharedActionViewModel.post(UserDirectorySharedAction.GoBack) sharedActionViewModel.post(UserDirectorySharedAction.GoBack)
} }
} }

View file

@ -60,7 +60,7 @@ class DirectoryUsersController @Inject constructor(private val session: Session,
is Loading -> renderLoading() is Loading -> renderLoading()
is Success -> renderSuccess( is Success -> renderSuccess(
computeUsersList(asyncUsers(), currentState.directorySearchTerm), computeUsersList(asyncUsers(), currentState.directorySearchTerm),
currentState.selectedUsers.map { it.userId }, currentState.getSelectedMatrixId(),
hasSearch hasSearch
) )
is Fail -> renderFailure(asyncUsers.error) is Fail -> renderFailure(asyncUsers.error)

View file

@ -51,7 +51,7 @@ class KnownUsersController @Inject constructor(private val session: Session,
fun setData(state: UserDirectoryViewState) { fun setData(state: UserDirectoryViewState) {
this.isFiltering = !state.filterKnownUsersValue.isEmpty() this.isFiltering = !state.filterKnownUsersValue.isEmpty()
val newSelection = state.selectedUsers.map { it.userId } val newSelection = state.getSelectedMatrixId()
this.users = state.knownUsers this.users = state.knownUsers
if (newSelection != selectedUsers) { if (newSelection != selectedUsers) {
this.selectedUsers = newSelection this.selectedUsers = newSelection

View file

@ -139,7 +139,7 @@ class KnownUsersFragment @Inject constructor(
knownUsersController.setData(it) knownUsersController.setData(it)
} }
private fun renderSelectedUsers(selectedUsers: Set<User>) { private fun renderSelectedUsers(selectedUsers: Set<PendingInvitee>) {
invalidateOptionsMenu() invalidateOptionsMenu()
val currentNumberOfChips = chipGroup.childCount val currentNumberOfChips = chipGroup.childCount
@ -156,22 +156,25 @@ class KnownUsersFragment @Inject constructor(
} }
} }
private fun addChipToGroup(user: User) { private fun addChipToGroup(pendingInvitee: PendingInvitee) {
val chip = Chip(requireContext()) val chip = Chip(requireContext())
chip.setChipBackgroundColorResource(android.R.color.transparent) chip.setChipBackgroundColorResource(android.R.color.transparent)
chip.chipStrokeWidth = dimensionConverter.dpToPx(1).toFloat() chip.chipStrokeWidth = dimensionConverter.dpToPx(1).toFloat()
chip.text = user.getBestName() chip.text = when (pendingInvitee) {
is PendingInvitee.UserPendingInvitee -> pendingInvitee.user.getBestName()
is PendingInvitee.ThreePidPendingInvitee -> pendingInvitee.threePid.value
}
chip.isClickable = true chip.isClickable = true
chip.isCheckable = false chip.isCheckable = false
chip.isCloseIconVisible = true chip.isCloseIconVisible = true
chipGroup.addView(chip) chipGroup.addView(chip)
chip.setOnCloseIconClickListener { chip.setOnCloseIconClickListener {
viewModel.handle(UserDirectoryAction.RemoveSelectedUser(user)) viewModel.handle(UserDirectoryAction.RemovePendingInvitee(pendingInvitee))
} }
} }
override fun onItemClick(user: User) { override fun onItemClick(user: User) {
view?.hideKeyboard() view?.hideKeyboard()
viewModel.handle(UserDirectoryAction.SelectUser(user)) viewModel.handle(UserDirectoryAction.SelectPendingInvitee(PendingInvitee.UserPendingInvitee(user)))
} }
} }

View file

@ -0,0 +1,25 @@
/*
* Copyright (c) 2020 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.riotx.features.userdirectory
import im.vector.matrix.android.api.session.identity.ThreePid
import im.vector.matrix.android.api.session.user.model.User
sealed class PendingInvitee {
data class UserPendingInvitee(val user: User): PendingInvitee()
data class ThreePidPendingInvitee(val threePid: ThreePid): PendingInvitee()
}

View file

@ -16,15 +16,12 @@
package im.vector.riotx.features.userdirectory package im.vector.riotx.features.userdirectory
import im.vector.matrix.android.api.session.identity.ThreePid
import im.vector.matrix.android.api.session.user.model.User
import im.vector.riotx.core.platform.VectorViewModelAction import im.vector.riotx.core.platform.VectorViewModelAction
sealed class UserDirectoryAction : VectorViewModelAction { sealed class UserDirectoryAction : VectorViewModelAction {
data class FilterKnownUsers(val value: String) : UserDirectoryAction() data class FilterKnownUsers(val value: String) : UserDirectoryAction()
data class SearchDirectoryUsers(val value: String) : UserDirectoryAction() data class SearchDirectoryUsers(val value: String) : UserDirectoryAction()
object ClearFilterKnownUsers : UserDirectoryAction() object ClearFilterKnownUsers : UserDirectoryAction()
data class SelectUser(val user: User) : UserDirectoryAction() data class SelectPendingInvitee(val pendingInvitee: PendingInvitee) : UserDirectoryAction()
data class SelectThreePid(val threePid: ThreePid) : UserDirectoryAction() data class RemovePendingInvitee(val pendingInvitee: PendingInvitee) : UserDirectoryAction()
data class RemoveSelectedUser(val user: User) : UserDirectoryAction()
} }

View file

@ -21,7 +21,6 @@ import android.view.View
import com.airbnb.mvrx.activityViewModel import com.airbnb.mvrx.activityViewModel
import com.airbnb.mvrx.withState import com.airbnb.mvrx.withState
import com.jakewharton.rxbinding3.widget.textChanges import com.jakewharton.rxbinding3.widget.textChanges
import im.vector.matrix.android.api.session.user.model.User
import im.vector.riotx.R import im.vector.riotx.R
import im.vector.riotx.core.extensions.cleanup import im.vector.riotx.core.extensions.cleanup
import im.vector.riotx.core.extensions.configureWith import im.vector.riotx.core.extensions.configureWith
@ -82,9 +81,9 @@ class UserDirectoryFragment @Inject constructor(
directRoomController.setData(it) directRoomController.setData(it)
} }
override fun onItemClick(user: User) { override fun onItemClick(pendingInvitee: PendingInvitee) {
view?.hideKeyboard() view?.hideKeyboard()
viewModel.handle(UserDirectoryAction.SelectUser(user)) viewModel.handle(UserDirectoryAction.SelectPendingInvitee(pendingInvitee))
sharedActionViewModel.post(UserDirectorySharedAction.GoBack) sharedActionViewModel.post(UserDirectorySharedAction.GoBack)
} }

View file

@ -16,7 +16,6 @@
package im.vector.riotx.features.userdirectory package im.vector.riotx.features.userdirectory
import im.vector.matrix.android.api.session.user.model.User
import im.vector.riotx.core.platform.VectorSharedAction import im.vector.riotx.core.platform.VectorSharedAction
sealed class UserDirectorySharedAction : VectorSharedAction { sealed class UserDirectorySharedAction : VectorSharedAction {
@ -24,5 +23,5 @@ sealed class UserDirectorySharedAction : VectorSharedAction {
object OpenPhoneBook : UserDirectorySharedAction() object OpenPhoneBook : UserDirectorySharedAction()
object Close : UserDirectorySharedAction() object Close : UserDirectorySharedAction()
object GoBack : UserDirectorySharedAction() object GoBack : UserDirectorySharedAction()
data class OnMenuItemSelected(val itemId: Int, val selectedUsers: Set<User>) : UserDirectorySharedAction() data class OnMenuItemSelected(val itemId: Int, val selectedUsers: Set<PendingInvitee>) : UserDirectorySharedAction()
} }

View file

@ -28,6 +28,7 @@ import com.squareup.inject.assisted.AssistedInject
import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.Session
import im.vector.matrix.android.api.util.toMatrixItem import im.vector.matrix.android.api.util.toMatrixItem
import im.vector.matrix.rx.rx import im.vector.matrix.rx.rx
import im.vector.riotx.core.extensions.exhaustive
import im.vector.riotx.core.extensions.toggle import im.vector.riotx.core.extensions.toggle
import im.vector.riotx.core.platform.VectorViewModel import im.vector.riotx.core.platform.VectorViewModel
import im.vector.riotx.features.createdirect.CreateDirectRoomActivity import im.vector.riotx.features.createdirect.CreateDirectRoomActivity
@ -59,9 +60,9 @@ class UserDirectoryViewModel @AssistedInject constructor(@Assisted
is FragmentViewModelContext -> (viewModelContext.fragment() as KnownUsersFragment).userDirectoryViewModelFactory.create(state) is FragmentViewModelContext -> (viewModelContext.fragment() as KnownUsersFragment).userDirectoryViewModelFactory.create(state)
is ActivityViewModelContext -> { is ActivityViewModelContext -> {
when (viewModelContext.activity<FragmentActivity>()) { when (viewModelContext.activity<FragmentActivity>()) {
is CreateDirectRoomActivity -> viewModelContext.activity<CreateDirectRoomActivity>().userDirectoryViewModelFactory.create(state) is CreateDirectRoomActivity -> viewModelContext.activity<CreateDirectRoomActivity>().userDirectoryViewModelFactory.create(state)
is InviteUsersToRoomActivity -> viewModelContext.activity<InviteUsersToRoomActivity>().userDirectoryViewModelFactory.create(state) is InviteUsersToRoomActivity -> viewModelContext.activity<InviteUsersToRoomActivity>().userDirectoryViewModelFactory.create(state)
else -> error("Wrong activity or fragment") else -> error("Wrong activity or fragment")
} }
} }
else -> error("Wrong activity or fragment") else -> error("Wrong activity or fragment")
@ -79,20 +80,20 @@ class UserDirectoryViewModel @AssistedInject constructor(@Assisted
is UserDirectoryAction.FilterKnownUsers -> knownUsersFilter.accept(Option.just(action.value)) is UserDirectoryAction.FilterKnownUsers -> knownUsersFilter.accept(Option.just(action.value))
is UserDirectoryAction.ClearFilterKnownUsers -> knownUsersFilter.accept(Option.empty()) is UserDirectoryAction.ClearFilterKnownUsers -> knownUsersFilter.accept(Option.empty())
is UserDirectoryAction.SearchDirectoryUsers -> directoryUsersSearch.accept(action.value) is UserDirectoryAction.SearchDirectoryUsers -> directoryUsersSearch.accept(action.value)
is UserDirectoryAction.SelectUser -> handleSelectUser(action) is UserDirectoryAction.SelectPendingInvitee -> handleSelectUser(action)
is UserDirectoryAction.RemoveSelectedUser -> handleRemoveSelectedUser(action) is UserDirectoryAction.RemovePendingInvitee -> handleRemoveSelectedUser(action)
} }.exhaustive
} }
private fun handleRemoveSelectedUser(action: UserDirectoryAction.RemoveSelectedUser) = withState { state -> private fun handleRemoveSelectedUser(action: UserDirectoryAction.RemovePendingInvitee) = withState { state ->
val selectedUsers = state.selectedUsers.minus(action.user) val selectedUsers = state.selectedUsers.minus(action.pendingInvitee)
setState { copy(selectedUsers = selectedUsers) } setState { copy(selectedUsers = selectedUsers) }
} }
private fun handleSelectUser(action: UserDirectoryAction.SelectUser) = withState { state -> private fun handleSelectUser(action: UserDirectoryAction.SelectPendingInvitee) = withState { state ->
// Reset the filter asap // Reset the filter asap
directoryUsersSearch.accept("") directoryUsersSearch.accept("")
val selectedUsers = state.selectedUsers.toggle(action.user) val selectedUsers = state.selectedUsers.toggle(action.pendingInvitee)
setState { copy(selectedUsers = selectedUsers) } setState { copy(selectedUsers = selectedUsers) }
} }

View file

@ -27,11 +27,21 @@ data class UserDirectoryViewState(
val excludedUserIds: Set<String>? = null, val excludedUserIds: Set<String>? = null,
val knownUsers: Async<PagedList<User>> = Uninitialized, val knownUsers: Async<PagedList<User>> = Uninitialized,
val directoryUsers: Async<List<User>> = Uninitialized, val directoryUsers: Async<List<User>> = Uninitialized,
val selectedUsers: Set<User> = emptySet(), val selectedUsers: Set<PendingInvitee> = emptySet(),
val createAndInviteState: Async<String> = Uninitialized, val createAndInviteState: Async<String> = Uninitialized,
val directorySearchTerm: String = "", val directorySearchTerm: String = "",
val filterKnownUsersValue: Option<String> = Option.empty() val filterKnownUsersValue: Option<String> = Option.empty()
) : MvRxState { ) : MvRxState {
constructor(args: KnownUsersFragmentArgs) : this(excludedUserIds = args.excludedUserIds) constructor(args: KnownUsersFragmentArgs) : this(excludedUserIds = args.excludedUserIds)
fun getSelectedMatrixId(): List<String> {
return selectedUsers
.mapNotNull {
when (it) {
is PendingInvitee.UserPendingInvitee -> it.user.userId
is PendingInvitee.ThreePidPendingInvitee -> null
}
}
}
} }