Block user possibility after reporting event content

This commit is contained in:
Benoit Marty 2019-11-05 16:32:43 +01:00
parent 99d09f71ad
commit d9f15c1d21
6 changed files with 40 additions and 15 deletions

View File

@ -50,7 +50,14 @@ sealed class RoomDetailActions {
data class ResendMessage(val eventId: String) : RoomDetailActions()
data class RemoveFailedEcho(val eventId: String) : RoomDetailActions()
data class ReportContent(val eventId: String, val reason: String, val spam: Boolean = false, val inappropriate: Boolean = false) : RoomDetailActions()
data class ReportContent(
val eventId: String,
val senderId: String?,
val reason: String,
val spam: Boolean = false,
val inappropriate: Boolean = false) : RoomDetailActions()
data class IgnoreUser(val userId: String?) : RoomDetailActions()
object ClearSendQueue : RoomDetailActions()
object ResendAll : RoomDetailActions()

View File

@ -757,7 +757,7 @@ class RoomDetailFragment @Inject constructor(
.setView(layout)
.setPositiveButton(R.string.report_content_custom_submit) { _, _ ->
val reason = input.text.toString()
roomDetailViewModel.process(RoomDetailActions.ReportContent(action.eventId, reason))
roomDetailViewModel.process(RoomDetailActions.ReportContent(action.eventId, action.senderId, reason))
}
.setNegativeButton(R.string.cancel, null)
.show()
@ -781,7 +781,7 @@ class RoomDetailFragment @Inject constructor(
.setTitle(R.string.content_reported_as_spam_title)
.setMessage(R.string.content_reported_as_spam_content)
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.block_user) { _, _ -> vectorBaseActivity.notImplemented("block user") }
.setNegativeButton(R.string.block_user) { _, _ -> roomDetailViewModel.process(RoomDetailActions.IgnoreUser(data.senderId)) }
.show()
.withColoredButton(DialogInterface.BUTTON_NEGATIVE)
}
@ -790,7 +790,7 @@ class RoomDetailFragment @Inject constructor(
.setTitle(R.string.content_reported_as_inappropriate_title)
.setMessage(R.string.content_reported_as_inappropriate_content)
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.block_user) { _, _ -> vectorBaseActivity.notImplemented("block user") }
.setNegativeButton(R.string.block_user) { _, _ -> roomDetailViewModel.process(RoomDetailActions.IgnoreUser(data.senderId)) }
.show()
.withColoredButton(DialogInterface.BUTTON_NEGATIVE)
}
@ -799,7 +799,7 @@ class RoomDetailFragment @Inject constructor(
.setTitle(R.string.content_reported_title)
.setMessage(R.string.content_reported_content)
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.block_user) { _, _ -> vectorBaseActivity.notImplemented("block user") }
.setNegativeButton(R.string.block_user) { _, _ -> roomDetailViewModel.process(RoomDetailActions.IgnoreUser(data.senderId)) }
.show()
.withColoredButton(DialogInterface.BUTTON_NEGATIVE)
}
@ -1124,10 +1124,10 @@ class RoomDetailFragment @Inject constructor(
roomDetailViewModel.process(RoomDetailActions.RemoveFailedEcho(action.eventId))
}
is SimpleAction.ReportContentSpam -> {
roomDetailViewModel.process(RoomDetailActions.ReportContent(action.eventId, "This message is spam", spam = true))
roomDetailViewModel.process(RoomDetailActions.ReportContent(action.eventId, action.senderId, "This message is spam", spam = true))
}
is SimpleAction.ReportContentInappropriate -> {
roomDetailViewModel.process(RoomDetailActions.ReportContent(action.eventId, "This message is inappropriate", inappropriate = true))
roomDetailViewModel.process(RoomDetailActions.ReportContent(action.eventId, action.senderId, "This message is inappropriate", inappropriate = true))
}
is SimpleAction.ReportContentCustom -> {
promptReasonToReportContent(action)

View File

@ -157,6 +157,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
is RoomDetailActions.SetReadMarkerAction -> handleSetReadMarkerAction(action)
is RoomDetailActions.MarkAllAsRead -> handleMarkAllAsRead()
is RoomDetailActions.ReportContent -> handleReportContent(action)
is RoomDetailActions.IgnoreUser -> handleIgnoreUser(action)
}
}
@ -710,6 +711,23 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
})
}
private fun handleIgnoreUser(action: RoomDetailActions.IgnoreUser) {
if (action.userId.isNullOrEmpty()) {
return
}
session.ignoreUserIds(listOf(action.userId), object : MatrixCallback<Unit> {
override fun onSuccess(data: Unit) {
_requestLiveData.postValue(LiveEvent(Success(action)))
}
override fun onFailure(failure: Throwable) {
_requestLiveData.postValue(LiveEvent(Fail(failure)))
}
})
}
private fun observeSyncState() {
session.rx()
.liveSyncState()

View File

@ -102,9 +102,9 @@ class MessageActionsEpoxyController @Inject constructor(private val stringProvid
if (action is SimpleAction.ReportContent && state.expendedReportContentMenu) {
// Special case for report content menu: add the submenu
listOf(
SimpleAction.ReportContentSpam(action.eventId),
SimpleAction.ReportContentInappropriate(action.eventId),
SimpleAction.ReportContentCustom(action.eventId)
SimpleAction.ReportContentSpam(action.eventId, action.senderId),
SimpleAction.ReportContentInappropriate(action.eventId, action.senderId),
SimpleAction.ReportContentCustom(action.eventId, action.senderId)
).forEachIndexed { indexReport, actionReport ->
bottomSheetItemAction {
id("actionReport_$indexReport")

View File

@ -263,7 +263,7 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted
if (session.myUserId != event.root.senderId && event.root.getClearType() == EventType.MESSAGE) {
// not sent by me
add(SimpleAction.ReportContent(eventId))
add(SimpleAction.ReportContent(eventId, event.root.senderId))
}
}
}

View File

@ -35,10 +35,10 @@ sealed class SimpleAction(@StringRes val titleRes: Int, @DrawableRes val iconRes
data class ViewSource(val content: String) : SimpleAction(R.string.view_source, R.drawable.ic_view_source)
data class ViewDecryptedSource(val content: String) : SimpleAction(R.string.view_decrypted_source, R.drawable.ic_view_source)
data class CopyPermalink(val eventId: String) : SimpleAction(R.string.permalink, R.drawable.ic_permalink)
data class ReportContent(val eventId: String) : SimpleAction(R.string.report_content, R.drawable.ic_flag)
data class ReportContentSpam(val eventId: String) : SimpleAction(R.string.report_content_spam, R.drawable.ic_report_spam)
data class ReportContentInappropriate(val eventId: String) : SimpleAction(R.string.report_content_inappropriate, R.drawable.ic_report_inappropriate)
data class ReportContentCustom(val eventId: String) : SimpleAction(R.string.report_content_custom, R.drawable.ic_report_custom)
data class ReportContent(val eventId: String, val senderId: String?) : SimpleAction(R.string.report_content, R.drawable.ic_flag)
data class ReportContentSpam(val eventId: String, val senderId: String?) : SimpleAction(R.string.report_content_spam, R.drawable.ic_report_spam)
data class ReportContentInappropriate(val eventId: String, val senderId: String?) : SimpleAction(R.string.report_content_inappropriate, R.drawable.ic_report_inappropriate)
data class ReportContentCustom(val eventId: String, val senderId: String?) : SimpleAction(R.string.report_content_custom, R.drawable.ic_report_custom)
data class QuickReact(val eventId: String, val clickedOn: String, val add: Boolean) : SimpleAction(0, 0)
data class ViewReactions(val messageInformationData: MessageInformationData) : SimpleAction(R.string.message_view_reaction, R.drawable.ic_view_reactions)
data class ViewEditHistory(val messageInformationData: MessageInformationData) :