mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 20:06:51 +03:00
Merge pull request #2402 from Dominaezzz/suspend_functions_1
Convert ReportingService to suspend functions
This commit is contained in:
commit
6ff12b3a88
3 changed files with 12 additions and 24 deletions
|
@ -16,9 +16,6 @@
|
|||
|
||||
package org.matrix.android.sdk.api.session.room.reporting
|
||||
|
||||
import org.matrix.android.sdk.api.MatrixCallback
|
||||
import org.matrix.android.sdk.api.util.Cancelable
|
||||
|
||||
/**
|
||||
* This interface defines methods to report content of an event.
|
||||
*/
|
||||
|
@ -28,5 +25,5 @@ interface ReportingService {
|
|||
* Report content
|
||||
* Ref: https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-rooms-roomid-report-eventid
|
||||
*/
|
||||
fun reportContent(eventId: String, score: Int, reason: String, callback: MatrixCallback<Unit>): Cancelable
|
||||
suspend fun reportContent(eventId: String, score: Int, reason: String)
|
||||
}
|
||||
|
|
|
@ -18,14 +18,9 @@ package org.matrix.android.sdk.internal.session.room.reporting
|
|||
|
||||
import com.squareup.inject.assisted.Assisted
|
||||
import com.squareup.inject.assisted.AssistedInject
|
||||
import org.matrix.android.sdk.api.MatrixCallback
|
||||
import org.matrix.android.sdk.api.session.room.reporting.ReportingService
|
||||
import org.matrix.android.sdk.api.util.Cancelable
|
||||
import org.matrix.android.sdk.internal.task.TaskExecutor
|
||||
import org.matrix.android.sdk.internal.task.configureWith
|
||||
|
||||
internal class DefaultReportingService @AssistedInject constructor(@Assisted private val roomId: String,
|
||||
private val taskExecutor: TaskExecutor,
|
||||
private val reportContentTask: ReportContentTask
|
||||
) : ReportingService {
|
||||
|
||||
|
@ -34,13 +29,8 @@ internal class DefaultReportingService @AssistedInject constructor(@Assisted pri
|
|||
fun create(roomId: String): ReportingService
|
||||
}
|
||||
|
||||
override fun reportContent(eventId: String, score: Int, reason: String, callback: MatrixCallback<Unit>): Cancelable {
|
||||
override suspend fun reportContent(eventId: String, score: Int, reason: String) {
|
||||
val params = ReportContentTask.Params(roomId, eventId, score, reason)
|
||||
|
||||
return reportContentTask
|
||||
.configureWith(params) {
|
||||
this.callback = callback
|
||||
}
|
||||
.executeBy(taskExecutor)
|
||||
reportContentTask.execute(params)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,6 +99,7 @@ import org.matrix.android.sdk.rx.rx
|
|||
import org.matrix.android.sdk.rx.unwrap
|
||||
import timber.log.Timber
|
||||
import java.io.File
|
||||
import java.lang.Exception
|
||||
import java.util.UUID
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
@ -1112,15 +1113,15 @@ class RoomDetailViewModel @AssistedInject constructor(
|
|||
}
|
||||
|
||||
private fun handleReportContent(action: RoomDetailAction.ReportContent) {
|
||||
room.reportContent(action.eventId, -100, action.reason, object : MatrixCallback<Unit> {
|
||||
override fun onSuccess(data: Unit) {
|
||||
_viewEvents.post(RoomDetailViewEvents.ActionSuccess(action))
|
||||
viewModelScope.launch {
|
||||
val event = try {
|
||||
room.reportContent(action.eventId, -100, action.reason)
|
||||
RoomDetailViewEvents.ActionSuccess(action)
|
||||
} catch (failure: Exception) {
|
||||
RoomDetailViewEvents.ActionFailure(action, failure)
|
||||
}
|
||||
|
||||
override fun onFailure(failure: Throwable) {
|
||||
_viewEvents.post(RoomDetailViewEvents.ActionFailure(action, failure))
|
||||
}
|
||||
})
|
||||
_viewEvents.post(event)
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleIgnoreUser(action: RoomDetailAction.IgnoreUser) {
|
||||
|
|
Loading…
Reference in a new issue