Report content: confirmation dialogs

This commit is contained in:
Benoit Marty 2019-10-10 18:06:33 +02:00
parent a7a19dab11
commit 4a6237b50e
5 changed files with 71 additions and 21 deletions

View File

@ -50,7 +50,7 @@ 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) : RoomDetailActions()
data class ReportContent(val eventId: String, val reason: String, val spam: Boolean = false, val inappropriate: Boolean = false) : RoomDetailActions()
object ClearSendQueue : RoomDetailActions()
object ResendAll : RoomDetailActions()

View File

@ -268,6 +268,10 @@ class RoomDetailFragment :
roomDetailViewModel.selectSubscribe(RoomDetailViewState::syncState) { syncState ->
syncStateView.render(syncState)
}
roomDetailViewModel.requestLiveData.observeEvent(this) {
displayRoomDetailActionResult(it)
}
}
override fun onDestroy() {
@ -777,6 +781,51 @@ class RoomDetailFragment :
.show()
}
private fun displayRoomDetailActionResult(result: Async<RoomDetailActions>) {
when (result) {
is Fail -> {
AlertDialog.Builder(activity!!)
.setTitle(R.string.dialog_title_error)
.setMessage(errorFormatter.toHumanReadable(result.error))
.setPositiveButton(R.string.ok, null)
.show()
}
is Success -> {
when (val data = result.invoke()) {
is RoomDetailActions.ReportContent -> {
when {
data.spam -> {
AlertDialog.Builder(activity!!)
.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") }
.show()
}
data.inappropriate -> {
AlertDialog.Builder(activity!!)
.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") }
.show()
}
else -> {
AlertDialog.Builder(activity!!)
.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") }
.show()
}
}
}
}
}
}
}
// TimelineEventController.Callback ************************************************************
override fun onUrlClicked(url: String): Boolean {
@ -1064,10 +1113,10 @@ class RoomDetailFragment :
roomDetailViewModel.process(RoomDetailActions.RemoveFailedEcho(action.eventId))
}
is SimpleAction.ReportContentSpam -> {
roomDetailViewModel.process(RoomDetailActions.ReportContent(action.eventId, "This message is spam"))
roomDetailViewModel.process(RoomDetailActions.ReportContent(action.eventId, "This message is spam", spam = true))
}
is SimpleAction.ReportContentInappropriate -> {
roomDetailViewModel.process(RoomDetailActions.ReportContent(action.eventId, "This message is inappropriate"))
roomDetailViewModel.process(RoomDetailActions.ReportContent(action.eventId, "This message is inappropriate", inappropriate = true))
}
// TODO Custom
else -> {

View File

@ -94,6 +94,11 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
private var timeline = room.createTimeline(eventId, timelineSettings)
// Can be used for several actions, for a one shot result
private val _requestLiveData = MutableLiveData<LiveEvent<Async<RoomDetailActions>>>()
val requestLiveData: LiveData<LiveEvent<Async<RoomDetailActions>>>
get() = _requestLiveData
// Slot to keep a pending action during permission request
var pendingAction: RoomDetailActions? = null
@ -707,27 +712,13 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
}
private fun handleReportContent(action: RoomDetailActions.ReportContent) {
setState {
copy(
reportContentRequest = Loading()
)
}
room.reportContent(action.eventId, -100, action.reason, object : MatrixCallback<Unit> {
override fun onSuccess(data: Unit) {
setState {
copy(
reportContentRequest = Success(Unit)
)
}
_requestLiveData.postValue(LiveEvent(Success(action)))
}
override fun onFailure(failure: Throwable) {
setState {
copy(
reportContentRequest = Fail(failure)
)
}
_requestLiveData.postValue(LiveEvent(Fail(failure)))
}
})
}

View File

@ -52,8 +52,7 @@ data class RoomDetailViewState(
val tombstoneEvent: Event? = null,
val tombstoneEventHandling: Async<String> = Uninitialized,
val syncState: SyncState = SyncState.IDLE,
val highlightedEventId: String? = null,
val reportContentRequest: Async<Unit> = Uninitialized
val highlightedEventId: String? = null
) : MvRxState {
constructor(args: RoomDetailArgs) : this(roomId = args.roomId, eventId = args.eventId)

View File

@ -41,4 +41,15 @@
<string name="report_content_spam">"It's spam"</string>
<string name="report_content_inappropriate">"It's inappropriate"</string>
<string name="report_content_custom">"Custom report"</string>
<string name="report_content_custom_title">"Report this content"</string>
<string name="report_content_custom_hint">"Reason for reporting this content"</string>
<string name="report_content_custom_submit">"REPORT"</string>
<string name="block_user">"BLOCK USER"</string>
<string name="content_reported_title">"Content reported"</string>
<string name="content_reported_content">"This content was reported.\n\nIf you don't want to see any more content from this user, you can block him to hide his messages"</string>
<string name="content_reported_as_spam_title">"Reported as spam"</string>
<string name="content_reported_as_spam_content">"This content was reported as spam.\n\nIf you don't want to see any more content from this user, you can block him to hide his messages"</string>
<string name="content_reported_as_inappropriate_title">"Reported as inappropriate"</string>
<string name="content_reported_as_inappropriate_content">"This content was reported as inappropriate.\n\nIf you don't want to see any more content from this user, you can block him to hide his messages"</string>
</resources>