Implement Space "Add existing rooms" logic and ui

This commit is contained in:
ganfra
2026-01-20 22:15:42 +01:00
parent e840671bf2
commit 9fe7c50972
10 changed files with 736 additions and 8 deletions

View File

@@ -0,0 +1,32 @@
/*
* Copyright (c) 2026 Element Creations Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
* Please see LICENSE files in the repository root for full details.
*/
package io.element.android.libraries.matrix.api.room.recent
import io.element.android.libraries.matrix.api.MatrixClient
import io.element.android.libraries.matrix.api.room.RoomInfo
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
/**
* Returns a [Flow] of [RoomInfo] from recently visited DM rooms.
* The flow emits items lazily, allowing callers to filter and take only what they need.
* Use [kotlinx.coroutines.flow.take] to limit results and stop iteration early.
*/
fun MatrixClient.getRecentRooms(
predicate: (RoomInfo) -> Boolean,
): Flow<RoomInfo> = flow {
val recentlyVisitedRooms = getRecentlyVisitedRooms().getOrDefault(emptyList())
for (roomId in recentlyVisitedRooms) {
getRoom(roomId)?.use { room ->
val info = room.info()
if (predicate(info)) {
emit(info)
}
}
}
}