Convert ReportingService to suspend functions
Signed-off-by: Dominic Fischer <dominicfischer7@gmail.com>
This commit is contained in:
parent
60ce351a27
commit
d67029c42c
|
@ -16,9 +16,6 @@
|
||||||
|
|
||||||
package org.matrix.android.sdk.api.session.room.reporting
|
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.
|
* This interface defines methods to report content of an event.
|
||||||
*/
|
*/
|
||||||
|
@ -28,5 +25,5 @@ interface ReportingService {
|
||||||
* Report content
|
* Report content
|
||||||
* Ref: https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-rooms-roomid-report-eventid
|
* 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.Assisted
|
||||||
import com.squareup.inject.assisted.AssistedInject
|
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.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,
|
internal class DefaultReportingService @AssistedInject constructor(@Assisted private val roomId: String,
|
||||||
private val taskExecutor: TaskExecutor,
|
|
||||||
private val reportContentTask: ReportContentTask
|
private val reportContentTask: ReportContentTask
|
||||||
) : ReportingService {
|
) : ReportingService {
|
||||||
|
|
||||||
|
@ -34,13 +29,8 @@ internal class DefaultReportingService @AssistedInject constructor(@Assisted pri
|
||||||
fun create(roomId: String): ReportingService
|
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)
|
val params = ReportContentTask.Params(roomId, eventId, score, reason)
|
||||||
|
reportContentTask.execute(params)
|
||||||
return reportContentTask
|
|
||||||
.configureWith(params) {
|
|
||||||
this.callback = callback
|
|
||||||
}
|
|
||||||
.executeBy(taskExecutor)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,6 +99,7 @@ import org.matrix.android.sdk.rx.rx
|
||||||
import org.matrix.android.sdk.rx.unwrap
|
import org.matrix.android.sdk.rx.unwrap
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.lang.Exception
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
|
@ -1112,15 +1113,15 @@ class RoomDetailViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleReportContent(action: RoomDetailAction.ReportContent) {
|
private fun handleReportContent(action: RoomDetailAction.ReportContent) {
|
||||||
room.reportContent(action.eventId, -100, action.reason, object : MatrixCallback<Unit> {
|
viewModelScope.launch {
|
||||||
override fun onSuccess(data: Unit) {
|
val event = try {
|
||||||
_viewEvents.post(RoomDetailViewEvents.ActionSuccess(action))
|
room.reportContent(action.eventId, -100, action.reason)
|
||||||
|
RoomDetailViewEvents.ActionSuccess(action)
|
||||||
|
} catch (failure: Exception) {
|
||||||
|
RoomDetailViewEvents.ActionFailure(action, failure)
|
||||||
}
|
}
|
||||||
|
_viewEvents.post(event)
|
||||||
override fun onFailure(failure: Throwable) {
|
|
||||||
_viewEvents.post(RoomDetailViewEvents.ActionFailure(action, failure))
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleIgnoreUser(action: RoomDetailAction.IgnoreUser) {
|
private fun handleIgnoreUser(action: RoomDetailAction.IgnoreUser) {
|
||||||
|
|
Loading…
Reference in New Issue