]> uap-core.de Git - rssreader.git/commitdiff
don't insert items when they are older than the max item age
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 31 May 2026 10:48:29 +0000 (12:48 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 31 May 2026 10:48:29 +0000 (12:48 +0200)
rss-application/src/main/kotlin/de/unixwork/rssreader/App.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/SyncJob.kt

index 6b0bb0415dce8aa625e74e49369c121f8894e4b7..de021aaf0e097c3fce75ac321f5250007af0d43b 100644 (file)
@@ -31,14 +31,14 @@ object App : Application {
     }
 
     fun syncAll() {
-        SyncJob({ Database.getAllFeeds()}).sync() {
+        SyncJob(settings, { Database.getAllFeeds()}).sync() {
             window?.reload()
         }
     }
 
     fun syncCurrent() {
         window?.feedList?.currentFeed?.let {
-            SyncJob({ Database.getFeed(it.id)?.let { mutableListOf(it)} ?: mutableListOf() }).sync() {
+            SyncJob(settings, { Database.getFeed(it.id)?.let { mutableListOf(it)} ?: mutableListOf() }).sync() {
                 window?.reload()
             }
         }
@@ -246,7 +246,7 @@ object App : Application {
                 try {
                     val pending = Database.getPendingFeeds(settings.defaultRefreshInterval)
                     if(!pending.isEmpty()) {
-                        SyncJob { pending }.syncBlocking()
+                        SyncJob(settings, { pending }).syncBlocking()
                         GlobalScope.launch(ToolkitDispatcher) {
                             window!!.sourceList.invalidateCache()
                             window!!.sourceList.reloadStatus()
index d1b0087d5ea65f93c0b11affbc2fb7d8e81a9e8a..ade37050bc56407d0a7472073287267081810b2f 100644 (file)
@@ -352,10 +352,12 @@ object Database {
                         val id = rs.getInt("feed_id")
                         val name = rs.getString("name")
                         val url = rs.getString("url")
+                        val maxItemAge = rs.getInt("max_item_age")
                         val authUser = rs.getString("auth_user")
                         val authPassword = rs.getString("auth_password")
                         val certPath = rs.getString("certpath")
                         val feed = Feed(id, name, url)
+                        feed.maxItemAge = maxItemAge
                         feed.user = authUser
                         feed.password = authPassword
                         feed.certpath = certPath
@@ -381,10 +383,12 @@ object Database {
                         val id = rs.getInt("feed_id")
                         val name = rs.getString("name")
                         val url = rs.getString("url")
+                        val maxItemAge = rs.getInt("max_item_age")
                         val authUser = rs.getString("auth_user")
                         val authPassword = rs.getString("auth_password")
                         val certPath = rs.getString("certpath")
                         feed = Feed(id, name, url)
+                        feed.maxItemAge = maxItemAge
                         feed.user = authUser
                         feed.password = authPassword
                         feed.certpath = certPath
@@ -411,6 +415,7 @@ object Database {
                         val id = rs.getInt("feed_id")
                         val name = rs.getString("name")
                         val url = rs.getString("url")
+                        val maxItemAge = rs.getInt("max_item_age")
                         val authUser = rs.getString("auth_user")
                         val authPassword = rs.getString("auth_password")
                         val certPath = rs.getString("certpath")
@@ -418,6 +423,7 @@ object Database {
                         feed.user = authUser
                         feed.password = authPassword
                         feed.certpath = certPath
+                        feed.maxItemAge = maxItemAge
                         feeds.add(feed)
                     }
                 }
index acc616c0760b3d4799b9d96d04a92ab4583ff6bf..60c4f03447797e93873894edcad4f92f4551c327 100644 (file)
@@ -59,7 +59,7 @@ class MainWindow() {
             val evt = event.subListEventData
             val feedIndex = evt.rowIndex
             if(evt.sublistIndex >= 0) {
-                SyncJob({
+                SyncJob(App.settings,{
                     if(feedIndex >= 0) {
                         val feed = Database.getFeed(sourceList.groups[evt.sublistIndex].feeds[feedIndex].id)
                         feed?.let { mutableListOf(it)} ?: mutableListOf()
index 51932fa18fbb501d0cbccf6b0a9d6b21f6611523..62506fe8926143088815986332866d8154144630 100644 (file)
@@ -15,8 +15,11 @@ import java.net.URI
 import java.net.http.HttpClient
 import java.net.http.HttpRequest
 import java.net.http.HttpResponse
+import java.time.Duration
+import java.time.Instant
 
-class SyncJob(feeds: () -> List<Feed>) {
+class SyncJob(settings: Settings, feeds: () -> List<Feed>) {
+    val settings = settings
     val getFeeds: () -> List<Feed> = feeds
     var completionContext = ToolkitDispatcher
 
@@ -65,6 +68,19 @@ class SyncJob(feeds: () -> List<Feed>) {
                                 println("Fetched feed: ${syndFeed.title}")
                                 syndFeed.entries.forEach { entry ->
                                     //println("  ${entry.title} - ${entry.link}")
+                                    if(feed.maxItemAge >= 0) {
+                                        val max_age = if(feed.maxItemAge == 0) settings.maxItemAge else feed.maxItemAge
+                                        if(max_age > 0) {
+                                            val date = entry.updatedDate ?: entry.publishedDate
+                                            date?.let {
+                                                val age = Duration.between(it.toInstant(), Instant.now()).toDays()
+                                                if(age > max_age) {
+                                                    //println("Item too old, skipping: ${entry.title}  date: ${it}")
+                                                    return@forEach
+                                                }
+                                            }
+                                        }
+                                    }
 
                                     val item = Item(0)
                                     item.feedId = feed.id