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:
parent
2131af28d5
commit
fa51f6eaa7
44 changed files with 547 additions and 356 deletions
|
|
@ -135,6 +135,6 @@ class RoomListPresenter @Inject constructor(
|
|||
// Safe to give bigger size than room list
|
||||
val extendedRangeEnd = range.last + midExtendedRangeSize
|
||||
val extendedRange = IntRange(extendedRangeStart, extendedRangeEnd)
|
||||
client.roomSummaryDataSource.updateAllRoomsVisibleRange(extendedRange)
|
||||
client.roomListService.updateAllRoomsVisibleRange(extendedRange)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ import io.element.android.libraries.core.coroutine.CoroutineDispatchers
|
|||
import io.element.android.libraries.di.SessionScope
|
||||
import io.element.android.libraries.matrix.api.MatrixClient
|
||||
import io.element.android.libraries.matrix.api.core.RoomId
|
||||
import io.element.android.libraries.matrix.api.room.RoomSummary
|
||||
import io.element.android.libraries.matrix.api.roomlist.RoomSummary
|
||||
import kotlinx.coroutines.withContext
|
||||
import javax.inject.Inject
|
||||
|
||||
|
|
@ -44,8 +44,9 @@ class DefaultInviteStateDataSource @Inject constructor(
|
|||
@Composable
|
||||
override fun inviteState(): InvitesState {
|
||||
val invites by client
|
||||
.roomSummaryDataSource
|
||||
.inviteRooms()
|
||||
.roomListService
|
||||
.invites()
|
||||
.summaries
|
||||
.collectAsState()
|
||||
|
||||
val seenInvites by seenInvitesStore
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ import io.element.android.libraries.designsystem.components.avatar.AvatarData
|
|||
import io.element.android.libraries.designsystem.components.avatar.AvatarSize
|
||||
import io.element.android.libraries.eventformatter.api.RoomLastMessageFormatter
|
||||
import io.element.android.libraries.matrix.api.core.RoomId
|
||||
import io.element.android.libraries.matrix.api.room.RoomSummary
|
||||
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.roomlist.RoomSummary
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
|
|
@ -44,7 +44,7 @@ import kotlinx.coroutines.withContext
|
|||
import javax.inject.Inject
|
||||
|
||||
class RoomListDataSource @Inject constructor(
|
||||
private val roomSummaryDataSource: RoomSummaryDataSource,
|
||||
private val roomListService: RoomListService,
|
||||
private val lastMessageTimestampFormatter: LastMessageTimestampFormatter,
|
||||
private val roomLastMessageFormatter: RoomLastMessageFormatter,
|
||||
private val coroutineDispatchers: CoroutineDispatchers,
|
||||
|
|
@ -61,8 +61,9 @@ class RoomListDataSource @Inject constructor(
|
|||
}
|
||||
|
||||
fun launchIn(coroutineScope: CoroutineScope) {
|
||||
roomSummaryDataSource
|
||||
roomListService
|
||||
.allRooms()
|
||||
.summaries
|
||||
.onEach { roomSummaries ->
|
||||
replaceWith(roomSummaries)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,8 +47,8 @@ import io.element.android.libraries.matrix.test.A_ROOM_NAME
|
|||
import io.element.android.libraries.matrix.test.A_USER_ID
|
||||
import io.element.android.libraries.matrix.test.A_USER_NAME
|
||||
import io.element.android.libraries.matrix.test.FakeMatrixClient
|
||||
import io.element.android.libraries.matrix.test.room.FakeRoomSummaryDataSource
|
||||
import io.element.android.libraries.matrix.test.room.aRoomSummaryFilled
|
||||
import io.element.android.libraries.matrix.test.roomlist.FakeRoomListService
|
||||
import io.element.android.libraries.matrix.test.verification.FakeSessionVerificationService
|
||||
import io.element.android.tests.testutils.consumeItemsUntilPredicate
|
||||
import io.element.android.tests.testutils.testCoroutineDispatchers
|
||||
|
|
@ -111,9 +111,9 @@ class RoomListPresenterTests {
|
|||
|
||||
@Test
|
||||
fun `present - load 1 room with success`() = runTest {
|
||||
val roomSummaryDataSource = FakeRoomSummaryDataSource()
|
||||
val roomListService = FakeRoomListService()
|
||||
val matrixClient = FakeMatrixClient(
|
||||
roomSummaryDataSource = roomSummaryDataSource
|
||||
roomListService = roomListService
|
||||
)
|
||||
val presenter = createRoomListPresenter(matrixClient)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
|
|
@ -123,7 +123,7 @@ class RoomListPresenterTests {
|
|||
// Room list is loaded with 16 placeholders
|
||||
Truth.assertThat(initialState.roomList.size).isEqualTo(16)
|
||||
Truth.assertThat(initialState.roomList.all { it.isPlaceholder }).isTrue()
|
||||
roomSummaryDataSource.postAllRooms(listOf(aRoomSummaryFilled()))
|
||||
roomListService.postAllRooms(listOf(aRoomSummaryFilled()))
|
||||
val withRoomState = consumeItemsUntilPredicate { state -> state.roomList.size == 1 }.last()
|
||||
Truth.assertThat(withRoomState.roomList.size).isEqualTo(1)
|
||||
Truth.assertThat(withRoomState.roomList.first())
|
||||
|
|
@ -133,15 +133,15 @@ class RoomListPresenterTests {
|
|||
|
||||
@Test
|
||||
fun `present - load 1 room with success and filter rooms`() = runTest {
|
||||
val roomSummaryDataSource = FakeRoomSummaryDataSource()
|
||||
val roomListService = FakeRoomListService()
|
||||
val matrixClient = FakeMatrixClient(
|
||||
roomSummaryDataSource = roomSummaryDataSource
|
||||
roomListService = roomListService
|
||||
)
|
||||
val presenter = createRoomListPresenter(matrixClient)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
roomSummaryDataSource.postAllRooms(listOf(aRoomSummaryFilled()))
|
||||
roomListService.postAllRooms(listOf(aRoomSummaryFilled()))
|
||||
val loadedState = consumeItemsUntilPredicate { state -> state.roomList.size == 1 }.last()
|
||||
// Test filtering with result
|
||||
loadedState.eventSink.invoke(RoomListEvents.UpdateFilter(A_ROOM_NAME.substring(0, 3)))
|
||||
|
|
@ -160,39 +160,39 @@ class RoomListPresenterTests {
|
|||
|
||||
@Test
|
||||
fun `present - update visible range`() = runTest {
|
||||
val roomSummaryDataSource = FakeRoomSummaryDataSource()
|
||||
val roomListService = FakeRoomListService()
|
||||
val matrixClient = FakeMatrixClient(
|
||||
roomSummaryDataSource = roomSummaryDataSource
|
||||
roomListService = roomListService
|
||||
)
|
||||
val presenter = createRoomListPresenter(matrixClient)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
roomSummaryDataSource.postAllRooms(listOf(aRoomSummaryFilled()))
|
||||
roomListService.postAllRooms(listOf(aRoomSummaryFilled()))
|
||||
val loadedState = awaitItem()
|
||||
// check initial value
|
||||
Truth.assertThat(roomSummaryDataSource.latestSlidingSyncRange).isNull()
|
||||
Truth.assertThat(roomListService.latestSlidingSyncRange).isNull()
|
||||
// Test empty range
|
||||
loadedState.eventSink.invoke(RoomListEvents.UpdateVisibleRange(IntRange(1, 0)))
|
||||
Truth.assertThat(roomSummaryDataSource.latestSlidingSyncRange).isNull()
|
||||
Truth.assertThat(roomListService.latestSlidingSyncRange).isNull()
|
||||
// Update visible range and check that range is transmitted to the SDK after computation
|
||||
loadedState.eventSink.invoke(RoomListEvents.UpdateVisibleRange(IntRange(0, 0)))
|
||||
Truth.assertThat(roomSummaryDataSource.latestSlidingSyncRange)
|
||||
Truth.assertThat(roomListService.latestSlidingSyncRange)
|
||||
.isEqualTo(IntRange(0, 20))
|
||||
loadedState.eventSink.invoke(RoomListEvents.UpdateVisibleRange(IntRange(0, 1)))
|
||||
Truth.assertThat(roomSummaryDataSource.latestSlidingSyncRange)
|
||||
Truth.assertThat(roomListService.latestSlidingSyncRange)
|
||||
.isEqualTo(IntRange(0, 21))
|
||||
loadedState.eventSink.invoke(RoomListEvents.UpdateVisibleRange(IntRange(19, 29)))
|
||||
Truth.assertThat(roomSummaryDataSource.latestSlidingSyncRange)
|
||||
Truth.assertThat(roomListService.latestSlidingSyncRange)
|
||||
.isEqualTo(IntRange(0, 49))
|
||||
loadedState.eventSink.invoke(RoomListEvents.UpdateVisibleRange(IntRange(49, 59)))
|
||||
Truth.assertThat(roomSummaryDataSource.latestSlidingSyncRange)
|
||||
Truth.assertThat(roomListService.latestSlidingSyncRange)
|
||||
.isEqualTo(IntRange(29, 79))
|
||||
loadedState.eventSink.invoke(RoomListEvents.UpdateVisibleRange(IntRange(149, 159)))
|
||||
Truth.assertThat(roomSummaryDataSource.latestSlidingSyncRange)
|
||||
Truth.assertThat(roomListService.latestSlidingSyncRange)
|
||||
.isEqualTo(IntRange(129, 179))
|
||||
loadedState.eventSink.invoke(RoomListEvents.UpdateVisibleRange(IntRange(149, 259)))
|
||||
Truth.assertThat(roomSummaryDataSource.latestSlidingSyncRange)
|
||||
Truth.assertThat(roomListService.latestSlidingSyncRange)
|
||||
.isEqualTo(IntRange(129, 279))
|
||||
cancelAndIgnoreRemainingEvents()
|
||||
}
|
||||
|
|
@ -200,9 +200,9 @@ class RoomListPresenterTests {
|
|||
|
||||
@Test
|
||||
fun `present - handle DismissRequestVerificationPrompt`() = runTest {
|
||||
val roomSummaryDataSource = FakeRoomSummaryDataSource()
|
||||
val roomListService = FakeRoomListService()
|
||||
val matrixClient = FakeMatrixClient(
|
||||
roomSummaryDataSource = roomSummaryDataSource
|
||||
roomListService = roomListService
|
||||
)
|
||||
val presenter = createRoomListPresenter(
|
||||
client = matrixClient,
|
||||
|
|
@ -317,7 +317,7 @@ class RoomListPresenterTests {
|
|||
inviteStateDataSource = inviteStateDataSource,
|
||||
leaveRoomPresenter = leaveRoomPresenter,
|
||||
roomListDataSource = RoomListDataSource(
|
||||
client.roomSummaryDataSource,
|
||||
client.roomListService,
|
||||
lastMessageTimestampFormatter,
|
||||
roomLastMessageFormatter,
|
||||
coroutineDispatchers = testCoroutineDispatchers()
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ import io.element.android.features.roomlist.impl.InvitesState
|
|||
import io.element.android.libraries.matrix.test.A_ROOM_ID
|
||||
import io.element.android.libraries.matrix.test.A_ROOM_ID_2
|
||||
import io.element.android.libraries.matrix.test.FakeMatrixClient
|
||||
import io.element.android.libraries.matrix.test.room.FakeRoomSummaryDataSource
|
||||
import io.element.android.libraries.matrix.test.room.aRoomSummaryFilled
|
||||
import io.element.android.libraries.matrix.test.roomlist.FakeRoomListService
|
||||
import io.element.android.tests.testutils.testCoroutineDispatchers
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Test
|
||||
|
|
@ -35,8 +35,8 @@ internal class DefaultInviteStateDataSourceTest {
|
|||
|
||||
@Test
|
||||
fun `emits NoInvites state if invites list is empty`() = runTest {
|
||||
val roomSummaryDataSource = FakeRoomSummaryDataSource()
|
||||
val client = FakeMatrixClient(roomSummaryDataSource = roomSummaryDataSource)
|
||||
val roomListService = FakeRoomListService()
|
||||
val client = FakeMatrixClient(roomListService = roomListService)
|
||||
val seenStore = FakeSeenInvitesStore()
|
||||
val dataSource = DefaultInviteStateDataSource(client, seenStore, testCoroutineDispatchers())
|
||||
|
||||
|
|
@ -49,9 +49,9 @@ internal class DefaultInviteStateDataSourceTest {
|
|||
|
||||
@Test
|
||||
fun `emits NewInvites state if unseen invite exists`() = runTest {
|
||||
val roomSummaryDataSource = FakeRoomSummaryDataSource()
|
||||
roomSummaryDataSource.postInviteRooms(listOf(aRoomSummaryFilled(roomId = A_ROOM_ID)))
|
||||
val client = FakeMatrixClient(roomSummaryDataSource = roomSummaryDataSource)
|
||||
val roomListService = FakeRoomListService()
|
||||
roomListService.postInviteRooms(listOf(aRoomSummaryFilled(roomId = A_ROOM_ID)))
|
||||
val client = FakeMatrixClient(roomListService = roomListService)
|
||||
val seenStore = FakeSeenInvitesStore()
|
||||
val dataSource = DefaultInviteStateDataSource(client, seenStore, testCoroutineDispatchers())
|
||||
|
||||
|
|
@ -65,9 +65,9 @@ internal class DefaultInviteStateDataSourceTest {
|
|||
|
||||
@Test
|
||||
fun `emits NewInvites state if multiple invites exist and at least one is unseen`() = runTest {
|
||||
val roomSummaryDataSource = FakeRoomSummaryDataSource()
|
||||
roomSummaryDataSource.postInviteRooms(listOf(aRoomSummaryFilled(roomId = A_ROOM_ID), aRoomSummaryFilled(roomId = A_ROOM_ID_2)))
|
||||
val client = FakeMatrixClient(roomSummaryDataSource = roomSummaryDataSource)
|
||||
val roomListService = FakeRoomListService()
|
||||
roomListService.postInviteRooms(listOf(aRoomSummaryFilled(roomId = A_ROOM_ID), aRoomSummaryFilled(roomId = A_ROOM_ID_2)))
|
||||
val client = FakeMatrixClient(roomListService = roomListService)
|
||||
val seenStore = FakeSeenInvitesStore()
|
||||
seenStore.publishRoomIds(setOf(A_ROOM_ID))
|
||||
val dataSource = DefaultInviteStateDataSource(client, seenStore, testCoroutineDispatchers(useUnconfinedTestDispatcher = true))
|
||||
|
|
@ -82,9 +82,9 @@ internal class DefaultInviteStateDataSourceTest {
|
|||
|
||||
@Test
|
||||
fun `emits SeenInvites state if invite exists in seen store`() = runTest {
|
||||
val roomSummaryDataSource = FakeRoomSummaryDataSource()
|
||||
roomSummaryDataSource.postInviteRooms(listOf(aRoomSummaryFilled(roomId = A_ROOM_ID)))
|
||||
val client = FakeMatrixClient(roomSummaryDataSource = roomSummaryDataSource)
|
||||
val roomListService = FakeRoomListService()
|
||||
roomListService.postInviteRooms(listOf(aRoomSummaryFilled(roomId = A_ROOM_ID)))
|
||||
val client = FakeMatrixClient(roomListService = roomListService)
|
||||
val seenStore = FakeSeenInvitesStore()
|
||||
seenStore.publishRoomIds(setOf(A_ROOM_ID))
|
||||
val dataSource = DefaultInviteStateDataSource(client, seenStore, testCoroutineDispatchers(useUnconfinedTestDispatcher = true))
|
||||
|
|
@ -100,8 +100,8 @@ internal class DefaultInviteStateDataSourceTest {
|
|||
|
||||
@Test
|
||||
fun `emits new state in response to upstream events`() = runTest {
|
||||
val roomSummaryDataSource = FakeRoomSummaryDataSource()
|
||||
val client = FakeMatrixClient(roomSummaryDataSource = roomSummaryDataSource)
|
||||
val roomListService = FakeRoomListService()
|
||||
val client = FakeMatrixClient(roomListService = roomListService)
|
||||
val seenStore = FakeSeenInvitesStore()
|
||||
val dataSource = DefaultInviteStateDataSource(client, seenStore, testCoroutineDispatchers())
|
||||
|
||||
|
|
@ -112,7 +112,7 @@ internal class DefaultInviteStateDataSourceTest {
|
|||
Truth.assertThat(awaitItem()).isEqualTo(InvitesState.NoInvites)
|
||||
|
||||
// When a single invite is received, state should be NewInvites
|
||||
roomSummaryDataSource.postInviteRooms(listOf(aRoomSummaryFilled(roomId = A_ROOM_ID)))
|
||||
roomListService.postInviteRooms(listOf(aRoomSummaryFilled(roomId = A_ROOM_ID)))
|
||||
skipItems(1)
|
||||
Truth.assertThat(awaitItem()).isEqualTo(InvitesState.NewInvites)
|
||||
|
||||
|
|
@ -122,12 +122,12 @@ internal class DefaultInviteStateDataSourceTest {
|
|||
Truth.assertThat(awaitItem()).isEqualTo(InvitesState.SeenInvites)
|
||||
|
||||
// Another new invite resets it to NewInvites
|
||||
roomSummaryDataSource.postInviteRooms(listOf(aRoomSummaryFilled(roomId = A_ROOM_ID), aRoomSummaryFilled(roomId = A_ROOM_ID_2)))
|
||||
roomListService.postInviteRooms(listOf(aRoomSummaryFilled(roomId = A_ROOM_ID), aRoomSummaryFilled(roomId = A_ROOM_ID_2)))
|
||||
skipItems(1)
|
||||
Truth.assertThat(awaitItem()).isEqualTo(InvitesState.NewInvites)
|
||||
|
||||
// All of the invites going away reverts to NoInvites
|
||||
roomSummaryDataSource.postInviteRooms(emptyList())
|
||||
roomListService.postInviteRooms(emptyList())
|
||||
skipItems(1)
|
||||
Truth.assertThat(awaitItem()).isEqualTo(InvitesState.NoInvites)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue