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

Commit 8bd99c1

Browse files
committed
818: Also support boosts; rework logging a bit
1 parent 774b5a9 commit 8bd99c1

2 files changed

Lines changed: 22 additions & 14 deletions

File tree

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -427,22 +427,18 @@ class NotificationsFragment :
427427
private fun removeDuplicateOlderEntries(positionStart: Int) {
428428
val dataList = adapter.snapshot().items
429429

430-
Log.w(TAG, "found elements in adapter "+dataList.size)
431-
432-
for (pos in dataList.size - 1 downTo positionStart) {
430+
for (pos in dataList.lastIndex downTo positionStart) {
433431
val notificationViewData = dataList[pos]
434432

435433
val status = notificationViewData.statusViewData?.status
436434
?: continue
437435

438436
if (!viewModel.hasNewestNotificationId(notificationViewData.type, status.id, notificationViewData.id)) {
439-
Log.w(TAG, "Removing old notification at "+pos+" for "+status.id)
437+
Log.d(TAG, "Removing old notification at "+pos+" for "+status.id+" at "+status.createdAt)
440438

441439
adapter.notifyItemRemoved(pos)
442440
}
443441
}
444-
445-
Log.w(TAG, "elements after second "+ adapter.snapshot().size)
446442
}
447443

448444
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,8 @@ class NotificationsViewModel @Inject constructor(
484484
}
485485

486486
// Status id -> (highest) Notification id
487-
val seenFavorites = HashMap<String, String>()
487+
private val seenFavorites = HashMap<String, String>()
488+
private val seenBoosts = HashMap<String, String>()
488489

489490
private fun getNotifications(
490491
filters: Set<Notification.Type>,
@@ -497,10 +498,9 @@ class NotificationsViewModel @Inject constructor(
497498
?: return@filter true
498499

499500
return@filter if (hasNewestNotificationId(notification.type, status.id, notification.id)) {
500-
seenFavorites[status.id] = notification.id // TODO move to hasNewestNotificationId?
501-
502501
true
503502
} else {
503+
Log.d(TAG, "Filtering notification for "+status.id+" at "+status.createdAt)
504504
false
505505
}
506506
}
@@ -516,13 +516,25 @@ class NotificationsViewModel @Inject constructor(
516516
}
517517

518518
fun hasNewestNotificationId(type: Notification.Type, statusId: String, notificationId: String): Boolean {
519-
if (type != Notification.Type.FAVOURITE) {
520-
return true
521-
}
519+
val trackerArray = when(type) {
520+
Notification.Type.FAVOURITE -> seenFavorites
521+
Notification.Type.REBLOG -> seenBoosts
522+
else -> null
523+
} ?: return true
524+
525+
val highestNotificationId = trackerArray[statusId]
522526

523-
val highestNotificationId = seenFavorites[statusId]
527+
return if (highestNotificationId == null || isEqualOrNewer(notificationId, highestNotificationId)) {
528+
trackerArray[statusId] = notificationId
524529

525-
return highestNotificationId == null || isEqualOrNewer(notificationId, highestNotificationId)
530+
true
531+
} else {
532+
// TODO edge case: a newer favorite has been removed: the old notification will not be added again
533+
// (because the removed id is still in the seen array)
534+
// The code could find this out only heuristically: "looking at these notification ids (range), one in the array is not amongst them"
535+
536+
false
537+
}
526538
}
527539

528540
/**

0 commit comments

Comments
 (0)