mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-24 18:36:21 +03:00
Remove duplicated code by reusing RedactEventTask
This commit is contained in:
parent
300e167577
commit
a3f65b9bcb
1 changed files with 11 additions and 24 deletions
|
@ -19,13 +19,11 @@ import android.content.Context
|
||||||
import androidx.work.WorkerParameters
|
import androidx.work.WorkerParameters
|
||||||
import com.squareup.moshi.JsonClass
|
import com.squareup.moshi.JsonClass
|
||||||
import org.matrix.android.sdk.api.failure.Failure
|
import org.matrix.android.sdk.api.failure.Failure
|
||||||
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilitiesService
|
|
||||||
import org.matrix.android.sdk.internal.SessionManager
|
import org.matrix.android.sdk.internal.SessionManager
|
||||||
|
import org.matrix.android.sdk.internal.crypto.tasks.RedactEventTask
|
||||||
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
|
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
|
||||||
import org.matrix.android.sdk.internal.network.executeRequest
|
|
||||||
import org.matrix.android.sdk.internal.session.SessionComponent
|
import org.matrix.android.sdk.internal.session.SessionComponent
|
||||||
import org.matrix.android.sdk.internal.session.room.RoomAPI
|
import org.matrix.android.sdk.internal.session.room.RoomAPI
|
||||||
import org.matrix.android.sdk.internal.session.room.send.model.EventRedactBody
|
|
||||||
import org.matrix.android.sdk.internal.worker.SessionSafeCoroutineWorker
|
import org.matrix.android.sdk.internal.worker.SessionSafeCoroutineWorker
|
||||||
import org.matrix.android.sdk.internal.worker.SessionWorkerParams
|
import org.matrix.android.sdk.internal.worker.SessionWorkerParams
|
||||||
import org.matrix.android.sdk.internal.worker.WorkerParamsFactory
|
import org.matrix.android.sdk.internal.worker.WorkerParamsFactory
|
||||||
|
@ -51,34 +49,23 @@ internal class RedactEventWorker(context: Context, params: WorkerParameters, ses
|
||||||
|
|
||||||
@Inject lateinit var roomAPI: RoomAPI
|
@Inject lateinit var roomAPI: RoomAPI
|
||||||
@Inject lateinit var globalErrorReceiver: GlobalErrorReceiver
|
@Inject lateinit var globalErrorReceiver: GlobalErrorReceiver
|
||||||
@Inject lateinit var homeServerCapabilitiesService: HomeServerCapabilitiesService
|
@Inject lateinit var redactEventTask: RedactEventTask
|
||||||
|
|
||||||
override fun injectWith(injector: SessionComponent) {
|
override fun injectWith(injector: SessionComponent) {
|
||||||
injector.inject(this)
|
injector.inject(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun doSafeWork(params: Params): Result {
|
override suspend fun doSafeWork(params: Params): Result {
|
||||||
val eventId = params.eventId
|
|
||||||
val withRelations = if (homeServerCapabilitiesService.getHomeServerCapabilities().canRedactEventWithRelations &&
|
|
||||||
!params.withRelations.isNullOrEmpty()) {
|
|
||||||
params.withRelations
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
|
|
||||||
return runCatching {
|
return runCatching {
|
||||||
executeRequest(globalErrorReceiver) {
|
redactEventTask.execute(
|
||||||
roomAPI.redactEvent(
|
RedactEventTask.Params(
|
||||||
txId = params.txID,
|
txID = params.txID,
|
||||||
roomId = params.roomId,
|
roomId = params.roomId,
|
||||||
eventId = eventId,
|
eventId = params.eventId,
|
||||||
body = EventRedactBody(
|
|
||||||
reason = params.reason,
|
reason = params.reason,
|
||||||
withRelations = withRelations,
|
withRelations = params.withRelations,
|
||||||
withRelationsUnstable = withRelations,
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}.fold(
|
}.fold(
|
||||||
{
|
{
|
||||||
Result.success()
|
Result.success()
|
||||||
|
|
Loading…
Reference in a new issue