]> uap-core.de Git - rssreader.git/commitdiff
fix url merge in updateFeedCollection, update sourcelist after feed update
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 8 Dec 2025 14:33:11 +0000 (15:33 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 8 Dec 2025 14:33:11 +0000 (15:33 +0100)
rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/FeedConfig.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt

index 7defdf65d3ceeab26b62c4c78f6f41d42fdbb42a..51415c1d36dc7c8b4ed1c9aba4d43ee64f247ec1 100644 (file)
@@ -307,28 +307,66 @@ object Database {
                 stmt.execute()
             }
 
-            uris.forEach { uri ->
-                // disable all feeds first and then re-activate all feeds from the uri list
-                conn.prepareStatement("update feeds set disabled = TRUE where feedcollection_id = ?").use { stmt ->
+            var updateList = true
+            // check if the old and new list only contain a single uri
+            if(uris.size == 1) {
+                conn.prepareStatement("select count(*) from feeds where feedcollection_id = ? and disabled = FALSE").use { stmt ->
                     stmt.setInt(1, feed.id)
+                    stmt.executeQuery().use { rs ->
+                        if(rs.next() && rs.getInt(1) == 1) {
+                            updateList = false
+                        }
+                    }
+                }
+            }
+
+            if(updateList) {
+                // disable all feeds first and then re-activate all feeds from the uri list
+                conn.prepareStatement("""
+                    update feeds set auth_user = ?, auth_password = ?, certpath = ?, disabled = TRUE
+                    where feedcollection_id = ?
+                """.trimIndent()).use { stmt ->
+                    stmt.setString(1, user)
+                    stmt.setString(2, password)
+                    stmt.setString(3, cert)
+                    stmt.setInt(4, feed.id)
                     stmt.execute()
                 }
 
+                // merge url list
+                uris.forEach { uri ->
+                    conn.prepareStatement("""
+                        merge into feeds f
+                        using (select cast(? as int) as feedcollection_id, cast(? as varchar) as url) v
+                        on (f.feedcollection_id = v.feedcollection_id and f.url = v.url)
+                        when matched then update set
+                            f.disabled = false
+                        when not matched then insert(feedcollection_id, url, auth_user, auth_password, certpath)
+                        values (v.feedcollection_id, v.url, ?, ?, ?)
+                    """.trimMargin()).use { stmt ->
+                        stmt.setInt(1, feed.id)
+                        stmt.setString(2, uri)
+                        stmt.setString(3, user)
+                        stmt.setString(4, password)
+                        stmt.setString(5, cert)
+                        stmt.execute()
+                    }
+                }
+            } else {
+                // just update the single feed
                 conn.prepareStatement("""
                     update feeds set
                         url = ?,
                         auth_user = ?,
                         auth_password = ?,
-                        certpath = ?,
-                        disabled = FALSE
-                    where feedcollection_id = ? and url = ?
-                """.trimMargin()).use { stmt ->
-                    stmt.setString(1, uri)
+                        certpath = ?
+                    where feedcollection_id = ?
+                """.trimIndent()).use { stmt ->
+                    stmt.setString(1, uris.first())
                     stmt.setString(2, user)
                     stmt.setString(3, password)
                     stmt.setString(4, cert)
                     stmt.setInt(5, feed.id)
-                    stmt.setString(6, uri)
                     stmt.execute()
                 }
             }
index 538206cdefde00d0aa9efb876cdf0bdbeed5593b..90df0dcc5bee449a8aec287493986ad82efc2a6a 100644 (file)
@@ -208,6 +208,15 @@ class FeedConfig(toplevel: Toplevel) {
             itemStateMode = 0
         }
         println("groupSel: ${groups.selectedIndex}, feedName: $feedName, urlStr: $urlStr")
+        var u:String? = user.toString()
+        var p:String? = password.toString()
+
+        if(u?.isEmpty() == true) {
+            u = null
+        }
+        if(p?.isEmpty() == true) {
+            p = null
+        }
         parent?.let {
             FeedConfig.PreviousGroup = it
             try {
@@ -215,9 +224,9 @@ class FeedConfig(toplevel: Toplevel) {
                     parent = it,
                     name = feedName,
                     uris = uris,
-                    user = user.toString(),
-                    password = password.toString(),
-                    cert = cert.toString(),
+                    user = u,
+                    password = p,
+                    cert = null, //cert.toString(),
                     internalBrowser = internalBrowser,
                     updateInterval = updateIntv,
                     maxItemAge = maxItemAge,
@@ -235,7 +244,6 @@ class FeedConfig(toplevel: Toplevel) {
     }
 
     public fun updateFeed() {
-        val parent = groups.selected
         val feedName = name.toString()
         val urlStr = urls.toString()
         val uris = urlStr.split("\n").map { it.trim() }.filter { it.isNotBlank() }
@@ -258,17 +266,14 @@ class FeedConfig(toplevel: Toplevel) {
             itemStateMode = 0
         }
 
-        var user: String? = null
-        var password: String? = null
-        var cert: String? = null
+        var u:String? = user.toString()
+        var p:String? = password.toString()
 
-        val u = user.toString()
-        val p = password.toString()
-        if(u.isNotBlank()) {
-            user = u
+        if(u?.isEmpty() == true) {
+            u = null
         }
-        if(p.isNotBlank()) {
-            password = p
+        if(p?.isEmpty() == true) {
+            p = null
         }
 
         feedCollection?.let {
@@ -278,7 +283,7 @@ class FeedConfig(toplevel: Toplevel) {
             it.internalBrowser = internalBrowser
             it.maxItemAge = maxItemAge
             try {
-                Database.updateFeedCollection(it, uris, user, password, cert)
+                Database.updateFeedCollection(it, uris, u, p, null)
             } catch (e: Exception) {
                 e.printStackTrace()
             }
index 37a373e70ba619bf6cb904b5eaa2f5b491a09b3f..89e422964f62ea74b57c6cc47256daf156ae0248 100644 (file)
@@ -448,6 +448,7 @@ class MainWindow() {
                     feedConfig?.updateFeed()
                 }
                 ev.`object`.close()
+                //sourceList.updateFeeds()
             },
             ui = null)
         feedConfig = FeedConfig(w)