1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-06-16 18:30:00 +00:00

Fix deciding which streams are new

This commit is contained in:
TobiGr 2021-11-30 23:31:36 +01:00
parent a8fe2d7e83
commit fd1155928e
3 changed files with 22 additions and 18 deletions

View File

@ -42,7 +42,7 @@ class NotificationWorker(
.map { feed ->
feed.mapNotNull { x ->
x.value?.takeIf {
it.newStreamsCount > 0
it.newStreams.isNotEmpty()
}
}
}

View File

@ -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<StreamInfoItem>): Int {
var count = 0
for (item in list) {
if (feedDatabaseManager.doesStreamExist(item)) {
return count
} else {
count++
}
private fun filterNewStreams(list: List<StreamInfoItem>): List<StreamInfoItem> {
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
}
}

View File

@ -11,14 +11,17 @@ data class FeedUpdateInfo(
val notificationMode: Int,
val name: String,
val avatarUrl: String,
val listInfo: ListInfo<StreamInfoItem>
val listInfo: ListInfo<StreamInfoItem>,
) {
constructor(subscription: SubscriptionEntity, listInfo: ListInfo<StreamInfoItem>) : this(
constructor(
subscription: SubscriptionEntity,
listInfo: ListInfo<StreamInfoItem>,
) : 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<StreamInfoItem>
get() = listInfo.relatedItems.take(newStreamsCount)
lateinit var newStreams: List<StreamInfoItem>
}