Introduce awaitRoom() and awaitRoomSummary()
This commit is contained in:
parent
d957e24747
commit
ebd491c6f0
@ -65,6 +65,11 @@ interface Room {
|
|||||||
*/
|
*/
|
||||||
fun roomSummary(): RoomSummary?
|
fun roomSummary(): RoomSummary?
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Suspending version of [roomSummary] method
|
||||||
|
*/
|
||||||
|
suspend fun awaitRoomSummary(): RoomSummary?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this room as a Space, if the type is correct.
|
* Use this room as a Space, if the type is correct.
|
||||||
*/
|
*/
|
||||||
|
@ -92,6 +92,13 @@ interface RoomService {
|
|||||||
*/
|
*/
|
||||||
fun getRoom(roomId: String): Room?
|
fun getRoom(roomId: String): Room?
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Suspending version of [getRoom] method.
|
||||||
|
* @param roomId the roomId to look for.
|
||||||
|
* @return a room with roomId or null
|
||||||
|
*/
|
||||||
|
suspend fun awaitRoom(roomId: String): Room?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a roomSummary from a roomId or a room alias.
|
* Get a roomSummary from a roomId or a room alias.
|
||||||
* @param roomIdOrAlias the roomId or the alias of a room to look for.
|
* @param roomIdOrAlias the roomId or the alias of a room to look for.
|
||||||
|
@ -82,6 +82,10 @@ internal class DefaultRoom(
|
|||||||
return roomSummaryDataSource.getRoomSummary(roomId)
|
return roomSummaryDataSource.getRoomSummary(roomId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun awaitRoomSummary(): RoomSummary? {
|
||||||
|
return roomSummaryDataSource.awaitRoomSummary(roomId)
|
||||||
|
}
|
||||||
|
|
||||||
override fun asSpace(): Space? {
|
override fun asSpace(): Space? {
|
||||||
if (roomSummary()?.roomType != RoomType.SPACE) return null
|
if (roomSummary()?.roomType != RoomType.SPACE) return null
|
||||||
return DefaultSpace(this, roomSummaryDataSource, viaParameterFinder)
|
return DefaultSpace(this, roomSummaryDataSource, viaParameterFinder)
|
||||||
|
@ -82,6 +82,10 @@ internal class DefaultRoomService @Inject constructor(
|
|||||||
return roomGetter.getRoom(roomId)
|
return roomGetter.getRoom(roomId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun awaitRoom(roomId: String): Room? {
|
||||||
|
return roomGetter.awaitRoom(roomId)
|
||||||
|
}
|
||||||
|
|
||||||
override fun getExistingDirectRoomWithUser(otherUserId: String): String? {
|
override fun getExistingDirectRoomWithUser(otherUserId: String): String? {
|
||||||
return roomGetter.getDirectRoomWith(otherUserId)
|
return roomGetter.getDirectRoomWith(otherUserId)
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
package org.matrix.android.sdk.internal.session.room
|
package org.matrix.android.sdk.internal.session.room
|
||||||
|
|
||||||
import io.realm.Realm
|
import io.realm.Realm
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import org.matrix.android.sdk.api.MatrixCoroutineDispatchers
|
||||||
import org.matrix.android.sdk.api.session.room.Room
|
import org.matrix.android.sdk.api.session.room.Room
|
||||||
import org.matrix.android.sdk.api.session.room.model.Membership
|
import org.matrix.android.sdk.api.session.room.model.Membership
|
||||||
import org.matrix.android.sdk.internal.database.RealmSessionProvider
|
import org.matrix.android.sdk.internal.database.RealmSessionProvider
|
||||||
@ -30,13 +32,16 @@ import javax.inject.Inject
|
|||||||
internal interface RoomGetter {
|
internal interface RoomGetter {
|
||||||
fun getRoom(roomId: String): Room?
|
fun getRoom(roomId: String): Room?
|
||||||
|
|
||||||
|
suspend fun awaitRoom(roomId: String): Room?
|
||||||
|
|
||||||
fun getDirectRoomWith(otherUserId: String): String?
|
fun getDirectRoomWith(otherUserId: String): String?
|
||||||
}
|
}
|
||||||
|
|
||||||
@SessionScope
|
@SessionScope
|
||||||
internal class DefaultRoomGetter @Inject constructor(
|
internal class DefaultRoomGetter @Inject constructor(
|
||||||
private val realmSessionProvider: RealmSessionProvider,
|
private val realmSessionProvider: RealmSessionProvider,
|
||||||
private val roomFactory: RoomFactory
|
private val roomFactory: RoomFactory,
|
||||||
|
private val coroutineDispatchers: MatrixCoroutineDispatchers,
|
||||||
) : RoomGetter {
|
) : RoomGetter {
|
||||||
|
|
||||||
override fun getRoom(roomId: String): Room? {
|
override fun getRoom(roomId: String): Room? {
|
||||||
@ -45,6 +50,10 @@ internal class DefaultRoomGetter @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun awaitRoom(roomId: String) = withContext(coroutineDispatchers.io) {
|
||||||
|
getRoom(roomId)
|
||||||
|
}
|
||||||
|
|
||||||
override fun getDirectRoomWith(otherUserId: String): String? {
|
override fun getDirectRoomWith(otherUserId: String): String? {
|
||||||
return realmSessionProvider.withRealm { realm ->
|
return realmSessionProvider.withRealm { realm ->
|
||||||
RoomSummaryEntity.where(realm)
|
RoomSummaryEntity.where(realm)
|
||||||
|
@ -26,6 +26,8 @@ import com.zhuinden.monarchy.Monarchy
|
|||||||
import io.realm.Realm
|
import io.realm.Realm
|
||||||
import io.realm.RealmQuery
|
import io.realm.RealmQuery
|
||||||
import io.realm.kotlin.where
|
import io.realm.kotlin.where
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import org.matrix.android.sdk.api.MatrixCoroutineDispatchers
|
||||||
import org.matrix.android.sdk.api.query.QueryStringValue
|
import org.matrix.android.sdk.api.query.QueryStringValue
|
||||||
import org.matrix.android.sdk.api.query.RoomCategoryFilter
|
import org.matrix.android.sdk.api.query.RoomCategoryFilter
|
||||||
import org.matrix.android.sdk.api.query.SpaceFilter
|
import org.matrix.android.sdk.api.query.SpaceFilter
|
||||||
@ -58,6 +60,7 @@ internal class RoomSummaryDataSource @Inject constructor(
|
|||||||
@SessionDatabase private val monarchy: Monarchy,
|
@SessionDatabase private val monarchy: Monarchy,
|
||||||
private val roomSummaryMapper: RoomSummaryMapper,
|
private val roomSummaryMapper: RoomSummaryMapper,
|
||||||
private val queryStringValueProcessor: QueryStringValueProcessor,
|
private val queryStringValueProcessor: QueryStringValueProcessor,
|
||||||
|
private val coroutineDispatchers: MatrixCoroutineDispatchers,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun getRoomSummary(roomIdOrAlias: String): RoomSummary? {
|
fun getRoomSummary(roomIdOrAlias: String): RoomSummary? {
|
||||||
@ -75,6 +78,10 @@ internal class RoomSummaryDataSource @Inject constructor(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun awaitRoomSummary(roomIdOrAlias: String) = withContext(coroutineDispatchers.io) {
|
||||||
|
getRoomSummary(roomIdOrAlias)
|
||||||
|
}
|
||||||
|
|
||||||
fun getRoomSummaryLive(roomId: String): LiveData<Optional<RoomSummary>> {
|
fun getRoomSummaryLive(roomId: String): LiveData<Optional<RoomSummary>> {
|
||||||
val liveData = monarchy.findAllMappedWithChanges(
|
val liveData = monarchy.findAllMappedWithChanges(
|
||||||
{ realm -> RoomSummaryEntity.where(realm, roomId).isNotEmpty(RoomSummaryEntityFields.DISPLAY_NAME) },
|
{ realm -> RoomSummaryEntity.where(realm, roomId).isNotEmpty(RoomSummaryEntityFields.DISPLAY_NAME) },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user