Revoke ThreePid invitation (#548)

This commit is contained in:
Benoit Marty 2020-07-09 17:47:41 +02:00
parent 863c09142f
commit c78bba803c
5 changed files with 48 additions and 4 deletions

View File

@ -18,4 +18,6 @@ package im.vector.riotx.features.roomprofile.members
import im.vector.riotx.core.platform.VectorViewModelAction import im.vector.riotx.core.platform.VectorViewModelAction
sealed class RoomMemberListAction : VectorViewModelAction sealed class RoomMemberListAction : VectorViewModelAction {
data class RevokeThreePidInvite(val stateKey: String) : RoomMemberListAction()
}

View File

@ -20,11 +20,14 @@ import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import androidx.appcompat.app.AlertDialog
import com.airbnb.mvrx.args import com.airbnb.mvrx.args
import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState import com.airbnb.mvrx.withState
import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.Event
import im.vector.matrix.android.api.session.events.model.toModel
import im.vector.matrix.android.api.session.room.model.RoomMemberSummary import im.vector.matrix.android.api.session.room.model.RoomMemberSummary
import im.vector.matrix.android.api.session.room.model.RoomThirdPartyInviteContent
import im.vector.matrix.android.api.util.toMatrixItem import im.vector.matrix.android.api.util.toMatrixItem
import im.vector.riotx.R import im.vector.riotx.R
import im.vector.riotx.core.extensions.cleanup import im.vector.riotx.core.extensions.cleanup
@ -90,7 +93,19 @@ class RoomMemberListFragment @Inject constructor(
} }
override fun onThreePidInvites(event: Event) { override fun onThreePidInvites(event: Event) {
// TODO Display a bottom sheet to revoke invite if power level is high enough // Display a dialog to revoke invite if power level is high enough
val content = event.content.toModel<RoomThirdPartyInviteContent>() ?: return
val stateKey = event.stateKey ?: return
if (withState(viewModel) { it.actionsPermissions.canRevokeThreePidInvite }) {
AlertDialog.Builder(requireActivity())
.setTitle(R.string.three_pid_revoke_invite_dialog_title)
.setMessage(getString(R.string.three_pid_revoke_invite_dialog_content, content.displayName))
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.revoke) { _, _ ->
viewModel.handle(RoomMemberListAction.RevokeThreePidInvite(stateKey))
}
.show()
}
} }
private fun renderRoomSummary(state: RoomMemberListViewState) { private fun renderRoomSummary(state: RoomMemberListViewState) {

View File

@ -16,11 +16,13 @@
package im.vector.riotx.features.roomprofile.members package im.vector.riotx.features.roomprofile.members
import androidx.lifecycle.viewModelScope
import com.airbnb.mvrx.FragmentViewModelContext import com.airbnb.mvrx.FragmentViewModelContext
import com.airbnb.mvrx.MvRxViewModelFactory import com.airbnb.mvrx.MvRxViewModelFactory
import com.airbnb.mvrx.ViewModelContext import com.airbnb.mvrx.ViewModelContext
import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.Assisted
import com.squareup.inject.assisted.AssistedInject import com.squareup.inject.assisted.AssistedInject
import im.vector.matrix.android.api.NoOpMatrixCallback
import im.vector.matrix.android.api.crypto.RoomEncryptionTrustLevel import im.vector.matrix.android.api.crypto.RoomEncryptionTrustLevel
import im.vector.matrix.android.api.extensions.orFalse import im.vector.matrix.android.api.extensions.orFalse
import im.vector.matrix.android.api.query.QueryStringValue import im.vector.matrix.android.api.query.QueryStringValue
@ -37,12 +39,14 @@ import im.vector.matrix.rx.asObservable
import im.vector.matrix.rx.mapOptional import im.vector.matrix.rx.mapOptional
import im.vector.matrix.rx.rx import im.vector.matrix.rx.rx
import im.vector.matrix.rx.unwrap import im.vector.matrix.rx.unwrap
import im.vector.riotx.core.extensions.exhaustive
import im.vector.riotx.core.platform.EmptyViewEvents import im.vector.riotx.core.platform.EmptyViewEvents
import im.vector.riotx.core.platform.VectorViewModel import im.vector.riotx.core.platform.VectorViewModel
import im.vector.riotx.features.powerlevel.PowerLevelsObservableFactory import im.vector.riotx.features.powerlevel.PowerLevelsObservableFactory
import io.reactivex.Observable import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.functions.BiFunction import io.reactivex.functions.BiFunction
import kotlinx.coroutines.launch
import timber.log.Timber import timber.log.Timber
class RoomMemberListViewModel @AssistedInject constructor(@Assisted initialState: RoomMemberListViewState, class RoomMemberListViewModel @AssistedInject constructor(@Assisted initialState: RoomMemberListViewState,
@ -125,7 +129,12 @@ class RoomMemberListViewModel @AssistedInject constructor(@Assisted initialState
PowerLevelsObservableFactory(room).createObservable() PowerLevelsObservableFactory(room).createObservable()
.subscribe { .subscribe {
val permissions = ActionPermissions( val permissions = ActionPermissions(
canInvite = PowerLevelsHelper(it).isUserAbleToInvite(session.myUserId) canInvite = PowerLevelsHelper(it).isUserAbleToInvite(session.myUserId),
canRevokeThreePidInvite = PowerLevelsHelper(it).isUserAllowedToSend(
userId = session.myUserId,
isState = true,
eventType = EventType.STATE_ROOM_THIRD_PARTY_INVITE
)
) )
setState { setState {
copy(actionsPermissions = permissions) copy(actionsPermissions = permissions)
@ -177,5 +186,19 @@ class RoomMemberListViewModel @AssistedInject constructor(@Assisted initialState
} }
override fun handle(action: RoomMemberListAction) { override fun handle(action: RoomMemberListAction) {
when (action) {
is RoomMemberListAction.RevokeThreePidInvite -> handleRevokeThreePidInvite(action)
}.exhaustive
}
private fun handleRevokeThreePidInvite(action: RoomMemberListAction.RevokeThreePidInvite) {
viewModelScope.launch {
room.sendStateEvent(
eventType = EventType.STATE_ROOM_THIRD_PARTY_INVITE,
stateKey = action.stateKey,
body = emptyMap(),
callback = NoOpMatrixCallback()
)
}
} }
} }

View File

@ -40,7 +40,8 @@ data class RoomMemberListViewState(
} }
data class ActionPermissions( data class ActionPermissions(
val canInvite: Boolean = false val canInvite: Boolean = false,
val canRevokeThreePidInvite: Boolean = false
) )
typealias RoomMemberSummaries = List<Pair<RoomMemberListCategories, List<RoomMemberSummary>>> typealias RoomMemberSummaries = List<Pair<RoomMemberListCategories, List<RoomMemberSummary>>>

View File

@ -2550,4 +2550,7 @@ Not all features in Riot are implemented in RiotX yet. Main missing (and coming
<string name="loading_contact_book">Retrieving your contacts…</string> <string name="loading_contact_book">Retrieving your contacts…</string>
<string name="empty_contact_book">Your contact book is empty</string> <string name="empty_contact_book">Your contact book is empty</string>
<string name="contacts_book_title">Contacts book</string> <string name="contacts_book_title">Contacts book</string>
<string name="three_pid_revoke_invite_dialog_title">Revoke invite</string>
<string name="three_pid_revoke_invite_dialog_content">Revoke invite to %1$s?</string>
</resources> </resources>