Fix disappearing placeholders (#2309)
* add getNextPlaceholderIdAfter to TimelineDao * fix disappearing placeholders * fix disappearing placeholders
This commit is contained in:
parent
c3da6f901f
commit
61ba6fe181
6 changed files with 178 additions and 21 deletions
|
@ -53,11 +53,19 @@ class CachedTimelineRemoteMediator(
|
|||
|
||||
try {
|
||||
var dbEmpty = false
|
||||
|
||||
val topPlaceholderId = if (loadType == LoadType.REFRESH) {
|
||||
timelineDao.getTopPlaceholderId(activeAccount.id)
|
||||
} else {
|
||||
null // don't execute the query if it is not needed
|
||||
}
|
||||
|
||||
if (!initialRefresh && loadType == LoadType.REFRESH) {
|
||||
val topId = timelineDao.getTopId(activeAccount.id)
|
||||
topId?.let { cachedTopId ->
|
||||
val statusResponse = api.homeTimeline(
|
||||
maxId = cachedTopId,
|
||||
sinceId = topPlaceholderId, // so already existing placeholders don't get accidentally overwritten
|
||||
limit = state.config.pageSize
|
||||
).await()
|
||||
|
||||
|
@ -74,7 +82,7 @@ class CachedTimelineRemoteMediator(
|
|||
|
||||
val statusResponse = when (loadType) {
|
||||
LoadType.REFRESH -> {
|
||||
api.homeTimeline(limit = state.config.pageSize).await()
|
||||
api.homeTimeline(sinceId = topPlaceholderId, limit = state.config.pageSize).await()
|
||||
}
|
||||
LoadType.PREPEND -> {
|
||||
return MediatorResult.Success(endOfPaginationReached = true)
|
||||
|
|
|
@ -128,7 +128,9 @@ class CachedTimelineViewModel @Inject constructor(
|
|||
|
||||
timelineDao.insertStatus(Placeholder(placeholderId, loading = true).toEntity(activeAccount.id))
|
||||
|
||||
val response = api.homeTimeline(maxId = placeholderId.inc(), limit = 20).await()
|
||||
val nextPlaceholderId = timelineDao.getNextPlaceholderIdAfter(activeAccount.id, placeholderId)
|
||||
|
||||
val response = api.homeTimeline(maxId = placeholderId.inc(), sinceId = nextPlaceholderId, limit = 20).await()
|
||||
|
||||
val statuses = response.body()
|
||||
if (!response.isSuccessful || statuses == null) {
|
||||
|
|
|
@ -142,4 +142,10 @@ AND timelineUserId = :accountId
|
|||
|
||||
@Query("SELECT serverId FROM TimelineStatusEntity WHERE timelineUserId = :accountId ORDER BY LENGTH(serverId) DESC, serverId DESC LIMIT 1")
|
||||
abstract suspend fun getTopId(accountId: Long): String?
|
||||
|
||||
@Query("SELECT serverId FROM TimelineStatusEntity WHERE timelineUserId = :accountId AND authorServerId IS NULL ORDER BY LENGTH(serverId) DESC, serverId DESC LIMIT 1")
|
||||
abstract suspend fun getTopPlaceholderId(accountId: Long): String?
|
||||
|
||||
@Query("SELECT serverId FROM TimelineStatusEntity WHERE timelineUserId = :accountId AND authorServerId IS NULL AND (LENGTH(:serverId) > LENGTH(serverId) OR (LENGTH(:serverId) = LENGTH(serverId) AND :serverId > serverId)) ORDER BY LENGTH(serverId) DESC, serverId DESC LIMIT 1")
|
||||
abstract suspend fun getNextPlaceholderIdAfter(accountId: Long, serverId: String): String?
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue