diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationWorker.kt b/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationWorker.kt index 1c75442a1..df1ddd5c9 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationWorker.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationWorker.kt @@ -42,7 +42,7 @@ class NotificationWorker( .map { feed -> feed.mapNotNull { x -> x.value?.takeIf { - it.newStreamsCount > 0 + it.newStreams.isNotEmpty() } } } diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadManager.kt b/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadManager.kt index d5bcce419..aa4b40f5b 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadManager.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadManager.kt @@ -214,7 +214,10 @@ class FeedLoadManager(private val context: Context) { val subscriptionId = notification.value!!.uid val info = notification.value!!.listInfo - notification.value!!.newStreamsCount = countNewStreams(info.relatedItems) + notification.value!!.newStreams = filterNewStreams( + notification.value!!.listInfo.relatedItems + ) + feedDatabaseManager.upsertAll(subscriptionId, info.relatedItems) subscriptionManager.updateFromInfo(subscriptionId, info) @@ -241,16 +244,17 @@ class FeedLoadManager(private val context: Context) { } } - private fun countNewStreams(list: List): Int { - var count = 0 - for (item in list) { - if (feedDatabaseManager.doesStreamExist(item)) { - return count - } else { - count++ - } + private fun filterNewStreams(list: List): List { + return list.filter { + !feedDatabaseManager.doesStreamExist(it) && + it.uploadDate != null && + // Streams older than this date are automatically removed from the feed. + // Therefore, streams which are not in the database, + // but older than this date, are considered old. + it.uploadDate!!.offsetDateTime().isAfter( + FeedDatabaseManager.FEED_OLDEST_ALLOWED_DATE + ) } - return 0 } } diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedUpdateInfo.kt b/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedUpdateInfo.kt index a86578e15..5f72a6b84 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedUpdateInfo.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedUpdateInfo.kt @@ -11,14 +11,17 @@ data class FeedUpdateInfo( val notificationMode: Int, val name: String, val avatarUrl: String, - val listInfo: ListInfo + val listInfo: ListInfo, ) { - constructor(subscription: SubscriptionEntity, listInfo: ListInfo) : this( + constructor( + subscription: SubscriptionEntity, + listInfo: ListInfo, + ) : this( uid = subscription.uid, notificationMode = subscription.notificationMode, name = subscription.name, avatarUrl = subscription.avatarUrl, - listInfo = listInfo + listInfo = listInfo, ) /** @@ -27,8 +30,5 @@ data class FeedUpdateInfo( val pseudoId: Int get() = listInfo.url.hashCode() - var newStreamsCount: Int = 0 - - val newStreams: List - get() = listInfo.relatedItems.take(newStreamsCount) + lateinit var newStreams: List }