MatrixRoom API refinement (#719)
- `syncUpdateFlow` becomes a `val` and always returns the same instance of the underlying `StateFlow` instead of different `Flow` instances to allow consumers not to remember the `Flow` and not to specify an unneeded initial value. - `timeline` becomes a `val` as it already always returns the same instance. - Amends calling code accordingly - Removes a few unneeded `val`s in `RustMatrixClient - Fixes a small bug in `MessagesPresenter` that allowed to sometime show a newly created room's name as "Empty room" (changes `LaunchedEffect(syncUpdateFlow)` to `LaunchedEffect(syncUpdateFlow.value)`)
This commit is contained in:
parent
91060c76a7
commit
354374ed49
8 changed files with 23 additions and 34 deletions
|
|
@ -73,10 +73,10 @@ import org.matrix.rustcomponents.sdk.RoomVisibility as RustRoomVisibility
|
|||
class RustMatrixClient constructor(
|
||||
private val client: Client,
|
||||
private val sessionStore: SessionStore,
|
||||
private val appCoroutineScope: CoroutineScope,
|
||||
appCoroutineScope: CoroutineScope,
|
||||
private val dispatchers: CoroutineDispatchers,
|
||||
private val baseDirectory: File,
|
||||
private val baseCacheDirectory: File,
|
||||
baseCacheDirectory: File,
|
||||
private val clock: SystemClock,
|
||||
) : MatrixClient {
|
||||
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ import kotlinx.coroutines.cancel
|
|||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
|
|
@ -71,15 +72,10 @@ class RustMatrixRoom(
|
|||
override val roomId = RoomId(innerRoom.id())
|
||||
|
||||
private val roomCoroutineScope = sessionCoroutineScope.childScope(coroutineDispatchers.main, "RoomScope-$roomId")
|
||||
|
||||
override val membersStateFlow: StateFlow<MatrixRoomMembersState>
|
||||
get() = _membersStateFlow
|
||||
|
||||
private var _membersStateFlow = MutableStateFlow<MatrixRoomMembersState>(MatrixRoomMembersState.Unknown)
|
||||
private val _membersStateFlow = MutableStateFlow<MatrixRoomMembersState>(MatrixRoomMembersState.Unknown)
|
||||
private val isInit = MutableStateFlow(false)
|
||||
private val syncUpdateFlow = MutableStateFlow(systemClock.epochMillis())
|
||||
|
||||
private val timeline by lazy {
|
||||
private val _syncUpdateFlow = MutableStateFlow(0L)
|
||||
private val _timeline by lazy {
|
||||
RustMatrixTimeline(
|
||||
matrixRoom = this,
|
||||
innerRoom = innerRoom,
|
||||
|
|
@ -88,13 +84,11 @@ class RustMatrixRoom(
|
|||
)
|
||||
}
|
||||
|
||||
override fun syncUpdateFlow(): Flow<Long> {
|
||||
return syncUpdateFlow
|
||||
}
|
||||
override val membersStateFlow: StateFlow<MatrixRoomMembersState> = _membersStateFlow.asStateFlow()
|
||||
|
||||
override fun timeline(): MatrixTimeline {
|
||||
return timeline
|
||||
}
|
||||
override val syncUpdateFlow: StateFlow<Long> = _syncUpdateFlow.asStateFlow()
|
||||
|
||||
override val timeline: MatrixTimeline = _timeline
|
||||
|
||||
override fun open(): Result<Unit> {
|
||||
if (isInit.value) return Result.failure(IllegalStateException("Listener already registered"))
|
||||
|
|
@ -110,10 +104,10 @@ class RustMatrixRoom(
|
|||
roomListItem.subscribe(settings)
|
||||
roomCoroutineScope.launch(coroutineDispatchers.computation) {
|
||||
innerRoom.timelineDiffFlow { initialList ->
|
||||
timeline.postItems(initialList)
|
||||
_timeline.postItems(initialList)
|
||||
}.onEach {
|
||||
syncUpdateFlow.value = systemClock.epochMillis()
|
||||
timeline.postDiff(it)
|
||||
_syncUpdateFlow.value = systemClock.epochMillis()
|
||||
_timeline.postDiff(it)
|
||||
}.launchIn(this)
|
||||
fetchMembers()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue