From 3ba2c47d1eab7bec68aa04dfda007e97ad51efbb Mon Sep 17 00:00:00 2001 From: Maxime NATUREL <46314705+mnaturel@users.noreply.github.com> Date: Thu, 19 Jan 2023 17:30:06 +0100 Subject: [PATCH] Load more poll during sync if there is no completed backward load --- .../sdk/api/session/room/poll/LoadedPollsStatus.kt | 1 + .../session/room/poll/GetLoadedPollsStatusTask.kt | 1 + .../internal/session/room/poll/LoadMorePollsTask.kt | 1 + .../roomprofile/polls/list/domain/SyncPollsUseCase.kt | 11 +++++++++-- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/poll/LoadedPollsStatus.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/poll/LoadedPollsStatus.kt index f4a7dcc6c2..efc01e2cdf 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/poll/LoadedPollsStatus.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/poll/LoadedPollsStatus.kt @@ -22,4 +22,5 @@ package org.matrix.android.sdk.api.session.room.poll data class LoadedPollsStatus( val canLoadMore: Boolean, val nbSyncedDays: Int, + val hasCompletedASyncBackward: Boolean, ) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/poll/GetLoadedPollsStatusTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/poll/GetLoadedPollsStatusTask.kt index 118c81a451..98b1e5931a 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/poll/GetLoadedPollsStatusTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/poll/GetLoadedPollsStatusTask.kt @@ -42,6 +42,7 @@ internal class DefaultGetLoadedPollsStatusTask @Inject constructor( LoadedPollsStatus( canLoadMore = status.isEndOfPollsBackward.not(), nbSyncedDays = status.getNbSyncedDays(params.currentTimestampMs), + hasCompletedASyncBackward = status.hasCompletedASyncBackward, ) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/poll/LoadMorePollsTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/poll/LoadMorePollsTask.kt index 94b73ff211..0858d2ae91 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/poll/LoadMorePollsTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/poll/LoadMorePollsTask.kt @@ -65,6 +65,7 @@ internal class DefaultLoadMorePollsTask @Inject constructor( return LoadedPollsStatus( canLoadMore = currentPollHistoryStatus.isEndOfPollsBackward.not(), nbSyncedDays = currentPollHistoryStatus.getNbSyncedDays(params.currentTimestampMs), + hasCompletedASyncBackward = currentPollHistoryStatus.hasCompletedASyncBackward, ) } diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/polls/list/domain/SyncPollsUseCase.kt b/vector/src/main/java/im/vector/app/features/roomprofile/polls/list/domain/SyncPollsUseCase.kt index 7346406c84..7d58fb7694 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/polls/list/domain/SyncPollsUseCase.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/polls/list/domain/SyncPollsUseCase.kt @@ -21,15 +21,22 @@ import org.matrix.android.sdk.api.session.room.poll.LoadedPollsStatus 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( private val roomPollRepository: RoomPollRepository, private val getLoadedPollsStatusUseCase: GetLoadedPollsStatusUseCase, + private val loadMorePollsUseCase: LoadMorePollsUseCase, ) { suspend fun execute(roomId: String): LoadedPollsStatus { roomPollRepository.syncPolls(roomId) - return getLoadedPollsStatusUseCase.execute(roomId) + val loadedStatus = getLoadedPollsStatusUseCase.execute(roomId) + return if (loadedStatus.hasCompletedASyncBackward) { + loadedStatus + } else { + loadMorePollsUseCase.execute(roomId) + } } }