]> uap-core.de Git - rssreader.git/commitdiff
use item updated date as primary date, use pubDate as fallback
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 30 Aug 2025 08:43:54 +0000 (10:43 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 30 Aug 2025 08:43:54 +0000 (10:43 +0200)
rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/Item.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/SyncJob.kt

index ef3d368b0cf496932e54ec6a0e72419d4b0fc013..543787dd6cb06f931cb9d13b2835a6786a0db7c0 100644 (file)
@@ -80,6 +80,7 @@ object Database {
                         description CLOB,
                         author VARCHAR,
                         pub_date TIMESTAMP,
+                        updated TIMESTAMP,
                         guid VARCHAR UNIQUE,
                         contentText CLOB,
                         contentHTML CLOB,
@@ -227,6 +228,7 @@ object Database {
                     item.description = rs.getString("description")
                     item.author = rs.getString("author")
                     item.pubDate = rs.getObject("pub_date", java.time.LocalDateTime::class.java)
+                    item.updated = rs.getObject("updated", java.time.LocalDateTime::class.java)
                     item.guid = rs.getString("guid")
                     item.contentText = rs.getString("contentText")
                     item.contentHtml = rs.getString("contentHTML")
@@ -270,8 +272,8 @@ object Database {
     public fun addItems(items: Collection<Item>) {
         dataSource.connection.use { conn ->
             conn.prepareStatement("""
-                    insert into items (feed_id, title, link, category, description, author, pub_date, guid, contentText, contentHTML)
-                    select ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
+                    insert into items (feed_id, title, link, category, description, author, pub_date, updated, guid, contentText, contentHTML)
+                    select ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
                     where ? not in (select guid from items) 
                 """.trimIndent()).use { stmt ->
                 items.forEach { item ->
@@ -282,10 +284,11 @@ object Database {
                     stmt.setString(5, item.description)
                     stmt.setString(6, item.author)
                     stmt.setTimestamp(7, item.pubDate?.let { java.sql.Timestamp.valueOf(it) })
-                    stmt.setString(8, item.guid)
-                    stmt.setString(9, item.contentText)
-                    stmt.setString(10, item.contentHtml)
-                    stmt.setString(11, item.guid)
+                    stmt.setTimestamp(8, item.updated?.let { java.sql.Timestamp.valueOf(it) })
+                    stmt.setString(9, item.guid)
+                    stmt.setString(10, item.contentText)
+                    stmt.setString(11, item.contentHtml)
+                    stmt.setString(12, item.guid)
                     stmt.addBatch()
                 }
                 stmt.executeBatch()
index 4f70c484cfc832349b68ddd52017d2cf699f9be2..33758edd524ea0868c812ec8cc03f5533b33528b 100644 (file)
@@ -12,6 +12,7 @@ class Item(id: Int) {
     var description: String? = null
     var author: String? = null
     var pubDate: LocalDateTime? = null
+    var updated: LocalDateTime? = null
     var guid: String? = null
     var contentText: String? = null
     var contentHtml: String? = null
index be8be02389d21519f976be5b3469d822a82f6bcf..3ea9eed3df0539f1f7d79048f9cac1c06fabc17c 100644 (file)
@@ -77,9 +77,7 @@ class MainWindow {
                         var result: String? = null
                         when(col) {
                             0 -> result = elm.title
-                            1 -> {
-                                result = elm.pubDate?.format(formatter)
-                            }
+                            1 -> result = elm.updated?.format(formatter) ?: elm.pubDate?.format(formatter)
                         }
                         result
                     }
index 57e7ee32b19a16b9640e7b3b3a1b4386c3567bd2..35c1fc83f3de0925582fed5047dc62dc8c54f9b4 100644 (file)
@@ -60,6 +60,9 @@ class SyncJob {
                                 entry.publishedDate?.let {
                                     item.pubDate = it.toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDateTime()
                                 }
+                                entry.updatedDate?.let {
+                                    item.updated = it.toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDateTime()
+                                }
                                 item.guid = entry.uri
                                 val contents = entry.contents
                                 contents.forEach { content ->