Merge pull request #1142 from vector-im/feature/fix_upload_error

Fix / correctly update local echo failed state
This commit is contained in:
Valere 2020-03-17 09:48:43 +01:00 committed by GitHub
commit ef2783e9f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 5 deletions

View file

@ -193,6 +193,7 @@ internal class DefaultSession @Inject constructor(
stopAnyBackgroundSync()
liveEntityObservers.forEach { it.cancelProcess() }
cacheService.get().clearCache(callback)
workManagerProvider.cancelAllWorks()
}
@Subscribe(threadMode = ThreadMode.MAIN)

View file

@ -77,6 +77,16 @@ internal class UploadContentWorker(val context: Context, params: WorkerParameter
return Result.success(inputData)
}
// Just defensive code to ensure that we never have an uncaught exception that could break the queue
return try {
internalDoWork(params)
} catch (failure: Throwable) {
Timber.e(failure)
handleFailure(params, failure)
}
}
private suspend fun internalDoWork(params: Params): Result {
val sessionComponent = getSessionComponent(params.sessionId) ?: return Result.success()
sessionComponent.inject(this)

View file

@ -23,6 +23,7 @@ import androidx.work.OneTimeWorkRequest
import androidx.work.WorkerParameters
import com.squareup.moshi.JsonClass
import im.vector.matrix.android.api.session.events.model.Event
import im.vector.matrix.android.api.session.room.send.SendState
import im.vector.matrix.android.internal.di.WorkManagerProvider
import im.vector.matrix.android.internal.session.room.timeline.TimelineSendEventWorkCommon
import im.vector.matrix.android.internal.worker.SessionWorkerParams
@ -49,6 +50,7 @@ internal class MultipleEventSendingDispatcherWorker(context: Context, params: Wo
@Inject lateinit var workManagerProvider: WorkManagerProvider
@Inject lateinit var timelineSendEventWorkCommon: TimelineSendEventWorkCommon
@Inject lateinit var localEchoUpdater: LocalEchoUpdater
override suspend fun doWork(): Result {
Timber.v("Start dispatch sending multiple event work")
@ -57,14 +59,17 @@ internal class MultipleEventSendingDispatcherWorker(context: Context, params: Wo
Timber.e("Work cancelled due to input error from parent")
}
if (params.lastFailureMessage != null) {
// Transmit the error
return Result.success(inputData)
}
val sessionComponent = getSessionComponent(params.sessionId) ?: return Result.success()
sessionComponent.inject(this)
if (params.lastFailureMessage != null) {
params.events.forEach { event ->
event.eventId?.let { localEchoUpdater.updateSendState(it, SendState.UNDELIVERED) }
}
// Transmit the error if needed?
return Result.success(inputData)
}
// Create a work for every event
params.events.forEach { event ->
if (params.isEncrypted) {