Sending queue : change a bit the logic to re-enable sending queue.
This commit is contained in:
parent
a12fa8d8a4
commit
f98441c74d
2 changed files with 13 additions and 14 deletions
|
|
@ -24,14 +24,14 @@ import io.element.android.libraries.di.SingleIn
|
||||||
import io.element.android.libraries.matrix.api.MatrixClient
|
import io.element.android.libraries.matrix.api.MatrixClient
|
||||||
import io.element.android.libraries.matrix.api.core.RoomId
|
import io.element.android.libraries.matrix.api.core.RoomId
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.FlowPreview
|
||||||
|
import kotlinx.coroutines.flow.debounce
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import timber.log.Timber
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
const val SEND_QUEUES_RETRY_DELAY_MILLIS = 1500L
|
const val SEND_QUEUES_RETRY_DELAY_MILLIS = 500L
|
||||||
|
|
||||||
@SingleIn(SessionScope::class)
|
@SingleIn(SessionScope::class)
|
||||||
class SendQueues @Inject constructor(
|
class SendQueues @Inject constructor(
|
||||||
|
|
@ -45,14 +45,12 @@ class SendQueues @Inject constructor(
|
||||||
}
|
}
|
||||||
.launchIn(coroutineScope)
|
.launchIn(coroutineScope)
|
||||||
|
|
||||||
|
@OptIn(FlowPreview::class)
|
||||||
matrixClient.sendQueueDisabledFlow()
|
matrixClient.sendQueueDisabledFlow()
|
||||||
.onEach { roomId: RoomId ->
|
.debounce(SEND_QUEUES_RETRY_DELAY_MILLIS)
|
||||||
Timber.d("Send queue disabled for room $roomId")
|
.onEach { _: RoomId ->
|
||||||
if (networkMonitor.connectivity.value == NetworkStatus.Online) {
|
if (networkMonitor.connectivity.value == NetworkStatus.Online) {
|
||||||
delay(SEND_QUEUES_RETRY_DELAY_MILLIS)
|
matrixClient.setAllSendQueuesEnabled(enabled = true)
|
||||||
matrixClient.getRoom(roomId)?.use { room ->
|
|
||||||
room.setSendQueueEnabled(enabled = true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.launchIn(coroutineScope)
|
.launchIn(coroutineScope)
|
||||||
|
|
|
||||||
|
|
@ -55,12 +55,13 @@ import org.junit.Test
|
||||||
runCurrent()
|
runCurrent()
|
||||||
|
|
||||||
assert(setAllSendQueuesEnabledLambda)
|
assert(setAllSendQueuesEnabledLambda)
|
||||||
.isCalledOnce()
|
.isCalledExactly(2)
|
||||||
.with(value(true))
|
.withSequence(
|
||||||
|
listOf(value(true)),
|
||||||
|
listOf(value(true)),
|
||||||
|
)
|
||||||
|
|
||||||
assert(setRoomSendQueueEnabledLambda)
|
assert(setRoomSendQueueEnabledLambda).isNeverCalled()
|
||||||
.isCalledOnce()
|
|
||||||
.with(value(true))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue