Browse Source

mxCallbackFlow already contains a `tryOrNull` wrapper around the block, so not need to add an extra one.

Also the block can return a non-null TaskHandle.
pull/3533/head
Benoit Marty 3 weeks ago
parent
commit
1309d04649
  1. 16
      libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/roomlist/RoomListExtensions.kt
  2. 5
      libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/sync/SyncServiceExtension.kt
  3. 2
      libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/util/CallbackFlow.kt

16
libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/roomlist/RoomListExtensions.kt

@ -97,9 +97,7 @@ internal fun RoomListServiceInterface.stateFlow(): Flow<RoomListServiceState> = @@ -97,9 +97,7 @@ internal fun RoomListServiceInterface.stateFlow(): Flow<RoomListServiceState> =
trySendBlocking(state)
}
}
tryOrNull {
state(listener)
}
state(listener)
}.buffer(Channel.UNLIMITED)
internal fun RoomListServiceInterface.syncIndicator(): Flow<RoomListServiceSyncIndicator> =
@ -109,13 +107,11 @@ internal fun RoomListServiceInterface.syncIndicator(): Flow<RoomListServiceSyncI @@ -109,13 +107,11 @@ internal fun RoomListServiceInterface.syncIndicator(): Flow<RoomListServiceSyncI
trySendBlocking(syncIndicator)
}
}
tryOrNull {
syncIndicator(
SYNC_INDICATOR_DELAY_BEFORE_SHOWING,
SYNC_INDICATOR_DELAY_BEFORE_HIDING,
listener,
)
}
syncIndicator(
SYNC_INDICATOR_DELAY_BEFORE_SHOWING,
SYNC_INDICATOR_DELAY_BEFORE_HIDING,
listener,
)
}.buffer(Channel.UNLIMITED)
internal fun RoomListServiceInterface.roomOrNull(roomId: String): RoomListItem? {

5
libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/sync/SyncServiceExtension.kt

@ -7,7 +7,6 @@ @@ -7,7 +7,6 @@
package io.element.android.libraries.matrix.impl.sync
import io.element.android.libraries.core.data.tryOrNull
import io.element.android.libraries.matrix.impl.util.mxCallbackFlow
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.trySendBlocking
@ -24,7 +23,5 @@ fun SyncServiceInterface.stateFlow(): Flow<SyncServiceState> = @@ -24,7 +23,5 @@ fun SyncServiceInterface.stateFlow(): Flow<SyncServiceState> =
trySendBlocking(state)
}
}
tryOrNull {
state(listener)
}
state(listener)
}.buffer(Channel.UNLIMITED)

2
libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/util/CallbackFlow.kt

@ -13,7 +13,7 @@ import kotlinx.coroutines.channels.awaitClose @@ -13,7 +13,7 @@ import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.callbackFlow
import org.matrix.rustcomponents.sdk.TaskHandle
internal fun <T> mxCallbackFlow(block: suspend ProducerScope<T>.() -> TaskHandle?) =
internal fun <T> mxCallbackFlow(block: suspend ProducerScope<T>.() -> TaskHandle) =
callbackFlow {
val taskHandle: TaskHandle? = tryOrNull {
block(this)

Loading…
Cancel
Save