Skip to content

Commit 8ce996e

Browse files
committed
Only check for new streams of subscriptions with enabled notifications automatically
1 parent 892a1df commit 8ce996e

4 files changed

Lines changed: 43 additions & 7 deletions

File tree

app/src/main/java/org/schabi/newpipe/database/feed/dao/FeedDAO.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import org.schabi.newpipe.database.feed.model.FeedEntity
1212
import org.schabi.newpipe.database.feed.model.FeedLastUpdatedEntity
1313
import org.schabi.newpipe.database.stream.StreamWithState
1414
import org.schabi.newpipe.database.stream.model.StreamStateEntity
15+
import org.schabi.newpipe.database.subscription.NotificationMode
1516
import org.schabi.newpipe.database.subscription.SubscriptionEntity
1617
import java.time.OffsetDateTime
1718

@@ -252,4 +253,21 @@ abstract class FeedDAO {
252253
"""
253254
)
254255
abstract fun getAllOutdatedForGroup(groupId: Long, outdatedThreshold: OffsetDateTime): Flowable<List<SubscriptionEntity>>
256+
257+
@Query(
258+
"""
259+
SELECT s.* FROM subscriptions s
260+
261+
LEFT JOIN feed_last_updated lu
262+
ON s.uid = lu.subscription_id
263+
264+
WHERE
265+
(lu.last_updated IS NULL OR lu.last_updated < :outdatedThreshold)
266+
AND s.notification_mode = :notificationMode
267+
"""
268+
)
269+
abstract fun getOutdatedWithNotificationMode(
270+
outdatedThreshold: OffsetDateTime,
271+
@NotificationMode notificationMode: Int
272+
): Flowable<List<SubscriptionEntity>>
255273
}

app/src/main/java/org/schabi/newpipe/local/feed/FeedDatabaseManager.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import org.schabi.newpipe.database.feed.model.FeedGroupEntity
1414
import org.schabi.newpipe.database.feed.model.FeedLastUpdatedEntity
1515
import org.schabi.newpipe.database.stream.StreamWithState
1616
import org.schabi.newpipe.database.stream.model.StreamEntity
17+
import org.schabi.newpipe.database.subscription.NotificationMode
1718
import org.schabi.newpipe.extractor.stream.StreamInfoItem
1819
import org.schabi.newpipe.extractor.stream.StreamType
1920
import org.schabi.newpipe.local.subscription.FeedGroupIcon
@@ -57,6 +58,11 @@ class FeedDatabaseManager(context: Context) {
5758

5859
fun outdatedSubscriptions(outdatedThreshold: OffsetDateTime) = feedTable.getAllOutdated(outdatedThreshold)
5960

61+
fun outdatedSubscriptionsWithNotificationMode(
62+
outdatedThreshold: OffsetDateTime,
63+
@NotificationMode notificationMode: Int
64+
) = feedTable.getOutdatedWithNotificationMode(outdatedThreshold, notificationMode)
65+
6066
fun notLoadedCount(groupId: Long = FeedGroupEntity.GROUP_ALL_ID): Flowable<Long> {
6167
return when (groupId) {
6268
FeedGroupEntity.GROUP_ALL_ID -> feedTable.notLoadedCount()

app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationWorker.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import androidx.work.rxjava3.RxWorker
1616
import io.reactivex.rxjava3.core.Observable
1717
import io.reactivex.rxjava3.core.Single
1818
import org.schabi.newpipe.R
19-
import org.schabi.newpipe.database.subscription.NotificationMode
2019
import org.schabi.newpipe.local.feed.service.FeedLoadManager
2120
import org.schabi.newpipe.local.feed.service.FeedLoadService
2221
import java.util.concurrent.TimeUnit
@@ -36,12 +35,14 @@ class NotificationWorker(
3635
private val feedLoadManager = FeedLoadManager(appContext)
3736

3837
override fun createWork(): Single<Result> = if (isEnabled(applicationContext)) {
39-
feedLoadManager.startLoading(ignoreOutdatedThreshold = true)
38+
feedLoadManager.startLoading(
39+
ignoreOutdatedThreshold = true,
40+
groupId = FeedLoadManager.GROUP_NOTIFICATION_ENABLED
41+
)
4042
.map { feed ->
4143
feed.mapNotNull { x ->
4244
x.value?.takeIf {
43-
it.notificationMode == NotificationMode.ENABLED &&
44-
it.newStreamsCount > 0
45+
it.newStreamsCount > 0
4546
}
4647
}
4748
}

app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadManager.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import io.reactivex.rxjava3.processors.PublishProcessor
1212
import io.reactivex.rxjava3.schedulers.Schedulers
1313
import org.schabi.newpipe.R
1414
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
15+
import org.schabi.newpipe.database.subscription.NotificationMode
1516
import org.schabi.newpipe.extractor.ListInfo
1617
import org.schabi.newpipe.extractor.stream.StreamInfoItem
1718
import org.schabi.newpipe.local.feed.FeedDatabaseManager
@@ -41,6 +42,8 @@ class FeedLoadManager(private val context: Context) {
4142
* Start checking for new streams of a subscription group.
4243
* @param groupId The ID of the subscription group to load.
4344
* When using [FeedGroupEntity.GROUP_ALL_ID], all subscriptions are loaded.
45+
* When using [GROUP_NOTIFICATION_ENABLED], only subscriptions with enabled notifications
46+
* for new streams are loaded.
4447
* @param ignoreOutdatedThreshold When `false`, only subscriptions which have not been updated
4548
* within the `feed_update_threshold` are checked for updates.
4649
* This threshold can be set by the user in the app settings.
@@ -73,6 +76,9 @@ class FeedLoadManager(private val context: Context) {
7376
*/
7477
val outdatedSubscriptions = when (groupId) {
7578
FeedGroupEntity.GROUP_ALL_ID -> feedDatabaseManager.outdatedSubscriptions(outdatedThreshold)
79+
GROUP_NOTIFICATION_ENABLED -> feedDatabaseManager.outdatedSubscriptionsWithNotificationMode(
80+
outdatedThreshold, NotificationMode.ENABLED
81+
)
7682
else -> feedDatabaseManager.outdatedSubscriptionsForGroup(groupId, outdatedThreshold)
7783
}
7884

@@ -248,16 +254,21 @@ class FeedLoadManager(private val context: Context) {
248254
}
249255
}
250256

251-
private companion object {
257+
companion object {
258+
259+
/**
260+
*
261+
*/
262+
const val GROUP_NOTIFICATION_ENABLED = -2L
252263

253264
/**
254265
* How many extractions will be running in parallel.
255266
*/
256-
const val PARALLEL_EXTRACTIONS = 6
267+
private const val PARALLEL_EXTRACTIONS = 6
257268

258269
/**
259270
* Number of items to buffer to mass-insert in the database.
260271
*/
261-
const val BUFFER_COUNT_BEFORE_INSERT = 20
272+
private const val BUFFER_COUNT_BEFORE_INSERT = 20
262273
}
263274
}

0 commit comments

Comments
 (0)