mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Send task: small rework and cleanup
This commit is contained in:
parent
b84d7f0834
commit
f6cc05634f
@ -106,11 +106,7 @@ internal class EventSenderProcessor @Inject constructor(
|
||||
// non blocking add to queue
|
||||
sendingQueue.add(task)
|
||||
markAsManaged(task)
|
||||
return object : Cancelable {
|
||||
override fun cancel() {
|
||||
task.cancel()
|
||||
}
|
||||
}
|
||||
return task
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -17,7 +17,6 @@
|
||||
package org.matrix.android.sdk.internal.session.room.send.queue
|
||||
|
||||
import android.content.Context
|
||||
import org.matrix.android.sdk.api.auth.data.sessionId
|
||||
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||
import org.matrix.android.sdk.api.session.crypto.CryptoService
|
||||
import org.matrix.android.sdk.api.session.room.send.SendState
|
||||
|
@ -16,14 +16,20 @@
|
||||
|
||||
package org.matrix.android.sdk.internal.session.room.send.queue
|
||||
|
||||
abstract class QueuedTask {
|
||||
import org.matrix.android.sdk.api.util.Cancelable
|
||||
|
||||
abstract class QueuedTask : Cancelable {
|
||||
var retryCount = 0
|
||||
|
||||
private var hasBeenCancelled: Boolean = false
|
||||
|
||||
abstract suspend fun execute()
|
||||
|
||||
abstract fun onTaskFailed()
|
||||
|
||||
abstract fun isCancelled() : Boolean
|
||||
open fun isCancelled() = hasBeenCancelled
|
||||
|
||||
abstract fun cancel()
|
||||
final override fun cancel() {
|
||||
hasBeenCancelled = true
|
||||
}
|
||||
}
|
||||
|
@ -22,18 +22,16 @@ import org.matrix.android.sdk.internal.session.room.send.CancelSendTracker
|
||||
import org.matrix.android.sdk.internal.session.room.send.LocalEchoRepository
|
||||
|
||||
internal class RedactQueuedTask(
|
||||
val toRedactEventId: String,
|
||||
private val toRedactEventId: String,
|
||||
val redactionLocalEchoId: String,
|
||||
val roomId: String,
|
||||
val reason: String?,
|
||||
val redactEventTask: RedactEventTask,
|
||||
val localEchoRepository: LocalEchoRepository,
|
||||
val cancelSendTracker: CancelSendTracker
|
||||
private val roomId: String,
|
||||
private val reason: String?,
|
||||
private val redactEventTask: RedactEventTask,
|
||||
private val localEchoRepository: LocalEchoRepository,
|
||||
private val cancelSendTracker: CancelSendTracker
|
||||
) : QueuedTask() {
|
||||
|
||||
private var _isCancelled: Boolean = false
|
||||
|
||||
override fun toString() = "[RedactEventRunnableTask $redactionLocalEchoId]"
|
||||
override fun toString() = "[RedactQueuedTask $redactionLocalEchoId]"
|
||||
|
||||
override suspend fun execute() {
|
||||
redactEventTask.execute(RedactEventTask.Params(redactionLocalEchoId, roomId, toRedactEventId, reason))
|
||||
@ -44,10 +42,6 @@ internal class RedactQueuedTask(
|
||||
}
|
||||
|
||||
override fun isCancelled(): Boolean {
|
||||
return _isCancelled || cancelSendTracker.isCancelRequestedFor(redactionLocalEchoId, roomId)
|
||||
}
|
||||
|
||||
override fun cancel() {
|
||||
_isCancelled = true
|
||||
return super.isCancelled() || cancelSendTracker.isCancelRequestedFor(redactionLocalEchoId, roomId)
|
||||
}
|
||||
}
|
||||
|
@ -33,9 +33,7 @@ internal class SendEventQueuedTask(
|
||||
val cancelSendTracker: CancelSendTracker
|
||||
) : QueuedTask() {
|
||||
|
||||
private var _isCancelled: Boolean = false
|
||||
|
||||
override fun toString() = "[SendEventRunnableTask ${event.eventId}]"
|
||||
override fun toString() = "[SendEventQueuedTask ${event.eventId}]"
|
||||
|
||||
override suspend fun execute() {
|
||||
sendEventTask.execute(SendEventTask.Params(event, encrypt))
|
||||
@ -56,10 +54,6 @@ internal class SendEventQueuedTask(
|
||||
}
|
||||
|
||||
override fun isCancelled(): Boolean {
|
||||
return _isCancelled || cancelSendTracker.isCancelRequestedFor(event.eventId, event.roomId)
|
||||
}
|
||||
|
||||
override fun cancel() {
|
||||
_isCancelled = true
|
||||
return super.isCancelled() || cancelSendTracker.isCancelRequestedFor(event.eventId, event.roomId)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user