RoomList: simple implementation of setRange
This commit is contained in:
parent
6759240687
commit
f9acecf9eb
5 changed files with 194 additions and 14 deletions
|
|
@ -44,19 +44,19 @@ class MatrixClient internal constructor(
|
|||
.requiredState(
|
||||
requiredState = listOf(
|
||||
RequiredState(key = "m.room.avatar", value = ""),
|
||||
RequiredState(key = "m.room.name", value = ""),
|
||||
RequiredState(key = "m.room.encryption", value = ""),
|
||||
)
|
||||
)
|
||||
.name(name = "HomeScreenView")
|
||||
.syncMode(mode = SlidingSyncMode.FULL_SYNC)
|
||||
.syncMode(mode = SlidingSyncMode.SELECTIVE)
|
||||
.addRange(0u, 10u)
|
||||
.build()
|
||||
|
||||
private val slidingSync = client
|
||||
.slidingSync()
|
||||
.homeserver("https://slidingsync.lab.element.dev")
|
||||
.withCommonExtensions()
|
||||
.coldCache("ElementX")
|
||||
//.coldCache("ElementX")
|
||||
.addView(slidingSyncView)
|
||||
.build()
|
||||
|
||||
|
|
@ -66,7 +66,8 @@ class MatrixClient internal constructor(
|
|||
slidingSyncObserverProxy.updateSummaryFlow,
|
||||
slidingSync,
|
||||
slidingSyncView,
|
||||
dispatchers
|
||||
dispatchers,
|
||||
::onRestartSync
|
||||
)
|
||||
private var slidingSyncObserverToken: StoppableSpawn? = null
|
||||
|
||||
|
|
@ -77,6 +78,10 @@ class MatrixClient internal constructor(
|
|||
client.setDelegate(clientDelegate)
|
||||
}
|
||||
|
||||
private fun onRestartSync(){
|
||||
slidingSyncObserverToken = slidingSync.sync()
|
||||
}
|
||||
|
||||
fun getRoom(roomId: String): MatrixRoom? {
|
||||
val slidingSyncRoom = slidingSync.getRoom(roomId) ?: return null
|
||||
val room = slidingSyncRoom.fullRoom() ?: return null
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import java.util.*
|
|||
|
||||
interface RoomSummaryDataSource {
|
||||
fun roomSummaries(): Flow<List<RoomSummary>>
|
||||
fun setSlidingSyncRange(range: IntRange)
|
||||
}
|
||||
|
||||
internal class RustRoomSummaryDataSource(
|
||||
|
|
@ -19,7 +20,8 @@ internal class RustRoomSummaryDataSource(
|
|||
private val slidingSync: SlidingSync,
|
||||
private val slidingSyncView: SlidingSyncView,
|
||||
private val coroutineDispatchers: CoroutineDispatchers,
|
||||
private val roomSummaryDetailsFactory: RoomSummaryDetailsFactory = RoomSummaryDetailsFactory()
|
||||
private val onRestartSync: () -> Unit,
|
||||
private val roomSummaryDetailsFactory: RoomSummaryDetailsFactory = RoomSummaryDetailsFactory(),
|
||||
) : RoomSummaryDataSource, Closeable {
|
||||
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + coroutineDispatchers.io)
|
||||
|
|
@ -69,6 +71,12 @@ internal class RustRoomSummaryDataSource(
|
|||
return roomSummaries.sample(50)
|
||||
}
|
||||
|
||||
override fun setSlidingSyncRange(range: IntRange) {
|
||||
Timber.v("setVisibleRange=$range")
|
||||
slidingSyncView.setRange(range.first.toUInt(), range.last.toUInt())
|
||||
onRestartSync()
|
||||
}
|
||||
|
||||
private suspend fun didReceiveSyncUpdate(summary: UpdateSummary) {
|
||||
Timber.v("UpdateRooms with identifiers: ${summary.rooms}")
|
||||
if (state.value != SlidingSyncState.LIVE) {
|
||||
|
|
@ -140,11 +148,12 @@ internal class RustRoomSummaryDataSource(
|
|||
)
|
||||
}
|
||||
|
||||
private suspend fun updateRoomSummaries(block: MutableList<RoomSummary>.() -> Unit) = withContext(coroutineDispatchers.diffUpdateDispatcher){
|
||||
val mutableRoomSummaries = roomSummaries.value.toMutableList()
|
||||
block(mutableRoomSummaries)
|
||||
roomSummaries.value = mutableRoomSummaries
|
||||
}
|
||||
private suspend fun updateRoomSummaries(block: MutableList<RoomSummary>.() -> Unit) =
|
||||
withContext(coroutineDispatchers.diffUpdateDispatcher) {
|
||||
val mutableRoomSummaries = roomSummaries.value.toMutableList()
|
||||
block(mutableRoomSummaries)
|
||||
roomSummaries.value = mutableRoomSummaries
|
||||
}
|
||||
|
||||
fun SlidingSyncViewRoomsListDiff.isInvalidation(): Boolean {
|
||||
return when (this) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue