Feature/fga/sync states (#1042)

* Change RoomSummaryDataSource to RoomListService to better reflects the rust api

* Better Sync management

* Sync: improve sync spinner rendering

* Sync: make test compiles

* Sync: add more test for sync spinner

* Sync: more clean-up

* Sync: pr review

---------

Co-authored-by: ganfra <francoisg@element.io>
This commit is contained in:
ganfra 2023-08-09 14:37:43 +02:00 committed by GitHub
parent 2131af28d5
commit fa51f6eaa7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
44 changed files with 547 additions and 356 deletions

View file

@ -26,7 +26,7 @@ import io.element.android.libraries.matrix.api.notification.NotificationService
import io.element.android.libraries.matrix.api.pusher.PushersService
import io.element.android.libraries.matrix.api.room.MatrixRoom
import io.element.android.libraries.matrix.api.room.RoomMembershipObserver
import io.element.android.libraries.matrix.api.room.RoomSummaryDataSource
import io.element.android.libraries.matrix.api.roomlist.RoomListService
import io.element.android.libraries.matrix.api.sync.SyncService
import io.element.android.libraries.matrix.api.user.MatrixSearchUserResults
import io.element.android.libraries.matrix.api.user.MatrixUser
@ -35,7 +35,7 @@ import java.io.Closeable
interface MatrixClient : Closeable {
val sessionId: SessionId
val roomSummaryDataSource: RoomSummaryDataSource
val roomListService: RoomListService
val mediaLoader: MatrixMediaLoader
suspend fun getRoom(roomId: RoomId): MatrixRoom?
suspend fun findDM(userId: UserId): MatrixRoom?

View file

@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.element.android.libraries.matrix.api.room
package io.element.android.libraries.matrix.api.roomlist
import kotlinx.coroutines.TimeoutCancellationException
import kotlinx.coroutines.flow.StateFlow
@ -23,25 +23,34 @@ import kotlinx.coroutines.withTimeout
import timber.log.Timber
import kotlin.time.Duration
interface RoomSummaryDataSource {
/**
* Holds some flows related to a specific set of rooms.
* Can be retrieved from [RoomListService] methods.
*/
interface RoomList {
sealed class LoadingState {
object NotLoaded : LoadingState()
data class Loaded(val numberOfRooms: Int) : LoadingState()
}
fun updateAllRoomsVisibleRange(range: IntRange)
fun allRoomsLoadingState(): StateFlow<LoadingState>
fun allRooms(): StateFlow<List<RoomSummary>>
fun inviteRooms(): StateFlow<List<RoomSummary>>
/**
* The list of room summaries as a flow.
*/
val summaries: StateFlow<List<RoomSummary>>
/**
* The loading state of the room list as a flow.
* This is useful to know if a specific set of rooms is loaded or not.
*/
val loadingState: StateFlow<LoadingState>
}
suspend fun RoomSummaryDataSource.awaitAllRoomsAreLoaded(timeout: Duration = Duration.INFINITE) {
suspend fun RoomList.awaitLoaded(timeout: Duration = Duration.INFINITE) {
try {
Timber.d("awaitAllRoomsAreLoaded: wait")
withTimeout(timeout) {
allRoomsLoadingState().firstOrNull {
it is RoomSummaryDataSource.LoadingState.Loaded
loadingState.firstOrNull {
it is RoomList.LoadingState.Loaded
}
}
} catch (timeoutException: TimeoutCancellationException) {

View file

@ -0,0 +1,56 @@
/*
* Copyright (c) 2023 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.libraries.matrix.api.roomlist
import kotlinx.coroutines.flow.StateFlow
/**
* Entry point for the room list api.
* This service will provide different sets of rooms (all, invites, etc.).
* It requires the SyncService to be started to receive updates.
*/
interface RoomListService {
sealed class State {
object Idle : State()
object Running : State()
object Error : State()
object Terminated : State()
}
/**
* returns a [RoomList] object of all rooms we want to display.
* This will exclude some rooms like the invites, or spaces.
*/
fun allRooms(): RoomList
/**
* returns a [RoomList] object of all invites.
*/
fun invites(): RoomList
/**
* Will set the visible range of all rooms.
* This is useful to load more data when the user scrolls down.
*/
fun updateAllRoomsVisibleRange(range: IntRange)
/**
* The state of the service as a flow.
*/
val state: StateFlow<State>
}

View file

@ -14,9 +14,10 @@
* limitations under the License.
*/
package io.element.android.libraries.matrix.api.room
package io.element.android.libraries.matrix.api.roomlist
import io.element.android.libraries.matrix.api.core.RoomId
import io.element.android.libraries.matrix.api.room.RoomMember
import io.element.android.libraries.matrix.api.room.message.RoomMessage
sealed interface RoomSummary {