This commit is contained in:
Valere 2020-10-09 00:33:53 +02:00 committed by Benoit Marty
parent 41e168a519
commit ace412f9e3
9 changed files with 20 additions and 33 deletions

View File

@ -44,7 +44,7 @@ internal class DefaultEncryptEventTask @Inject constructor(
) : EncryptEventTask {
override suspend fun execute(params: EncryptEventTask.Params): Event {
// don't want to wait for any query
//if (!params.crypto.isRoomEncrypted(params.roomId)) return params.event
// if (!params.crypto.isRoomEncrypted(params.roomId)) return params.event
val localEvent = params.event
if (localEvent.eventId == null) {
throw IllegalArgumentException()

View File

@ -17,7 +17,6 @@
package org.matrix.android.sdk.internal.session.room.send
import android.content.Context
import androidx.work.BackoffPolicy
import androidx.work.OneTimeWorkRequest
import androidx.work.WorkerParameters
import com.squareup.moshi.JsonClass
@ -31,7 +30,6 @@ import org.matrix.android.sdk.internal.worker.SessionWorkerParams
import org.matrix.android.sdk.internal.worker.WorkerParamsFactory
import org.matrix.android.sdk.internal.worker.startChain
import timber.log.Timber
import java.util.concurrent.TimeUnit
import javax.inject.Inject
/**

View File

@ -23,13 +23,10 @@ import io.realm.RealmConfiguration
import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.failure.shouldBeRetried
import org.matrix.android.sdk.api.session.crypto.CryptoService
import org.matrix.android.sdk.api.session.events.model.Content
import org.matrix.android.sdk.api.session.room.send.SendState
import org.matrix.android.sdk.internal.crypto.tasks.SendEventTask
import org.matrix.android.sdk.internal.di.SessionDatabase
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.SessionComponent
import org.matrix.android.sdk.internal.session.room.RoomAPI
import org.matrix.android.sdk.internal.worker.SessionSafeCoroutineWorker
import org.matrix.android.sdk.internal.worker.SessionWorkerParams
import timber.log.Timber
@ -90,7 +87,7 @@ internal class SendEventWorker(context: Context,
Timber.v("## SendEvent: [${System.currentTimeMillis()}] Send event ${params.eventId}")
return try {
sendEventTask.execute(SendEventTask.Params(event, params.isEncrypted ?: cryptoService.isRoomEncrypted(event.roomId) , cryptoService))
sendEventTask.execute(SendEventTask.Params(event, params.isEncrypted ?: cryptoService.isRoomEncrypted(event.roomId), cryptoService))
Result.success()
} catch (exception: Throwable) {
if (/*currentAttemptCount >= MAX_NUMBER_OF_RETRY_BEFORE_FAILING ||**/ !exception.shouldBeRetried()) {
@ -107,5 +104,4 @@ internal class SendEventWorker(context: Context,
override fun buildErrorParams(params: Params, message: String): Params {
return params.copy(lastFailureMessage = params.lastFailureMessage ?: message)
}
}

View File

@ -153,7 +153,7 @@ internal class EventSenderProcessor @Inject constructor(
// SendPerformanceProfiler.startStage(task.event.eventId!!, SendPerformanceProfiler.Stages.SEND_WORKER)
Timber.v("## SendThread retryLoop for $task retryCount ${task.retryCount}")
task.execute()
//sendEventTask.execute(SendEventTask.Params(task.event, task.encrypt, cryptoService))
// sendEventTask.execute(SendEventTask.Params(task.event, task.encrypt, cryptoService))
// SendPerformanceProfiler.stopStage(task.event.eventId, SendPerformanceProfiler.Stages.SEND_WORKER)
break@retryLoop
} catch (exception: Throwable) {
@ -161,19 +161,17 @@ internal class EventSenderProcessor @Inject constructor(
exception is IOException || exception is Failure.NetworkConnection -> {
canReachServer = false
task.retryCount++
if (task.retryCount >= 3) task.onTaskFailed() //localEchoRepository.updateSendState(task.event.eventId!!, task.event.roomId, SendState.UNDELIVERED)
if (task.retryCount >= 3) task.onTaskFailed()
while (!canReachServer) {
Timber.v("## SendThread retryLoop cannot reach server, wait ts:${System.currentTimeMillis()}")
// schedule to retry
waitForNetwork()
// if thread as been killed meanwhile
// if (state == State.KILLING) break
}
}
(exception is Failure.ServerError && exception.error.code == MatrixError.M_LIMIT_EXCEEDED) -> {
task.retryCount++
if (task.retryCount >= 3) task.onTaskFailed() //localEchoRepository.updateSendState(task.event.eventId!!, task.event.roomId, SendState.UNDELIVERED)
Timber.v("## SendThread retryLoop retryable error for ${task} reason: ${exception.localizedMessage}")
if (task.retryCount >= 3) task.onTaskFailed()
Timber.v("## SendThread retryLoop retryable error for $task reason: ${exception.localizedMessage}")
// wait a bit
// Todo if its a quota exception can we get timout?
sleep(3_000)
@ -183,7 +181,6 @@ internal class EventSenderProcessor @Inject constructor(
Timber.v("## SendThread retryLoop retryable TOKEN error, interrupt")
// we can exit the loop
task.onTaskFailed()
// localEchoRepository.updateSendState(task.event.eventId!!, task.event.roomId, SendState.UNDELIVERED)
throw InterruptedException()
}
else -> {
@ -199,7 +196,7 @@ internal class EventSenderProcessor @Inject constructor(
}
} catch (interruptionException: InterruptedException) {
// will be thrown is thread is interrupted while seeping
interrupt();
interrupt()
Timber.v("## InterruptedException!! ${interruptionException.localizedMessage}")
}
// state = State.KILLED
@ -212,7 +209,7 @@ internal class EventSenderProcessor @Inject constructor(
retryNoNetworkTask = Timer(SyncState.NoNetwork.toString(), false).schedule(RETRY_WAIT_TIME_MS) {
synchronized(networkAvailableLock) {
canReachServer = checkHostAvailable().also {
Timber.v("## SendThread checkHostAvailable ${it}")
Timber.v("## SendThread checkHostAvailable $it")
}
networkAvailableLock.notify()
}

View File

@ -84,7 +84,7 @@ internal class QueueMemento @Inject constructor(context: Context,
suspend fun restoreTasks(eventProcessor: EventSenderProcessor) {
// events should be restarted in correct order
storage.getStringSet("ManagedBySender", null)?.let { pending ->
Timber.d("## Send - Recovering unsent events ${pending}")
Timber.d("## Send - Recovering unsent events $pending")
pending.mapNotNull { tryOrNull { TaskInfo.map(it) } }
}
?.sortedBy { it.order }
@ -95,7 +95,7 @@ internal class QueueMemento @Inject constructor(context: Context,
localEchoRepository.getUpToDateEcho(info.localEchoId)?.let {
if (it.sendState.isSending() && it.eventId != null && it.roomId != null) {
localEchoRepository.updateSendState(it.eventId, it.roomId, SendState.UNSENT)
Timber.d("## Send -Reschedule send ${info}")
Timber.d("## Send -Reschedule send $info")
eventProcessor.postTask(queuedTaskFactory.createSendTask(it, info.encrypt ?: cryptoService.isRoomEncrypted(it.roomId)))
}
}
@ -106,15 +106,15 @@ internal class QueueMemento @Inject constructor(context: Context,
// try to get reason
val reason = it.content?.get("reason") as? String
if (it.redacts != null && it.roomId != null) {
Timber.d("## Send -Reschedule redact ${info}")
Timber.d("## Send -Reschedule redact $info")
eventProcessor.postTask(queuedTaskFactory.createRedactTask(it.eventId, it.redacts, it.roomId, reason))
}
}
//postTask(queuedTaskFactory.createRedactTask(info.eventToRedactId, info.)
// postTask(queuedTaskFactory.createRedactTask(info.eventToRedactId, info.)
}
}
} catch (failure: Throwable) {
Timber.e("failed to restore task ${info}")
Timber.e("failed to restore task $info")
}
}
}

View File

@ -43,7 +43,6 @@ internal class RedactQueuedTask(
localEchoRepository.updateSendState(redactionLocalEchoId, roomId, SendState.UNDELIVERED)
}
override fun isCancelled(): Boolean {
return _isCancelled || cancelSendTracker.isCancelRequestedFor(redactionLocalEchoId, roomId)
}

View File

@ -851,18 +851,17 @@ internal class DefaultTimeline(
fun onLocalEchoCreated(onLocalEchoCreated: OnLocalEchoCreated): Boolean {
var postSnapshot = false
if (isLive && onLocalEchoCreated.roomId == roomId) {
// Manage some ui echos (do it before filter because actual event could be filtered out)
when (onLocalEchoCreated.timelineEvent.root.getClearType()) {
EventType.REDACTION -> {
}
EventType.REACTION -> {
val content = onLocalEchoCreated.timelineEvent.root.content?.toModel<ReactionContent>()
if (RelationType.ANNOTATION == content?.relatesTo?.type) {
val reaction = content.relatesTo.key
val relatedEventID = content.relatesTo.eventId
(inMemoryReactions.getOrPut(relatedEventID) { mutableListOf() }).add(
inMemoryReactions.getOrPut(relatedEventID) { mutableListOf() }
.add(
ReactionUiEchoData(
localEchoId = onLocalEchoCreated.timelineEvent.eventId,
reactedOnEventId = relatedEventID,

View File

@ -21,7 +21,6 @@ import androidx.work.ExistingWorkPolicy
import androidx.work.ListenableWorker
import androidx.work.OneTimeWorkRequest
import org.matrix.android.sdk.api.util.Cancelable
import org.matrix.android.sdk.api.util.NoOpCancellable
import org.matrix.android.sdk.internal.di.WorkManagerProvider
import org.matrix.android.sdk.internal.util.CancelableWork
import org.matrix.android.sdk.internal.worker.startChain

View File

@ -1061,7 +1061,6 @@ class RoomDetailViewModel @AssistedInject constructor(
}
}
private fun handleResendAll() {
room.resendAllFailedMessages()
}