1
0
mirror of https://github.com/vector-im/element-android.git synced 2025-07-29 19:41:14 +03:00

Mavericks 2: make the UT happy. Let SDK exposes MatrixCoroutineDispatchers.

This commit is contained in:
ganfra
2021-10-12 13:47:32 +02:00
parent a26e43e90c
commit a24a9b43fa
41 changed files with 108 additions and 102 deletions

View File

@ -16,14 +16,14 @@
package org.matrix.android.sdk.flow
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.withContext
internal fun <T> Flow<T>.startWith(supplier: suspend () -> T): Flow<T> {
internal fun <T> Flow<T>.startWith(dispatcher: CoroutineDispatcher, supplier: suspend () -> T): Flow<T> {
return onStart {
val value = withContext(Dispatchers.IO) {
val value = withContext(dispatcher) {
supplier()
}
emit(value)

View File

@ -36,42 +36,42 @@ class FlowRoom(private val room: Room) {
fun liveRoomSummary(): Flow<Optional<RoomSummary>> {
return room.getRoomSummaryLive().asFlow()
.startWith {
.startWith(room.coroutineDispatchers.io) {
room.roomSummary().toOptional()
}
}
fun liveRoomMembers(queryParams: RoomMemberQueryParams): Flow<List<RoomMemberSummary>> {
return room.getRoomMembersLive(queryParams).asFlow()
.startWith {
.startWith(room.coroutineDispatchers.io) {
room.getRoomMembers(queryParams)
}
}
fun liveAnnotationSummary(eventId: String): Flow<Optional<EventAnnotationsSummary>> {
return room.getEventAnnotationsSummaryLive(eventId).asFlow()
.startWith {
.startWith(room.coroutineDispatchers.io) {
room.getEventAnnotationsSummary(eventId).toOptional()
}
}
fun liveTimelineEvent(eventId: String): Flow<Optional<TimelineEvent>> {
return room.getTimeLineEventLive(eventId).asFlow()
.startWith {
.startWith(room.coroutineDispatchers.io) {
room.getTimeLineEvent(eventId).toOptional()
}
}
fun liveStateEvent(eventType: String, stateKey: QueryStringValue): Flow<Optional<Event>> {
return room.getStateEventLive(eventType, stateKey).asFlow()
.startWith {
.startWith(room.coroutineDispatchers.io) {
room.getStateEvent(eventType, stateKey).toOptional()
}
}
fun liveStateEvents(eventTypes: Set<String>): Flow<List<Event>> {
return room.getStateEventsLive(eventTypes).asFlow()
.startWith {
.startWith(room.coroutineDispatchers.io) {
room.getStateEvents(eventTypes)
}
}
@ -90,7 +90,7 @@ class FlowRoom(private val room: Room) {
fun liveDraft(): Flow<Optional<UserDraft>> {
return room.getDraftLive().asFlow()
.startWith {
.startWith(room.coroutineDispatchers.io) {
room.getDraft().toOptional()
}
}

View File

@ -46,35 +46,35 @@ class FlowSession(private val session: Session) {
fun liveRoomSummaries(queryParams: RoomSummaryQueryParams): Flow<List<RoomSummary>> {
return session.getRoomSummariesLive(queryParams).asFlow()
.startWith {
.startWith(session.coroutineDispatchers.io) {
session.getRoomSummaries(queryParams)
}
}
fun liveGroupSummaries(queryParams: GroupSummaryQueryParams): Flow<List<GroupSummary>> {
return session.getGroupSummariesLive(queryParams).asFlow()
.startWith {
.startWith(session.coroutineDispatchers.io) {
session.getGroupSummaries(queryParams)
}
}
fun liveSpaceSummaries(queryParams: SpaceSummaryQueryParams): Flow<List<RoomSummary>> {
return session.spaceService().getSpaceSummariesLive(queryParams).asFlow()
.startWith {
.startWith(session.coroutineDispatchers.io) {
session.spaceService().getSpaceSummaries(queryParams)
}
}
fun liveBreadcrumbs(queryParams: RoomSummaryQueryParams): Flow<List<RoomSummary>> {
return session.getBreadcrumbsLive(queryParams).asFlow()
.startWith {
.startWith(session.coroutineDispatchers.io) {
session.getBreadcrumbs(queryParams)
}
}
fun liveMyDevicesInfo(): Flow<List<DeviceInfo>> {
return session.cryptoService().getLiveMyDevicesInfo().asFlow()
.startWith {
.startWith(session.coroutineDispatchers.io) {
session.cryptoService().getMyDevicesInfo()
}
}
@ -89,14 +89,14 @@ class FlowSession(private val session: Session) {
fun liveUser(userId: String): Flow<Optional<User>> {
return session.getUserLive(userId).asFlow()
.startWith {
.startWith(session.coroutineDispatchers.io) {
session.getUser(userId).toOptional()
}
}
fun liveRoomMember(userId: String, roomId: String): Flow<Optional<RoomMemberSummary>> {
return session.getRoomMemberLive(userId, roomId).asFlow()
.startWith {
.startWith(session.coroutineDispatchers.io) {
session.getRoomMember(userId, roomId).toOptional()
}
}
@ -115,45 +115,45 @@ class FlowSession(private val session: Session) {
fun liveThreePIds(refreshData: Boolean): Flow<List<ThreePid>> {
return session.getThreePidsLive(refreshData).asFlow()
.startWith { session.getThreePids() }
.startWith(session.coroutineDispatchers.io) { session.getThreePids() }
}
fun livePendingThreePIds(): Flow<List<ThreePid>> {
return session.getPendingThreePidsLive().asFlow()
.startWith { session.getPendingThreePids() }
.startWith(session.coroutineDispatchers.io) { session.getPendingThreePids() }
}
fun liveUserCryptoDevices(userId: String): Flow<List<CryptoDeviceInfo>> {
return session.cryptoService().getLiveCryptoDeviceInfo(userId).asFlow()
.startWith {
.startWith(session.coroutineDispatchers.io) {
session.cryptoService().getCryptoDeviceInfo(userId)
}
}
fun liveCrossSigningInfo(userId: String): Flow<Optional<MXCrossSigningInfo>> {
return session.cryptoService().crossSigningService().getLiveCrossSigningKeys(userId).asFlow()
.startWith {
.startWith(session.coroutineDispatchers.io) {
session.cryptoService().crossSigningService().getUserCrossSigningKeys(userId).toOptional()
}
}
fun liveCrossSigningPrivateKeys(): Flow<Optional<PrivateKeysInfo>> {
return session.cryptoService().crossSigningService().getLiveCrossSigningPrivateKeys().asFlow()
.startWith {
.startWith(session.coroutineDispatchers.io) {
session.cryptoService().crossSigningService().getCrossSigningPrivateKeys().toOptional()
}
}
fun liveUserAccountData(types: Set<String>): Flow<List<UserAccountDataEvent>> {
return session.accountDataService().getLiveUserAccountDataEvents(types).asFlow()
.startWith {
.startWith(session.coroutineDispatchers.io) {
session.accountDataService().getUserAccountDataEvents(types)
}
}
fun liveRoomAccountData(types: Set<String>): Flow<List<RoomAccountDataEvent>> {
return session.accountDataService().getLiveRoomAccountDataEvents(types).asFlow()
.startWith {
.startWith(session.coroutineDispatchers.io) {
session.accountDataService().getRoomAccountDataEvents(types)
}
}
@ -165,7 +165,7 @@ class FlowSession(private val session: Session) {
excludedTypes: Set<String>? = null
): Flow<List<Widget>> {
return session.widgetService().getRoomWidgetsLive(roomId, widgetId, widgetTypes, excludedTypes).asFlow()
.startWith {
.startWith(session.coroutineDispatchers.io) {
session.widgetService().getRoomWidgets(roomId, widgetId, widgetTypes, excludedTypes)
}
}