Add action to report a user form the user profile view. EventId is not relevant, but requested by the API.
This commit is contained in:
parent
99ec61e120
commit
b14cb81ece
|
@ -22,6 +22,7 @@ import im.vector.app.core.platform.VectorViewModelAction
|
||||||
sealed class RoomMemberProfileAction : VectorViewModelAction {
|
sealed class RoomMemberProfileAction : VectorViewModelAction {
|
||||||
object RetryFetchingInfo : RoomMemberProfileAction()
|
object RetryFetchingInfo : RoomMemberProfileAction()
|
||||||
object IgnoreUser : RoomMemberProfileAction()
|
object IgnoreUser : RoomMemberProfileAction()
|
||||||
|
object ReportUser : RoomMemberProfileAction()
|
||||||
data class BanOrUnbanUser(val reason: String?) : RoomMemberProfileAction()
|
data class BanOrUnbanUser(val reason: String?) : RoomMemberProfileAction()
|
||||||
data class KickUser(val reason: String?) : RoomMemberProfileAction()
|
data class KickUser(val reason: String?) : RoomMemberProfileAction()
|
||||||
object InviteUser : RoomMemberProfileAction()
|
object InviteUser : RoomMemberProfileAction()
|
||||||
|
|
|
@ -39,6 +39,7 @@ class RoomMemberProfileController @Inject constructor(
|
||||||
|
|
||||||
interface Callback {
|
interface Callback {
|
||||||
fun onIgnoreClicked()
|
fun onIgnoreClicked()
|
||||||
|
fun onReportClicked()
|
||||||
fun onTapVerify()
|
fun onTapVerify()
|
||||||
fun onShowDeviceList()
|
fun onShowDeviceList()
|
||||||
fun onShowDeviceListNoCrossSigning()
|
fun onShowDeviceListNoCrossSigning()
|
||||||
|
@ -225,7 +226,7 @@ class RoomMemberProfileController @Inject constructor(
|
||||||
title = stringProvider.getString(R.string.room_participants_action_invite),
|
title = stringProvider.getString(R.string.room_participants_action_invite),
|
||||||
destructive = false,
|
destructive = false,
|
||||||
editable = false,
|
editable = false,
|
||||||
divider = ignoreActionTitle != null,
|
divider = true,
|
||||||
action = { callback?.onInviteClicked() }
|
action = { callback?.onInviteClicked() }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -235,10 +236,18 @@ class RoomMemberProfileController @Inject constructor(
|
||||||
title = ignoreActionTitle,
|
title = ignoreActionTitle,
|
||||||
destructive = true,
|
destructive = true,
|
||||||
editable = false,
|
editable = false,
|
||||||
divider = false,
|
divider = true,
|
||||||
action = { callback?.onIgnoreClicked() }
|
action = { callback?.onIgnoreClicked() }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
buildProfileAction(
|
||||||
|
id = "report",
|
||||||
|
title = stringProvider.getString(R.string.message_report_user),
|
||||||
|
destructive = true,
|
||||||
|
editable = false,
|
||||||
|
divider = false,
|
||||||
|
action = { callback?.onReportClicked() }
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,9 +323,9 @@ class RoomMemberProfileController @Inject constructor(
|
||||||
private fun RoomMemberProfileViewState.buildIgnoreActionTitle(): String? {
|
private fun RoomMemberProfileViewState.buildIgnoreActionTitle(): String? {
|
||||||
val isIgnored = isIgnored() ?: return null
|
val isIgnored = isIgnored() ?: return null
|
||||||
return if (isIgnored) {
|
return if (isIgnored) {
|
||||||
stringProvider.getString(R.string.unignore)
|
stringProvider.getString(R.string.room_participants_action_unignore_title)
|
||||||
} else {
|
} else {
|
||||||
stringProvider.getString(R.string.action_ignore)
|
stringProvider.getString(R.string.room_participants_action_ignore_title)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,11 +140,20 @@ class RoomMemberProfileFragment :
|
||||||
is RoomMemberProfileViewEvents.OnIgnoreActionSuccess -> Unit
|
is RoomMemberProfileViewEvents.OnIgnoreActionSuccess -> Unit
|
||||||
is RoomMemberProfileViewEvents.OnInviteActionSuccess -> Unit
|
is RoomMemberProfileViewEvents.OnInviteActionSuccess -> Unit
|
||||||
RoomMemberProfileViewEvents.GoBack -> handleGoBack()
|
RoomMemberProfileViewEvents.GoBack -> handleGoBack()
|
||||||
|
RoomMemberProfileViewEvents.OnReportActionSuccess -> handleReportSuccess()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setupLongClicks()
|
setupLongClicks()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun handleReportSuccess() {
|
||||||
|
MaterialAlertDialogBuilder(requireContext())
|
||||||
|
.setTitle(R.string.user_reported_as_inappropriate_title)
|
||||||
|
.setMessage(R.string.user_reported_as_inappropriate_content)
|
||||||
|
.setPositiveButton(R.string.ok, null)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
private fun setupLongClicks() {
|
private fun setupLongClicks() {
|
||||||
headerViews.memberProfileNameView.copyOnLongClick()
|
headerViews.memberProfileNameView.copyOnLongClick()
|
||||||
headerViews.memberProfileIdView.copyOnLongClick()
|
headerViews.memberProfileIdView.copyOnLongClick()
|
||||||
|
@ -301,6 +310,10 @@ class RoomMemberProfileFragment :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onReportClicked() {
|
||||||
|
viewModel.handle(RoomMemberProfileAction.ReportUser)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onTapVerify() {
|
override fun onTapVerify() {
|
||||||
viewModel.handle(RoomMemberProfileAction.VerifyUser)
|
viewModel.handle(RoomMemberProfileAction.VerifyUser)
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ sealed class RoomMemberProfileViewEvents : VectorViewEvents {
|
||||||
data class Failure(val throwable: Throwable) : RoomMemberProfileViewEvents()
|
data class Failure(val throwable: Throwable) : RoomMemberProfileViewEvents()
|
||||||
|
|
||||||
object OnIgnoreActionSuccess : RoomMemberProfileViewEvents()
|
object OnIgnoreActionSuccess : RoomMemberProfileViewEvents()
|
||||||
|
object OnReportActionSuccess : RoomMemberProfileViewEvents()
|
||||||
object OnSetPowerLevelSuccess : RoomMemberProfileViewEvents()
|
object OnSetPowerLevelSuccess : RoomMemberProfileViewEvents()
|
||||||
object OnInviteActionSuccess : RoomMemberProfileViewEvents()
|
object OnInviteActionSuccess : RoomMemberProfileViewEvents()
|
||||||
object OnKickActionSuccess : RoomMemberProfileViewEvents()
|
object OnKickActionSuccess : RoomMemberProfileViewEvents()
|
||||||
|
|
|
@ -161,6 +161,7 @@ class RoomMemberProfileViewModel @AssistedInject constructor(
|
||||||
when (action) {
|
when (action) {
|
||||||
is RoomMemberProfileAction.RetryFetchingInfo -> handleRetryFetchProfileInfo()
|
is RoomMemberProfileAction.RetryFetchingInfo -> handleRetryFetchProfileInfo()
|
||||||
is RoomMemberProfileAction.IgnoreUser -> handleIgnoreAction()
|
is RoomMemberProfileAction.IgnoreUser -> handleIgnoreAction()
|
||||||
|
is RoomMemberProfileAction.ReportUser -> handleReportAction()
|
||||||
is RoomMemberProfileAction.VerifyUser -> prepareVerification()
|
is RoomMemberProfileAction.VerifyUser -> prepareVerification()
|
||||||
is RoomMemberProfileAction.ShareRoomMemberProfile -> handleShareRoomMemberProfile()
|
is RoomMemberProfileAction.ShareRoomMemberProfile -> handleShareRoomMemberProfile()
|
||||||
is RoomMemberProfileAction.SetPowerLevel -> handleSetPowerLevel(action)
|
is RoomMemberProfileAction.SetPowerLevel -> handleSetPowerLevel(action)
|
||||||
|
@ -172,6 +173,25 @@ class RoomMemberProfileViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun handleReportAction() {
|
||||||
|
viewModelScope.launch {
|
||||||
|
val event = try {
|
||||||
|
// The API need an Event, use the latest Event.
|
||||||
|
val latestEventId = room?.roomSummary()?.latestPreviewableEvent?.eventId ?: return@launch
|
||||||
|
room.reportingService()
|
||||||
|
.reportContent(
|
||||||
|
eventId = latestEventId,
|
||||||
|
score = -100,
|
||||||
|
reason = "Reporting user ${initialState.userId} (eventId is not relevant)"
|
||||||
|
)
|
||||||
|
RoomMemberProfileViewEvents.OnReportActionSuccess
|
||||||
|
} catch (failure: Throwable) {
|
||||||
|
RoomMemberProfileViewEvents.Failure(failure)
|
||||||
|
}
|
||||||
|
_viewEvents.post(event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun handleOpenOrCreateDm(action: RoomMemberProfileAction.OpenOrCreateDm) {
|
private fun handleOpenOrCreateDm(action: RoomMemberProfileAction.OpenOrCreateDm) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
_viewEvents.post(RoomMemberProfileViewEvents.Loading())
|
_viewEvents.post(RoomMemberProfileViewEvents.Loading())
|
||||||
|
|
Loading…
Reference in New Issue