Load more poll during sync if there is no completed backward load
This commit is contained in:
parent
91904a3e8f
commit
3ba2c47d1e
|
@ -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,
|
||||||
)
|
)
|
||||||
|
|
|
@ -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,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue