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

Commit fd46df8

Browse files
committed
818: Also support boosts; rework logging a bit
1 parent 95ced4a commit fd46df8

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

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
@@ -441,22 +441,18 @@ class NotificationsFragment :
441441
private fun removeDuplicateOlderEntries(positionStart: Int) {
442442
val dataList = adapter.snapshot().items
443443

444-
Log.w(TAG, "found elements in adapter "+dataList.size)
445-
446-
for (pos in dataList.size - 1 downTo positionStart) {
444+
for (pos in dataList.lastIndex downTo positionStart) {
447445
val notificationViewData = dataList[pos]
448446

449447
val status = notificationViewData.statusViewData?.status
450448
?: continue
451449

452450
if (!viewModel.hasNewestNotificationId(notificationViewData.type, status.id, notificationViewData.id)) {
453-
Log.w(TAG, "Removing old notification at "+pos+" for "+status.id)
451+
Log.d(TAG, "Removing old notification at "+pos+" for "+status.id+" at "+status.createdAt)
454452

455453
adapter.notifyItemRemoved(pos)
456454
}
457455
}
458-
459-
Log.w(TAG, "elements after second "+ adapter.snapshot().size)
460456
}
461457

462458
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
@@ -485,7 +485,8 @@ class NotificationsViewModel @Inject constructor(
485485
}
486486

487487
// Status id -> (highest) Notification id
488-
val seenFavorites = HashMap<String, String>()
488+
private val seenFavorites = HashMap<String, String>()
489+
private val seenBoosts = HashMap<String, String>()
489490

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

500501
return@filter if (hasNewestNotificationId(notification.type, status.id, notification.id)) {
501-
seenFavorites[status.id] = notification.id // TODO move to hasNewestNotificationId?
502-
503502
true
504503
} else {
504+
Log.d(TAG, "Filtering notification for "+status.id+" at "+status.createdAt)
505505
false
506506
}
507507
}
@@ -517,13 +517,25 @@ class NotificationsViewModel @Inject constructor(
517517
}
518518

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

524-
val highestNotificationId = seenFavorites[statusId]
528+
return if (highestNotificationId == null || isEqualOrNewer(notificationId, highestNotificationId)) {
529+
trackerArray[statusId] = notificationId
525530

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

529541
/**

0 commit comments

Comments
 (0)