Skip to content
This repository was archived by the owner on May 23, 2025. It is now read-only.

Commit 503c58f

Browse files
committed
818: Avoid "list is empty" (due to a crash in load())
1 parent baa42d0 commit 503c58f

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

app/src/main/java/com/keylesspalace/tusky/components/notifications/NotificationsPagingSource.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,13 @@ class NotificationsPagingSource @Inject constructor(
9595

9696
// TODO this is the only location with the "raw" data for answering the TODO in NotificationsViewModel.hasNewestNotificationId()?
9797
// However the heuristic there would need (at least) the full range of notification ids here (so multiple calls to this method)?
98-
val apiNotificationIds = response.body()!!.map { it.id }
99-
Log.w(TAG, "Got notifications from api "+apiNotificationIds.first()+"-"+apiNotificationIds.last())
98+
val notificationList = response.body()!!
99+
val apiNotificationIds = notificationList.map { it.id }
100+
Log.w(TAG, (if (params is LoadParams.Refresh) "R" else "A/P") +" Got notifications from api "+apiNotificationIds.firstOrNull()+"-"+apiNotificationIds.lastOrNull())
100101

101102
val links = Links.from(response.headers()["link"])
102103
return LoadResult.Page(
103-
data = response.body()!!,
104+
data = notificationList,
104105
nextKey = links.next,
105106
prevKey = links.prev
106107
)

app/src/main/java/com/keylesspalace/tusky/components/notifications/NotificationsViewModel.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import com.keylesspalace.tusky.settings.PrefKeys
4141
import com.keylesspalace.tusky.usecase.TimelineCases
4242
import com.keylesspalace.tusky.util.StatusDisplayOptions
4343
import com.keylesspalace.tusky.util.deserialize
44-
import com.keylesspalace.tusky.util.isLessThan
44+
import com.keylesspalace.tusky.util.isLessThanOrEqual
4545
import com.keylesspalace.tusky.util.serialize
4646
import com.keylesspalace.tusky.util.throttleFirst
4747
import com.keylesspalace.tusky.util.toViewData
@@ -531,9 +531,7 @@ class NotificationsViewModel @Inject constructor(
531531
return@filter if (hasNewestNotificationId(notification.type, status.id, notification.id)) {
532532
true
533533
} else {
534-
// TODO this now leads sometimes (?) to a "List is empty" being displayed as first item.
535-
536-
Log.d(TAG, "Filtering notification "+(n-1)+" for "+status.id+" at "+status.createdAt)
534+
Log.d(TAG, "Filtering notification "+(n-1)+" for "+status.id+"/"+notification.id+" at "+status.createdAt)
537535
false
538536
}
539537
}
@@ -568,7 +566,7 @@ class NotificationsViewModel @Inject constructor(
568566

569567
val highestNotificationId = trackerArray[statusId]
570568

571-
return if (highestNotificationId == null || highestNotificationId.isLessThan(notificationId)) {
569+
return if (highestNotificationId == null || highestNotificationId.isLessThanOrEqual(notificationId)) {
572570
trackerArray[statusId] = notificationId
573571

574572
true

0 commit comments

Comments
 (0)