Skip to content

Commit

Permalink
Merge pull request #761 from vector-im/feature/fga/room_detail_factor…
Browse files Browse the repository at this point in the history
…y_improvement

Feature/fga/room detail factory improvement
  • Loading branch information
ganfra authored Jul 4, 2023
2 parents 714108e + 670280b commit 5ae8b6c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class RoomSummaryDetailsFactory(private val roomMessageFactory: RoomMessageFacto
return RoomSummaryDetails(
roomId = RoomId(roomListItem.id()),
name = roomListItem.name() ?: roomListItem.id(),
canonicalAlias = room?.canonicalAlias(),
isDirect = room?.isDirect() ?: false,
avatarURLString = room?.avatarUrl(),
canonicalAlias = roomListItem.canonicalAlias(),
isDirect = roomListItem.isDirect(),
avatarURLString = roomListItem.avatarUrl(),
unreadNotificationCount = roomListItem.unreadNotifications().use { it.notificationCount().toInt() },
lastMessage = latestRoomMessage,
lastMessageTimestamp = latestRoomMessage?.originServerTs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import org.matrix.rustcomponents.sdk.Room
import org.matrix.rustcomponents.sdk.RoomListEntriesUpdate
import org.matrix.rustcomponents.sdk.RoomListEntry
import org.matrix.rustcomponents.sdk.RoomListItem
import org.matrix.rustcomponents.sdk.RoomListService
import timber.log.Timber
import java.util.UUID
Expand All @@ -31,6 +33,7 @@ class RoomSummaryListProcessor(
private val roomSummaries: MutableStateFlow<List<RoomSummary>>,
private val roomListService: RoomListService,
private val roomSummaryDetailsFactory: RoomSummaryDetailsFactory = RoomSummaryDetailsFactory(),
private val shouldFetchFullRoom: Boolean = false,
) {

private val roomSummariesByIdentifier = HashMap<String, RoomSummary>()
Expand Down Expand Up @@ -113,7 +116,7 @@ class RoomSummaryListProcessor(

private fun buildAndCacheRoomSummaryForIdentifier(identifier: String): RoomSummary {
val builtRoomSummary = roomListService.roomOrNull(identifier)?.use { roomListItem ->
roomListItem.fullRoom().use { fullRoom ->
roomListItem.fullRoomOrNull().use { fullRoom ->
RoomSummary.Filled(
details = roomSummaryDetailsFactory.create(roomListItem, fullRoom)
)
Expand All @@ -123,6 +126,14 @@ class RoomSummaryListProcessor(
return builtRoomSummary
}

private fun RoomListItem.fullRoomOrNull(): Room? {
return if (shouldFetchFullRoom) {
fullRoom()
} else {
null
}
}

private suspend fun updateRoomSummaries(block: MutableList<RoomSummary>.() -> Unit) =
mutex.withLock {
val mutableRoomSummaries = roomSummaries.value.toMutableList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ internal class RustRoomSummaryDataSource(
private val inviteRooms = MutableStateFlow<List<RoomSummary>>(emptyList())

private val allRoomsLoadingState: MutableStateFlow<RoomSummaryDataSource.LoadingState> = MutableStateFlow(RoomSummaryDataSource.LoadingState.NotLoaded)
private val allRoomsListProcessor = RoomSummaryListProcessor(allRooms, roomListService, roomSummaryDetailsFactory)
private val inviteRoomsListProcessor = RoomSummaryListProcessor(inviteRooms, roomListService, roomSummaryDetailsFactory)
private val allRoomsListProcessor = RoomSummaryListProcessor(allRooms, roomListService, roomSummaryDetailsFactory, shouldFetchFullRoom = false)
private val inviteRoomsListProcessor = RoomSummaryListProcessor(inviteRooms, roomListService, roomSummaryDetailsFactory, shouldFetchFullRoom = true)

init {
sessionCoroutineScope.launch(coroutineDispatchers.computation) {
Expand Down

0 comments on commit 5ae8b6c

Please sign in to comment.