Renaming API field and adding more doc to make things clearer

This commit is contained in:
Maxime NATUREL 2023-01-26 10:33:42 +01:00
parent fc26d61305
commit c7d3e1926f
11 changed files with 32 additions and 16 deletions

View File

@ -20,7 +20,20 @@ package org.matrix.android.sdk.api.session.room.poll
* Represent the status of the loaded polls for a room.
*/
data class LoadedPollsStatus(
/**
* Indicate whether more polls can be loaded from timeline.
* A false value would mean the start of the timeline has been reached.
*/
val canLoadMore: Boolean,
val nbSyncedDays: Int,
/**
* Number of days of timeline events currently synced (fetched and stored in local).
*/
val daysSynced: Int,
/**
* Indicate whether a sync of timeline events has been completely done in backward. It would
* mean timeline events have been synced for at least a number of days defined by [PollHistoryService.loadingPeriodInDays].
*/
val hasCompletedASyncBackward: Boolean,
)

View File

@ -24,6 +24,9 @@ import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
*/
interface PollHistoryService {
/**
* The number of days covered when requesting to load more polls.
*/
val loadingPeriodInDays: Int
/**

View File

@ -43,7 +43,7 @@ internal class DefaultGetLoadedPollsStatusTask @Inject constructor(
.copy()
LoadedPollsStatus(
canLoadMore = status.isEndOfPollsBackward.not(),
nbSyncedDays = status.getNbSyncedDays(params.currentTimestampMs),
daysSynced = status.getNbSyncedDays(params.currentTimestampMs),
hasCompletedASyncBackward = status.hasCompletedASyncBackward,
)
}

View File

@ -53,7 +53,7 @@ internal class DefaultLoadMorePollsTask @Inject constructor(
return LoadedPollsStatus(
canLoadMore = currentPollHistoryStatus.isEndOfPollsBackward.not(),
nbSyncedDays = currentPollHistoryStatus.getNbSyncedDays(params.currentTimestampMs),
daysSynced = currentPollHistoryStatus.getNbSyncedDays(params.currentTimestampMs),
hasCompletedASyncBackward = currentPollHistoryStatus.hasCompletedASyncBackward,
)
}

View File

@ -68,7 +68,7 @@ class RoomPollsViewModel @AssistedInject constructor(
setState {
copy(
canLoadMore = loadedPollsStatus.canLoadMore,
nbSyncedDays = loadedPollsStatus.nbSyncedDays,
nbSyncedDays = loadedPollsStatus.daysSynced,
)
}
}
@ -100,7 +100,7 @@ class RoomPollsViewModel @AssistedInject constructor(
setState {
copy(
canLoadMore = status.canLoadMore,
nbSyncedDays = status.nbSyncedDays,
nbSyncedDays = status.daysSynced,
)
}
}

View File

@ -75,7 +75,7 @@ class RoomPollsViewModelTest {
val expectedViewState = initialState.copy(
polls = listOf(aPollSummary),
canLoadMore = loadedPollsStatus.canLoadMore,
nbSyncedDays = loadedPollsStatus.nbSyncedDays,
nbSyncedDays = loadedPollsStatus.daysSynced,
)
// When
@ -135,7 +135,7 @@ class RoomPollsViewModelTest {
val stateAfterInit = initialState.copy(
polls = emptyList(),
canLoadMore = loadedPollsStatus.canLoadMore,
nbSyncedDays = loadedPollsStatus.nbSyncedDays,
nbSyncedDays = loadedPollsStatus.daysSynced,
)
// When
@ -147,7 +147,7 @@ class RoomPollsViewModelTest {
.assertStatesChanges(
stateAfterInit,
{ copy(isLoadingMore = true) },
{ copy(canLoadMore = newLoadedPollsStatus.canLoadMore, nbSyncedDays = newLoadedPollsStatus.nbSyncedDays) },
{ copy(canLoadMore = newLoadedPollsStatus.canLoadMore, nbSyncedDays = newLoadedPollsStatus.daysSynced) },
{ copy(isLoadingMore = false) },
)
.finish()
@ -181,7 +181,7 @@ class RoomPollsViewModelTest {
private fun givenALoadedPollsStatus(canLoadMore: Boolean = true, nbSyncedDays: Int = 10) =
LoadedPollsStatus(
canLoadMore = canLoadMore,
nbSyncedDays = nbSyncedDays,
daysSynced = nbSyncedDays,
hasCompletedASyncBackward = false,
)
}

View File

@ -124,7 +124,7 @@ internal class RoomPollDataSourceTest {
private fun givenALoadedPollsStatus() = LoadedPollsStatus(
canLoadMore = true,
nbSyncedDays = 10,
daysSynced = 10,
hasCompletedASyncBackward = true,
)
}

View File

@ -72,7 +72,7 @@ class RoomPollRepositoryTest {
// Given
val expectedStatus = LoadedPollsStatus(
canLoadMore = true,
nbSyncedDays = 10,
daysSynced = 10,
hasCompletedASyncBackward = false,
)
coEvery { fakeRoomPollDataSource.getLoadedPollsStatus(A_ROOM_ID) } returns expectedStatus

View File

@ -39,7 +39,7 @@ class GetLoadedPollsStatusUseCaseTest {
val aRoomId = "roomId"
val expectedStatus = LoadedPollsStatus(
canLoadMore = true,
nbSyncedDays = 10,
daysSynced = 10,
hasCompletedASyncBackward = true,
)
coEvery { fakeRoomPollRepository.getLoadedPollsStatus(aRoomId) } returns expectedStatus

View File

@ -39,7 +39,7 @@ class LoadMorePollsUseCaseTest {
val aRoomId = "roomId"
val loadedPollsStatus = LoadedPollsStatus(
canLoadMore = true,
nbSyncedDays = 10,
daysSynced = 10,
hasCompletedASyncBackward = true,
)
coEvery { fakeRoomPollRepository.loadMorePolls(aRoomId) } returns loadedPollsStatus

View File

@ -45,7 +45,7 @@ class SyncPollsUseCaseTest {
val aRoomId = "roomId"
val aLoadedStatus = LoadedPollsStatus(
canLoadMore = true,
nbSyncedDays = 10,
daysSynced = 10,
hasCompletedASyncBackward = true,
)
coJustRun { fakeRoomPollRepository.syncPolls(aRoomId) }
@ -71,12 +71,12 @@ class SyncPollsUseCaseTest {
val aRoomId = "roomId"
val aLoadedStatus = LoadedPollsStatus(
canLoadMore = true,
nbSyncedDays = 10,
daysSynced = 10,
hasCompletedASyncBackward = false,
)
val anUpdatedLoadedStatus = LoadedPollsStatus(
canLoadMore = true,
nbSyncedDays = 10,
daysSynced = 10,
hasCompletedASyncBackward = true,
)
coJustRun { fakeRoomPollRepository.syncPolls(aRoomId) }