Message queuing : expose sending queue status on matrix client.

This commit is contained in:
ganfra
2024-06-05 18:09:36 +02:00
parent ed76598fa7
commit e8996efa37
3 changed files with 21 additions and 4 deletions

View File

@@ -115,4 +115,10 @@ interface MatrixClient : Closeable {
* connectivity is back on the device.
*/
suspend fun enableSendingQueue(enable: Boolean)
/**
* Returns the current status of the sending queue as a [StateFlow].
* If true, the sending queue is enabled.
*/
fun sendingQueueStatus(): StateFlow<Boolean>
}

View File

@@ -98,6 +98,7 @@ import org.matrix.rustcomponents.sdk.ClientDelegate
import org.matrix.rustcomponents.sdk.IgnoredUsersListener
import org.matrix.rustcomponents.sdk.NotificationProcessSetup
import org.matrix.rustcomponents.sdk.PowerLevels
import org.matrix.rustcomponents.sdk.SendingQueueStatusListener
import org.matrix.rustcomponents.sdk.TaskHandle
import org.matrix.rustcomponents.sdk.use
import timber.log.Timber
@@ -551,10 +552,20 @@ class RustMatrixClient(
}.distinctUntilChanged()
}
override suspend fun enableSendingQueue(enable: Boolean) = withContext(sessionDispatcher){
override suspend fun enableSendingQueue(enable: Boolean) = withContext(sessionDispatcher) {
client.enableSendingQueue(enable)
}
override fun sendingQueueStatus(): StateFlow<Boolean> = mxCallbackFlow {
client.subscribeToSendingQueueStatus(object : SendingQueueStatusListener {
override fun onValue(newValue: Boolean) {
channel.trySend(newValue)
}
})
}
.buffer(Channel.UNLIMITED)
.stateIn(sessionCoroutineScope, started = SharingStarted.Eagerly, initialValue = true)
private suspend fun File.getCacheSize(
includeCryptoDb: Boolean = false,
): Long = withContext(sessionDispatcher) {
@@ -594,9 +605,6 @@ class RustMatrixClient(
true
}
}
}
private val defaultRoomCreationPowerLevels = PowerLevels(

View File

@@ -305,4 +305,7 @@ class FakeMatrixClient(
}
override suspend fun enableSendingQueue(enable: Boolean) = enableSendingQueueLambda(enable)
var sendingQueueStatusFlow = MutableStateFlow(true)
override fun sendingQueueStatus(): StateFlow<Boolean> = sendingQueueStatusFlow
}