Browse Source

Sending queue : change a bit the logic to re-enable sending queue.

pull/3054/head
ganfra 3 months ago
parent
commit
6e7e024a2d
  1. 16
      appnav/src/main/kotlin/io/element/android/appnav/loggedin/SendQueues.kt
  2. 11
      appnav/src/test/kotlin/io/element/android/appnav/loggedin/SendQueuesTest.kt

16
appnav/src/main/kotlin/io/element/android/appnav/loggedin/SendQueues.kt

@ -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)

11
appnav/src/test/kotlin/io/element/android/appnav/loggedin/SendQueuesTest.kt

@ -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…
Cancel
Save