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")
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.
* 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
import im.vector.matrix.android.api.session.user.model.User
import im.vector.riotx.core.platform.VectorViewModelAction
import im.vector.riotx.features.userdirectory.PendingInvitee
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 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.user.model.User
import im.vector.matrix.rx.rx
import im.vector.riotx.core.platform.VectorViewModel
import im.vector.riotx.features.userdirectory.PendingInvitee
class CreateDirectRoomViewModel @AssistedInject constructor(@Assisted
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(
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.hideKeyboard
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.UserDirectorySharedAction
import im.vector.riotx.features.userdirectory.UserDirectorySharedActionViewModel
@ -103,13 +104,13 @@ class PhoneBookFragment @Inject constructor(
override fun onMatrixIdClick(matrixId: String) {
view?.hideKeyboard()
viewModel.handle(UserDirectoryAction.SelectUser(User(matrixId)))
viewModel.handle(UserDirectoryAction.SelectPendingInvitee(PendingInvitee.UserPendingInvitee(User(matrixId))))
sharedActionViewModel.post(UserDirectorySharedAction.GoBack)
}
override fun onThreePidClick(threePid: ThreePid) {
view?.hideKeyboard()
viewModel.handle(UserDirectoryAction.SelectThreePid(threePid))
viewModel.handle(UserDirectoryAction.SelectPendingInvitee(PendingInvitee.ThreePidPendingInvitee(threePid)))
sharedActionViewModel.post(UserDirectorySharedAction.GoBack)
}
}

View File

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

View File

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

View File

@ -139,7 +139,7 @@ class KnownUsersFragment @Inject constructor(
knownUsersController.setData(it)
}
private fun renderSelectedUsers(selectedUsers: Set<User>) {
private fun renderSelectedUsers(selectedUsers: Set<PendingInvitee>) {
invalidateOptionsMenu()
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())
chip.setChipBackgroundColorResource(android.R.color.transparent)
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.isCheckable = false
chip.isCloseIconVisible = true
chipGroup.addView(chip)
chip.setOnCloseIconClickListener {
viewModel.handle(UserDirectoryAction.RemoveSelectedUser(user))
viewModel.handle(UserDirectoryAction.RemovePendingInvitee(pendingInvitee))
}
}
override fun onItemClick(user: User) {
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
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
sealed class UserDirectoryAction : VectorViewModelAction {
data class FilterKnownUsers(val value: String) : UserDirectoryAction()
data class SearchDirectoryUsers(val value: String) : UserDirectoryAction()
object ClearFilterKnownUsers : UserDirectoryAction()
data class SelectUser(val user: User) : UserDirectoryAction()
data class SelectThreePid(val threePid: ThreePid) : UserDirectoryAction()
data class RemoveSelectedUser(val user: User) : UserDirectoryAction()
data class SelectPendingInvitee(val pendingInvitee: PendingInvitee) : UserDirectoryAction()
data class RemovePendingInvitee(val pendingInvitee: PendingInvitee) : UserDirectoryAction()
}

View File

@ -21,7 +21,6 @@ import android.view.View
import com.airbnb.mvrx.activityViewModel
import com.airbnb.mvrx.withState
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.core.extensions.cleanup
import im.vector.riotx.core.extensions.configureWith
@ -82,9 +81,9 @@ class UserDirectoryFragment @Inject constructor(
directRoomController.setData(it)
}
override fun onItemClick(user: User) {
override fun onItemClick(pendingInvitee: PendingInvitee) {
view?.hideKeyboard()
viewModel.handle(UserDirectoryAction.SelectUser(user))
viewModel.handle(UserDirectoryAction.SelectPendingInvitee(pendingInvitee))
sharedActionViewModel.post(UserDirectorySharedAction.GoBack)
}

View File

@ -16,7 +16,6 @@
package im.vector.riotx.features.userdirectory
import im.vector.matrix.android.api.session.user.model.User
import im.vector.riotx.core.platform.VectorSharedAction
sealed class UserDirectorySharedAction : VectorSharedAction {
@ -24,5 +23,5 @@ sealed class UserDirectorySharedAction : VectorSharedAction {
object OpenPhoneBook : UserDirectorySharedAction()
object Close : 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.util.toMatrixItem
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.platform.VectorViewModel
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 ActivityViewModelContext -> {
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)
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.ClearFilterKnownUsers -> knownUsersFilter.accept(Option.empty())
is UserDirectoryAction.SearchDirectoryUsers -> directoryUsersSearch.accept(action.value)
is UserDirectoryAction.SelectUser -> handleSelectUser(action)
is UserDirectoryAction.RemoveSelectedUser -> handleRemoveSelectedUser(action)
}
is UserDirectoryAction.SelectPendingInvitee -> handleSelectUser(action)
is UserDirectoryAction.RemovePendingInvitee -> handleRemoveSelectedUser(action)
}.exhaustive
}
private fun handleRemoveSelectedUser(action: UserDirectoryAction.RemoveSelectedUser) = withState { state ->
val selectedUsers = state.selectedUsers.minus(action.user)
private fun handleRemoveSelectedUser(action: UserDirectoryAction.RemovePendingInvitee) = withState { state ->
val selectedUsers = state.selectedUsers.minus(action.pendingInvitee)
setState { copy(selectedUsers = selectedUsers) }
}
private fun handleSelectUser(action: UserDirectoryAction.SelectUser) = withState { state ->
private fun handleSelectUser(action: UserDirectoryAction.SelectPendingInvitee) = withState { state ->
// Reset the filter asap
directoryUsersSearch.accept("")
val selectedUsers = state.selectedUsers.toggle(action.user)
val selectedUsers = state.selectedUsers.toggle(action.pendingInvitee)
setState { copy(selectedUsers = selectedUsers) }
}

View File

@ -27,11 +27,21 @@ data class UserDirectoryViewState(
val excludedUserIds: Set<String>? = null,
val knownUsers: Async<PagedList<User>> = Uninitialized,
val directoryUsers: Async<List<User>> = Uninitialized,
val selectedUsers: Set<User> = emptySet(),
val selectedUsers: Set<PendingInvitee> = emptySet(),
val createAndInviteState: Async<String> = Uninitialized,
val directorySearchTerm: String = "",
val filterKnownUsersValue: Option<String> = Option.empty()
) : MvRxState {
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
}
}
}
}