mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 16:30:31 +05:30
Fix (disable) notifications for already seen videos
This commit is contained in:
parent
de8aa43611
commit
aa21ef28f7
@ -101,7 +101,7 @@ object PreferenceHelper {
|
|||||||
authEditor.putString(PreferenceKeys.USERNAME, newValue).apply()
|
authEditor.putString(PreferenceKeys.USERNAME, newValue).apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setLatestVideoId(videoId: String) {
|
fun setLastSeenVideoId(videoId: String) {
|
||||||
editor.putString(PreferenceKeys.LAST_STREAM_VIDEO_ID, videoId).commit()
|
editor.putString(PreferenceKeys.LAST_STREAM_VIDEO_ID, videoId).commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ class SubscriptionsViewModel : ViewModel() {
|
|||||||
this@SubscriptionsViewModel.videoFeed.postValue(videoFeed)
|
this@SubscriptionsViewModel.videoFeed.postValue(videoFeed)
|
||||||
if (videoFeed.isNotEmpty()) {
|
if (videoFeed.isNotEmpty()) {
|
||||||
// save the last recent video to the prefs for the notification worker
|
// save the last recent video to the prefs for the notification worker
|
||||||
PreferenceHelper.setLatestVideoId(videoFeed[0].url!!.toID())
|
PreferenceHelper.setLastSeenVideoId(videoFeed[0].url!!.toID())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,24 +84,24 @@ class NotificationWorker(appContext: Context, parameters: WorkerParameters) :
|
|||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
return false
|
return false
|
||||||
}.filter {
|
|
||||||
PreferenceHelper.getBoolean(PreferenceKeys.SHORTS_NOTIFICATIONS, false) || !it.isShort
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val lastSeenStreamId = PreferenceHelper.getLastSeenVideoId()
|
val lastUserSeenVideoId = PreferenceHelper.getLastSeenVideoId()
|
||||||
val latestFeedStreamId = videoFeed.firstOrNull()?.url?.toID() ?: return true
|
val mostRecentStreamId = videoFeed.firstOrNull()?.url?.toID() ?: return true
|
||||||
|
// save the latest streams that got notified about
|
||||||
|
PreferenceHelper.setLastSeenVideoId(mostRecentStreamId)
|
||||||
|
|
||||||
// first time notifications are enabled or no new video available
|
// first time notifications are enabled or no new video available
|
||||||
if (lastSeenStreamId.isEmpty() || lastSeenStreamId == latestFeedStreamId) {
|
if (lastUserSeenVideoId.isEmpty() || lastUserSeenVideoId == mostRecentStreamId) return true
|
||||||
PreferenceHelper.setLatestVideoId(lastSeenStreamId)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
val channelsToIgnore = PreferenceHelper.getIgnorableNotificationChannels()
|
val channelsToIgnore = PreferenceHelper.getIgnorableNotificationChannels()
|
||||||
|
val enableShortsNotification = PreferenceHelper.getBoolean(PreferenceKeys.SHORTS_NOTIFICATIONS, false)
|
||||||
|
|
||||||
val channelGroups = videoFeed.asSequence()
|
val channelGroups = videoFeed.asSequence()
|
||||||
// filter the new videos until the last seen video in the feed
|
// filter the new videos until the last seen video in the feed
|
||||||
.takeWhile { it.url!!.toID() != lastSeenStreamId }
|
.takeWhile { it.url!!.toID() != lastUserSeenVideoId }
|
||||||
|
// don't show notifications for shorts videos if not enabled
|
||||||
|
.filter { enableShortsNotification || !it.isShort }
|
||||||
// hide for notifications unsubscribed channels
|
// hide for notifications unsubscribed channels
|
||||||
.filter { it.uploaderUrl!!.toID() !in channelsToIgnore }
|
.filter { it.uploaderUrl!!.toID() !in channelsToIgnore }
|
||||||
// group the new streams by the uploader
|
// group the new streams by the uploader
|
||||||
@ -116,8 +116,6 @@ class NotificationWorker(appContext: Context, parameters: WorkerParameters) :
|
|||||||
channelGroups.forEach { (channelId, streams) ->
|
channelGroups.forEach { (channelId, streams) ->
|
||||||
createNotificationsForChannel(channelId, streams)
|
createNotificationsForChannel(channelId, streams)
|
||||||
}
|
}
|
||||||
// save the latest streams that got notified about
|
|
||||||
PreferenceHelper.setLatestVideoId(videoFeed.first().url!!.toID())
|
|
||||||
// return whether the work succeeded
|
// return whether the work succeeded
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user