Load more poll during sync if there is no completed backward load

This commit is contained in:
Maxime NATUREL 2023-01-19 17:30:06 +01:00
parent 91904a3e8f
commit 3ba2c47d1e
4 changed files with 12 additions and 2 deletions

View File

@ -22,4 +22,5 @@ package org.matrix.android.sdk.api.session.room.poll
data class LoadedPollsStatus( data class LoadedPollsStatus(
val canLoadMore: Boolean, val canLoadMore: Boolean,
val nbSyncedDays: Int, val nbSyncedDays: Int,
val hasCompletedASyncBackward: Boolean,
) )

View File

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

View File

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

View File

@ -21,15 +21,22 @@ import org.matrix.android.sdk.api.session.room.poll.LoadedPollsStatus
import javax.inject.Inject import javax.inject.Inject
/** /**
* Sync the polls of a given room from last manual loading (see LoadMorePollsUseCase) until now. * Sync the polls of a given room from last manual loading if any (see LoadMorePollsUseCase) until now.
* Resume or start loading more to have at least a complete load.
*/ */
class SyncPollsUseCase @Inject constructor( class SyncPollsUseCase @Inject constructor(
private val roomPollRepository: RoomPollRepository, private val roomPollRepository: RoomPollRepository,
private val getLoadedPollsStatusUseCase: GetLoadedPollsStatusUseCase, private val getLoadedPollsStatusUseCase: GetLoadedPollsStatusUseCase,
private val loadMorePollsUseCase: LoadMorePollsUseCase,
) { ) {
suspend fun execute(roomId: String): LoadedPollsStatus { suspend fun execute(roomId: String): LoadedPollsStatus {
roomPollRepository.syncPolls(roomId) roomPollRepository.syncPolls(roomId)
return getLoadedPollsStatusUseCase.execute(roomId) val loadedStatus = getLoadedPollsStatusUseCase.execute(roomId)
return if (loadedStatus.hasCompletedASyncBackward) {
loadedStatus
} else {
loadMorePollsUseCase.execute(roomId)
}
} }
} }