fix empty timeline on initial load (#2586)

This commit is contained in:
Konrad Pozniak 2022-06-20 16:11:30 +02:00 committed by GitHub
parent 2e33233309
commit dba2fbc5c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 4 deletions

View file

@ -267,8 +267,11 @@ class CachedTimelineViewModel @Inject constructor(
}
}
override fun invalidate() {
currentPagingSource?.invalidate()
override suspend fun invalidate() {
// invalidating when we don't have statuses yet can cause empty timelines because it cancels the network load
if (db.timelineDao().getStatusCount(accountManager.activeAccount!!.id) > 0) {
currentPagingSource?.invalidate()
}
}
companion object {

View file

@ -249,7 +249,7 @@ class NetworkTimelineViewModel @Inject constructor(
currentSource?.invalidate()
}
override fun invalidate() {
override suspend fun invalidate() {
currentSource?.invalidate()
}

View file

@ -174,7 +174,7 @@ abstract class TimelineViewModel(
abstract fun fullReload()
/** Triggered when currently displayed data must be reloaded. */
protected abstract fun invalidate()
protected abstract suspend fun invalidate()
protected fun shouldFilterStatus(statusViewData: StatusViewData): Boolean {
val status = statusViewData.asStatusOrNull()?.status ?: return false

View file

@ -197,4 +197,7 @@ AND timelineUserId = :accountId
*/
@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?
@Query("SELECT COUNT(*) FROM TimelineStatusEntity WHERE timelineUserId = :accountId")
abstract suspend fun getStatusCount(accountId: Long): Int
}