cleaning
This commit is contained in:
parent
41e168a519
commit
ace412f9e3
@ -17,7 +17,6 @@
|
|||||||
package org.matrix.android.sdk.internal.session.room.send
|
package org.matrix.android.sdk.internal.session.room.send
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.work.BackoffPolicy
|
|
||||||
import androidx.work.OneTimeWorkRequest
|
import androidx.work.OneTimeWorkRequest
|
||||||
import androidx.work.WorkerParameters
|
import androidx.work.WorkerParameters
|
||||||
import com.squareup.moshi.JsonClass
|
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.WorkerParamsFactory
|
||||||
import org.matrix.android.sdk.internal.worker.startChain
|
import org.matrix.android.sdk.internal.worker.startChain
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,13 +23,10 @@ import io.realm.RealmConfiguration
|
|||||||
import org.greenrobot.eventbus.EventBus
|
import org.greenrobot.eventbus.EventBus
|
||||||
import org.matrix.android.sdk.api.failure.shouldBeRetried
|
import org.matrix.android.sdk.api.failure.shouldBeRetried
|
||||||
import org.matrix.android.sdk.api.session.crypto.CryptoService
|
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.api.session.room.send.SendState
|
||||||
import org.matrix.android.sdk.internal.crypto.tasks.SendEventTask
|
import org.matrix.android.sdk.internal.crypto.tasks.SendEventTask
|
||||||
import org.matrix.android.sdk.internal.di.SessionDatabase
|
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.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.SessionSafeCoroutineWorker
|
||||||
import org.matrix.android.sdk.internal.worker.SessionWorkerParams
|
import org.matrix.android.sdk.internal.worker.SessionWorkerParams
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
@ -107,5 +104,4 @@ internal class SendEventWorker(context: Context,
|
|||||||
override fun buildErrorParams(params: Params, message: String): Params {
|
override fun buildErrorParams(params: Params, message: String): Params {
|
||||||
return params.copy(lastFailureMessage = params.lastFailureMessage ?: message)
|
return params.copy(lastFailureMessage = params.lastFailureMessage ?: message)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -161,19 +161,17 @@ internal class EventSenderProcessor @Inject constructor(
|
|||||||
exception is IOException || exception is Failure.NetworkConnection -> {
|
exception is IOException || exception is Failure.NetworkConnection -> {
|
||||||
canReachServer = false
|
canReachServer = false
|
||||||
task.retryCount++
|
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) {
|
while (!canReachServer) {
|
||||||
Timber.v("## SendThread retryLoop cannot reach server, wait ts:${System.currentTimeMillis()}")
|
Timber.v("## SendThread retryLoop cannot reach server, wait ts:${System.currentTimeMillis()}")
|
||||||
// schedule to retry
|
// schedule to retry
|
||||||
waitForNetwork()
|
waitForNetwork()
|
||||||
// if thread as been killed meanwhile
|
|
||||||
// if (state == State.KILLING) break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(exception is Failure.ServerError && exception.error.code == MatrixError.M_LIMIT_EXCEEDED) -> {
|
(exception is Failure.ServerError && exception.error.code == MatrixError.M_LIMIT_EXCEEDED) -> {
|
||||||
task.retryCount++
|
task.retryCount++
|
||||||
if (task.retryCount >= 3) task.onTaskFailed() //localEchoRepository.updateSendState(task.event.eventId!!, task.event.roomId, SendState.UNDELIVERED)
|
if (task.retryCount >= 3) task.onTaskFailed()
|
||||||
Timber.v("## SendThread retryLoop retryable error for ${task} reason: ${exception.localizedMessage}")
|
Timber.v("## SendThread retryLoop retryable error for $task reason: ${exception.localizedMessage}")
|
||||||
// wait a bit
|
// wait a bit
|
||||||
// Todo if its a quota exception can we get timout?
|
// Todo if its a quota exception can we get timout?
|
||||||
sleep(3_000)
|
sleep(3_000)
|
||||||
@ -183,7 +181,6 @@ internal class EventSenderProcessor @Inject constructor(
|
|||||||
Timber.v("## SendThread retryLoop retryable TOKEN error, interrupt")
|
Timber.v("## SendThread retryLoop retryable TOKEN error, interrupt")
|
||||||
// we can exit the loop
|
// we can exit the loop
|
||||||
task.onTaskFailed()
|
task.onTaskFailed()
|
||||||
// localEchoRepository.updateSendState(task.event.eventId!!, task.event.roomId, SendState.UNDELIVERED)
|
|
||||||
throw InterruptedException()
|
throw InterruptedException()
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
@ -199,7 +196,7 @@ internal class EventSenderProcessor @Inject constructor(
|
|||||||
}
|
}
|
||||||
} catch (interruptionException: InterruptedException) {
|
} catch (interruptionException: InterruptedException) {
|
||||||
// will be thrown is thread is interrupted while seeping
|
// will be thrown is thread is interrupted while seeping
|
||||||
interrupt();
|
interrupt()
|
||||||
Timber.v("## InterruptedException!! ${interruptionException.localizedMessage}")
|
Timber.v("## InterruptedException!! ${interruptionException.localizedMessage}")
|
||||||
}
|
}
|
||||||
// state = State.KILLED
|
// state = State.KILLED
|
||||||
@ -212,7 +209,7 @@ internal class EventSenderProcessor @Inject constructor(
|
|||||||
retryNoNetworkTask = Timer(SyncState.NoNetwork.toString(), false).schedule(RETRY_WAIT_TIME_MS) {
|
retryNoNetworkTask = Timer(SyncState.NoNetwork.toString(), false).schedule(RETRY_WAIT_TIME_MS) {
|
||||||
synchronized(networkAvailableLock) {
|
synchronized(networkAvailableLock) {
|
||||||
canReachServer = checkHostAvailable().also {
|
canReachServer = checkHostAvailable().also {
|
||||||
Timber.v("## SendThread checkHostAvailable ${it}")
|
Timber.v("## SendThread checkHostAvailable $it")
|
||||||
}
|
}
|
||||||
networkAvailableLock.notify()
|
networkAvailableLock.notify()
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ internal class QueueMemento @Inject constructor(context: Context,
|
|||||||
suspend fun restoreTasks(eventProcessor: EventSenderProcessor) {
|
suspend fun restoreTasks(eventProcessor: EventSenderProcessor) {
|
||||||
// events should be restarted in correct order
|
// events should be restarted in correct order
|
||||||
storage.getStringSet("ManagedBySender", null)?.let { pending ->
|
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) } }
|
pending.mapNotNull { tryOrNull { TaskInfo.map(it) } }
|
||||||
}
|
}
|
||||||
?.sortedBy { it.order }
|
?.sortedBy { it.order }
|
||||||
@ -95,7 +95,7 @@ internal class QueueMemento @Inject constructor(context: Context,
|
|||||||
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)
|
||||||
Timber.d("## Send -Reschedule send ${info}")
|
Timber.d("## Send -Reschedule send $info")
|
||||||
eventProcessor.postTask(queuedTaskFactory.createSendTask(it, info.encrypt ?: cryptoService.isRoomEncrypted(it.roomId)))
|
eventProcessor.postTask(queuedTaskFactory.createSendTask(it, info.encrypt ?: cryptoService.isRoomEncrypted(it.roomId)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -106,7 +106,7 @@ internal class QueueMemento @Inject constructor(context: Context,
|
|||||||
// try to get reason
|
// try to get reason
|
||||||
val reason = it.content?.get("reason") as? String
|
val reason = it.content?.get("reason") as? String
|
||||||
if (it.redacts != null && it.roomId != null) {
|
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))
|
eventProcessor.postTask(queuedTaskFactory.createRedactTask(it.eventId, it.redacts, it.roomId, reason))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,7 +114,7 @@ internal class QueueMemento @Inject constructor(context: Context,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (failure: Throwable) {
|
} catch (failure: Throwable) {
|
||||||
Timber.e("failed to restore task ${info}")
|
Timber.e("failed to restore task $info")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,6 @@ internal class RedactQueuedTask(
|
|||||||
localEchoRepository.updateSendState(redactionLocalEchoId, roomId, SendState.UNDELIVERED)
|
localEchoRepository.updateSendState(redactionLocalEchoId, roomId, SendState.UNDELIVERED)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun isCancelled(): Boolean {
|
override fun isCancelled(): Boolean {
|
||||||
return _isCancelled || cancelSendTracker.isCancelRequestedFor(redactionLocalEchoId, roomId)
|
return _isCancelled || cancelSendTracker.isCancelRequestedFor(redactionLocalEchoId, roomId)
|
||||||
}
|
}
|
||||||
|
@ -851,18 +851,17 @@ internal class DefaultTimeline(
|
|||||||
fun onLocalEchoCreated(onLocalEchoCreated: OnLocalEchoCreated): Boolean {
|
fun onLocalEchoCreated(onLocalEchoCreated: OnLocalEchoCreated): Boolean {
|
||||||
var postSnapshot = false
|
var postSnapshot = false
|
||||||
if (isLive && onLocalEchoCreated.roomId == roomId) {
|
if (isLive && onLocalEchoCreated.roomId == roomId) {
|
||||||
|
|
||||||
// Manage some ui echos (do it before filter because actual event could be filtered out)
|
// Manage some ui echos (do it before filter because actual event could be filtered out)
|
||||||
when (onLocalEchoCreated.timelineEvent.root.getClearType()) {
|
when (onLocalEchoCreated.timelineEvent.root.getClearType()) {
|
||||||
EventType.REDACTION -> {
|
EventType.REDACTION -> {
|
||||||
|
|
||||||
}
|
}
|
||||||
EventType.REACTION -> {
|
EventType.REACTION -> {
|
||||||
val content = onLocalEchoCreated.timelineEvent.root.content?.toModel<ReactionContent>()
|
val content = onLocalEchoCreated.timelineEvent.root.content?.toModel<ReactionContent>()
|
||||||
if (RelationType.ANNOTATION == content?.relatesTo?.type) {
|
if (RelationType.ANNOTATION == content?.relatesTo?.type) {
|
||||||
val reaction = content.relatesTo.key
|
val reaction = content.relatesTo.key
|
||||||
val relatedEventID = content.relatesTo.eventId
|
val relatedEventID = content.relatesTo.eventId
|
||||||
(inMemoryReactions.getOrPut(relatedEventID) { mutableListOf() }).add(
|
inMemoryReactions.getOrPut(relatedEventID) { mutableListOf() }
|
||||||
|
.add(
|
||||||
ReactionUiEchoData(
|
ReactionUiEchoData(
|
||||||
localEchoId = onLocalEchoCreated.timelineEvent.eventId,
|
localEchoId = onLocalEchoCreated.timelineEvent.eventId,
|
||||||
reactedOnEventId = relatedEventID,
|
reactedOnEventId = relatedEventID,
|
||||||
|
@ -21,7 +21,6 @@ import androidx.work.ExistingWorkPolicy
|
|||||||
import androidx.work.ListenableWorker
|
import androidx.work.ListenableWorker
|
||||||
import androidx.work.OneTimeWorkRequest
|
import androidx.work.OneTimeWorkRequest
|
||||||
import org.matrix.android.sdk.api.util.Cancelable
|
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.di.WorkManagerProvider
|
||||||
import org.matrix.android.sdk.internal.util.CancelableWork
|
import org.matrix.android.sdk.internal.util.CancelableWork
|
||||||
import org.matrix.android.sdk.internal.worker.startChain
|
import org.matrix.android.sdk.internal.worker.startChain
|
||||||
|
@ -1061,7 +1061,6 @@ class RoomDetailViewModel @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun handleResendAll() {
|
private fun handleResendAll() {
|
||||||
room.resendAllFailedMessages()
|
room.resendAllFailedMessages()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user