From e68d49e7df33f1ae76a6d2383bbe6a839c2bcce8 Mon Sep 17 00:00:00 2001 From: Stypox Date: Fri, 31 Dec 2021 18:34:02 +0100 Subject: [PATCH] Do not fetch all streams when disabling notifications for a channel --- .../local/subscription/SubscriptionManager.kt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionManager.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionManager.kt index bcd64791e..e4af6e0ac 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionManager.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionManager.kt @@ -75,7 +75,12 @@ class SubscriptionManager(context: Context) { Completable.fromAction { entity.notificationMode = mode subscriptionTable().update(entity) - }.andThen(rememberLastStream(entity)) + }.apply { + if (mode != NotificationMode.DISABLED) { + // notifications have just been enabled, mark all streams as "old" + andThen(rememberAllStreams(entity)) + } + } } } @@ -108,7 +113,12 @@ class SubscriptionManager(context: Context) { subscriptionTable.delete(subscriptionEntity) } - private fun rememberLastStream(subscription: SubscriptionEntity): Completable { + /** + * Fetches the list of videos for the provided channel and saves them in the database, so that + * they will be considered as "old"/"already seen" streams and the user will never notified + * about any one of them. + */ + private fun rememberAllStreams(subscription: SubscriptionEntity): Completable { return ExtractorHelper.getChannelInfo(subscription.serviceId, subscription.url, false) .map { channel -> channel.relatedItems.map { stream -> StreamEntity(stream) } } .flatMapCompletable { entities ->