QueueMemento : fix synchronized

This commit is contained in:
ganfra 2020-12-11 19:18:48 +01:00
parent 629488bbe6
commit b1f492de58

View file

@ -49,8 +49,10 @@ internal class QueueMemento @Inject constructor(context: Context,
} }
fun unTrack(task: QueuedTask) { fun unTrack(task: QueuedTask) {
managedTaskInfos.remove(task) synchronized(managedTaskInfos) {
persist() managedTaskInfos.remove(task)
persist()
}
} }
private fun persist() { private fun persist() {
@ -64,19 +66,17 @@ internal class QueueMemento @Inject constructor(context: Context,
} }
private fun toTaskInfo(task: QueuedTask, order: Int): TaskInfo? { private fun toTaskInfo(task: QueuedTask, order: Int): TaskInfo? {
synchronized(managedTaskInfos) { return when (task) {
return when (task) { is SendEventQueuedTask -> SendEventTaskInfo(
is SendEventQueuedTask -> SendEventTaskInfo( localEchoId = task.event.eventId ?: "",
localEchoId = task.event.eventId ?: "", encrypt = task.encrypt,
encrypt = task.encrypt, order = order
order = order )
) is RedactQueuedTask -> RedactEventTaskInfo(
is RedactQueuedTask -> RedactEventTaskInfo( redactionLocalEcho = task.redactionLocalEchoId,
redactionLocalEcho = task.redactionLocalEchoId, order = order
order = order )
) else -> null
else -> null
}
} }
} }
@ -90,7 +90,7 @@ internal class QueueMemento @Inject constructor(context: Context,
?.forEach { info -> ?.forEach { info ->
try { try {
when (info) { when (info) {
is SendEventTaskInfo -> { is SendEventTaskInfo -> {
localEchoRepository.getUpToDateEcho(info.localEchoId)?.let { localEchoRepository.getUpToDateEcho(info.localEchoId)?.let {
if (it.sendState.isSending() && it.eventId != null && it.roomId != null) { if (it.sendState.isSending() && it.eventId != null && it.roomId != null) {
localEchoRepository.updateSendState(it.eventId, it.roomId, SendState.UNSENT) localEchoRepository.updateSendState(it.eventId, it.roomId, SendState.UNSENT)