File tree Expand file tree Collapse file tree
app/src/main/java/org/schabi/newpipe/local/feed Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ class NotificationWorker(
4242 .map { feed ->
4343 feed.mapNotNull { x ->
4444 x.value?.takeIf {
45- it.newStreamsCount > 0
45+ it.newStreams.isNotEmpty()
4646 }
4747 }
4848 }
Original file line number Diff line number Diff line change @@ -214,7 +214,10 @@ class FeedLoadManager(private val context: Context) {
214214 val subscriptionId = notification.value!! .uid
215215 val info = notification.value!! .listInfo
216216
217- notification.value!! .newStreamsCount = countNewStreams(info.relatedItems)
217+ notification.value!! .newStreams = filterNewStreams(
218+ notification.value!! .listInfo.relatedItems
219+ )
220+
218221 feedDatabaseManager.upsertAll(subscriptionId, info.relatedItems)
219222 subscriptionManager.updateFromInfo(subscriptionId, info)
220223
@@ -241,16 +244,17 @@ class FeedLoadManager(private val context: Context) {
241244 }
242245 }
243246
244- private fun countNewStreams (list : List <StreamInfoItem >): Int {
245- var count = 0
246- for (item in list) {
247- if (feedDatabaseManager.doesStreamExist(item)) {
248- return count
249- } else {
250- count++
251- }
247+ private fun filterNewStreams (list : List <StreamInfoItem >): List <StreamInfoItem > {
248+ return list.filter {
249+ ! feedDatabaseManager.doesStreamExist(it) &&
250+ it.uploadDate != null &&
251+ // Streams older than this date are automatically removed from the feed.
252+ // Therefore, streams which are not in the database,
253+ // but older than this date, are considered old.
254+ it.uploadDate!! .offsetDateTime().isAfter(
255+ FeedDatabaseManager .FEED_OLDEST_ALLOWED_DATE
256+ )
252257 }
253- return 0
254258 }
255259 }
256260
Original file line number Diff line number Diff line change @@ -11,14 +11,17 @@ data class FeedUpdateInfo(
1111 val notificationMode : Int ,
1212 val name : String ,
1313 val avatarUrl : String ,
14- val listInfo : ListInfo <StreamInfoItem >
14+ val listInfo : ListInfo <StreamInfoItem >,
1515) {
16- constructor (subscription: SubscriptionEntity , listInfo: ListInfo <StreamInfoItem >) : this (
16+ constructor (
17+ subscription: SubscriptionEntity ,
18+ listInfo: ListInfo <StreamInfoItem >,
19+ ) : this (
1720 uid = subscription.uid,
1821 notificationMode = subscription.notificationMode,
1922 name = subscription.name,
2023 avatarUrl = subscription.avatarUrl,
21- listInfo = listInfo
24+ listInfo = listInfo,
2225 )
2326
2427 /* *
@@ -27,8 +30,5 @@ data class FeedUpdateInfo(
2730 val pseudoId: Int
2831 get() = listInfo.url.hashCode()
2932
30- var newStreamsCount: Int = 0
31-
32- val newStreams: List <StreamInfoItem >
33- get() = listInfo.relatedItems.take(newStreamsCount)
33+ lateinit var newStreams: List <StreamInfoItem >
3434}
You can’t perform that action at this time.
0 commit comments