1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-24 00:50:32 +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 -> .map { feed ->
feed.mapNotNull { x -> feed.mapNotNull { x ->
x.value?.takeIf { 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 subscriptionId = notification.value!!.uid
val info = notification.value!!.listInfo val info = notification.value!!.listInfo
notification.value!!.newStreamsCount = countNewStreams(info.relatedItems) notification.value!!.newStreams = filterNewStreams(
notification.value!!.listInfo.relatedItems
)
feedDatabaseManager.upsertAll(subscriptionId, info.relatedItems) feedDatabaseManager.upsertAll(subscriptionId, info.relatedItems)
subscriptionManager.updateFromInfo(subscriptionId, info) subscriptionManager.updateFromInfo(subscriptionId, info)
@ -241,17 +244,18 @@ class FeedLoadManager(private val context: Context) {
} }
} }
private fun countNewStreams(list: List<StreamInfoItem>): Int { private fun filterNewStreams(list: List<StreamInfoItem>): List<StreamInfoItem> {
var count = 0 return list.filter {
for (item in list) { !feedDatabaseManager.doesStreamExist(it) &&
if (feedDatabaseManager.doesStreamExist(item)) { it.uploadDate != null &&
return count // Streams older than this date are automatically removed from the feed.
} else { // Therefore, streams which are not in the database,
count++ // but older than this date, are considered old.
it.uploadDate!!.offsetDateTime().isAfter(
FeedDatabaseManager.FEED_OLDEST_ALLOWED_DATE
)
} }
} }
return 0
}
} }
companion object { companion object {

View File

@ -11,14 +11,17 @@ data class FeedUpdateInfo(
val notificationMode: Int, val notificationMode: Int,
val name: String, val name: String,
val avatarUrl: 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, uid = subscription.uid,
notificationMode = subscription.notificationMode, notificationMode = subscription.notificationMode,
name = subscription.name, name = subscription.name,
avatarUrl = subscription.avatarUrl, avatarUrl = subscription.avatarUrl,
listInfo = listInfo listInfo = listInfo,
) )
/** /**
@ -27,8 +30,5 @@ data class FeedUpdateInfo(
val pseudoId: Int val pseudoId: Int
get() = listInfo.url.hashCode() get() = listInfo.url.hashCode()
var newStreamsCount: Int = 0 lateinit var newStreams: List<StreamInfoItem>
val newStreams: List<StreamInfoItem>
get() = listInfo.relatedItems.take(newStreamsCount)
} }