RoomList: prepare code to not fetch fullRoom
This commit is contained in:
parent
5b35bb4277
commit
b9157c4042
2 changed files with 14 additions and 3 deletions
|
|
@ -21,8 +21,10 @@ import kotlinx.coroutines.CompletableDeferred
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlinx.coroutines.sync.withLock
|
import kotlinx.coroutines.sync.withLock
|
||||||
|
import org.matrix.rustcomponents.sdk.Room
|
||||||
import org.matrix.rustcomponents.sdk.RoomListEntriesUpdate
|
import org.matrix.rustcomponents.sdk.RoomListEntriesUpdate
|
||||||
import org.matrix.rustcomponents.sdk.RoomListEntry
|
import org.matrix.rustcomponents.sdk.RoomListEntry
|
||||||
|
import org.matrix.rustcomponents.sdk.RoomListItem
|
||||||
import org.matrix.rustcomponents.sdk.RoomListService
|
import org.matrix.rustcomponents.sdk.RoomListService
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
@ -31,6 +33,7 @@ class RoomSummaryListProcessor(
|
||||||
private val roomSummaries: MutableStateFlow<List<RoomSummary>>,
|
private val roomSummaries: MutableStateFlow<List<RoomSummary>>,
|
||||||
private val roomListService: RoomListService,
|
private val roomListService: RoomListService,
|
||||||
private val roomSummaryDetailsFactory: RoomSummaryDetailsFactory = RoomSummaryDetailsFactory(),
|
private val roomSummaryDetailsFactory: RoomSummaryDetailsFactory = RoomSummaryDetailsFactory(),
|
||||||
|
private val shouldFetchFullRoom: Boolean = false,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val roomSummariesByIdentifier = HashMap<String, RoomSummary>()
|
private val roomSummariesByIdentifier = HashMap<String, RoomSummary>()
|
||||||
|
|
@ -113,7 +116,7 @@ class RoomSummaryListProcessor(
|
||||||
|
|
||||||
private fun buildAndCacheRoomSummaryForIdentifier(identifier: String): RoomSummary {
|
private fun buildAndCacheRoomSummaryForIdentifier(identifier: String): RoomSummary {
|
||||||
val builtRoomSummary = roomListService.roomOrNull(identifier)?.use { roomListItem ->
|
val builtRoomSummary = roomListService.roomOrNull(identifier)?.use { roomListItem ->
|
||||||
roomListItem.fullRoom().use { fullRoom ->
|
roomListItem.fullRoomOrNull().use { fullRoom ->
|
||||||
RoomSummary.Filled(
|
RoomSummary.Filled(
|
||||||
details = roomSummaryDetailsFactory.create(roomListItem, fullRoom)
|
details = roomSummaryDetailsFactory.create(roomListItem, fullRoom)
|
||||||
)
|
)
|
||||||
|
|
@ -123,6 +126,14 @@ class RoomSummaryListProcessor(
|
||||||
return builtRoomSummary
|
return builtRoomSummary
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun RoomListItem.fullRoomOrNull(): Room? {
|
||||||
|
return if (shouldFetchFullRoom) {
|
||||||
|
fullRoom()
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun updateRoomSummaries(block: MutableList<RoomSummary>.() -> Unit) =
|
private suspend fun updateRoomSummaries(block: MutableList<RoomSummary>.() -> Unit) =
|
||||||
mutex.withLock {
|
mutex.withLock {
|
||||||
val mutableRoomSummaries = roomSummaries.value.toMutableList()
|
val mutableRoomSummaries = roomSummaries.value.toMutableList()
|
||||||
|
|
|
||||||
|
|
@ -49,8 +49,8 @@ internal class RustRoomSummaryDataSource(
|
||||||
private val inviteRooms = MutableStateFlow<List<RoomSummary>>(emptyList())
|
private val inviteRooms = MutableStateFlow<List<RoomSummary>>(emptyList())
|
||||||
|
|
||||||
private val allRoomsLoadingState: MutableStateFlow<RoomSummaryDataSource.LoadingState> = MutableStateFlow(RoomSummaryDataSource.LoadingState.NotLoaded)
|
private val allRoomsLoadingState: MutableStateFlow<RoomSummaryDataSource.LoadingState> = MutableStateFlow(RoomSummaryDataSource.LoadingState.NotLoaded)
|
||||||
private val allRoomsListProcessor = RoomSummaryListProcessor(allRooms, roomListService, roomSummaryDetailsFactory)
|
private val allRoomsListProcessor = RoomSummaryListProcessor(allRooms, roomListService, roomSummaryDetailsFactory, shouldFetchFullRoom = false)
|
||||||
private val inviteRoomsListProcessor = RoomSummaryListProcessor(inviteRooms, roomListService, roomSummaryDetailsFactory)
|
private val inviteRoomsListProcessor = RoomSummaryListProcessor(inviteRooms, roomListService, roomSummaryDetailsFactory, shouldFetchFullRoom = true)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
sessionCoroutineScope.launch(coroutineDispatchers.computation) {
|
sessionCoroutineScope.launch(coroutineDispatchers.computation) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue