migrate timeline api calls from Rx Single to suspending functions (#2690)
* migrate timeline api calls from Rx Single to suspending functions * fix tests
This commit is contained in:
parent
25ba40a7ec
commit
655ce30031
6 changed files with 80 additions and 106 deletions
|
@ -22,7 +22,6 @@ import androidx.paging.RemoteMediator
|
|||
import com.keylesspalace.tusky.components.timeline.util.ifExpected
|
||||
import com.keylesspalace.tusky.network.MastodonApi
|
||||
import com.keylesspalace.tusky.viewdata.AttachmentViewData
|
||||
import kotlinx.coroutines.rx3.await
|
||||
import retrofit2.HttpException
|
||||
|
||||
@OptIn(ExperimentalPagingApi::class)
|
||||
|
@ -39,7 +38,7 @@ class AccountMediaRemoteMediator(
|
|||
try {
|
||||
val statusResponse = when (loadType) {
|
||||
LoadType.REFRESH -> {
|
||||
api.accountStatuses(viewModel.accountId, onlyMedia = true).await()
|
||||
api.accountStatuses(viewModel.accountId, onlyMedia = true)
|
||||
}
|
||||
LoadType.PREPEND -> {
|
||||
return MediatorResult.Success(endOfPaginationReached = true)
|
||||
|
@ -47,7 +46,7 @@ class AccountMediaRemoteMediator(
|
|||
LoadType.APPEND -> {
|
||||
val maxId = state.lastItemOrNull()?.statusId
|
||||
if (maxId != null) {
|
||||
api.accountStatuses(viewModel.accountId, maxId = maxId, onlyMedia = true).await()
|
||||
api.accountStatuses(viewModel.accountId, maxId = maxId, onlyMedia = true)
|
||||
} else {
|
||||
return MediatorResult.Success(endOfPaginationReached = false)
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ import com.keylesspalace.tusky.db.TimelineStatusEntity
|
|||
import com.keylesspalace.tusky.db.TimelineStatusWithAccount
|
||||
import com.keylesspalace.tusky.entity.Status
|
||||
import com.keylesspalace.tusky.network.MastodonApi
|
||||
import kotlinx.coroutines.rx3.await
|
||||
import retrofit2.HttpException
|
||||
|
||||
@OptIn(ExperimentalPagingApi::class)
|
||||
|
@ -71,7 +70,7 @@ class CachedTimelineRemoteMediator(
|
|||
maxId = cachedTopId,
|
||||
sinceId = topPlaceholderId, // so already existing placeholders don't get accidentally overwritten
|
||||
limit = state.config.pageSize
|
||||
).await()
|
||||
)
|
||||
|
||||
val statuses = statusResponse.body()
|
||||
if (statusResponse.isSuccessful && statuses != null) {
|
||||
|
@ -86,14 +85,14 @@ class CachedTimelineRemoteMediator(
|
|||
|
||||
val statusResponse = when (loadType) {
|
||||
LoadType.REFRESH -> {
|
||||
api.homeTimeline(sinceId = topPlaceholderId, limit = state.config.pageSize).await()
|
||||
api.homeTimeline(sinceId = topPlaceholderId, limit = state.config.pageSize)
|
||||
}
|
||||
LoadType.PREPEND -> {
|
||||
return MediatorResult.Success(endOfPaginationReached = true)
|
||||
}
|
||||
LoadType.APPEND -> {
|
||||
val maxId = state.pages.findLast { it.data.isNotEmpty() }?.data?.lastOrNull()?.status?.serverId
|
||||
api.homeTimeline(maxId = maxId, limit = state.config.pageSize).await()
|
||||
api.homeTimeline(maxId = maxId, limit = state.config.pageSize)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,6 @@ import kotlinx.coroutines.delay
|
|||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.rx3.await
|
||||
import retrofit2.HttpException
|
||||
import javax.inject.Inject
|
||||
import kotlin.time.DurationUnit
|
||||
|
@ -176,7 +175,7 @@ class CachedTimelineViewModel @Inject constructor(
|
|||
sinceId = nextPlaceholderId,
|
||||
limit = LOAD_AT_ONCE
|
||||
)
|
||||
}.await()
|
||||
}
|
||||
|
||||
val statuses = response.body()
|
||||
if (!response.isSuccessful || statuses == null) {
|
||||
|
|
|
@ -45,7 +45,6 @@ import kotlinx.coroutines.asExecutor
|
|||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.rx3.await
|
||||
import retrofit2.HttpException
|
||||
import retrofit2.Response
|
||||
import java.io.IOException
|
||||
|
@ -298,7 +297,7 @@ class NetworkTimelineViewModel @Inject constructor(
|
|||
Kind.FAVOURITES -> api.favourites(fromId, uptoId, limit)
|
||||
Kind.BOOKMARKS -> api.bookmarks(fromId, uptoId, limit)
|
||||
Kind.LIST -> api.listTimeline(id!!, fromId, uptoId, limit)
|
||||
}.await()
|
||||
}
|
||||
}
|
||||
|
||||
private fun StatusViewData.Concrete.update() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue