]> uap-core.de Git - rssreader.git/commitdiff
correctly update read status when a feedgroup is selected
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 29 Nov 2025 16:06:31 +0000 (17:06 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 29 Nov 2025 16:06:31 +0000 (17:06 +0100)
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

index 1d7790d100197b38c9bf87b53938795d083fa51d..e7f4b098894e2724da69995c805b9dd1efecfab0 100644 (file)
@@ -51,15 +51,27 @@ object App : Application {
 
     fun markCurrentFeedAsRead() {
         if(window?.feedList?.currentFeed != null) {
-            window?.feedList?.currentFeed?.unreadItemsCount = 0
-            window?.feedList?.currentFeed?.items?.forEach { item ->
-                item.isRead = true
+            if(window?.feedList?.currentFeed?.isGroup == false) {
+                // normal feedcollection
+                window?.feedList?.currentFeed?.unreadItemsCount = 0
+                window?.feedList?.currentFeed?.items?.forEach { item ->
+                    item.isRead = true
+                }
+                GlobalScope.launch(Dispatchers.IO) {
+                    Database.updateFeedReadState(window?.feedList?.currentFeed!!, true)
+                }
+            } else {
+                // feedgroup
+                window?.feedList?.currentFeed?.items?.forEach { item ->
+                    item.isRead = true
+                    item.collection?.unreadItemsCount = 0
+                }
+                GlobalScope.launch(Dispatchers.IO) {
+                    Database.updateFeedGroupReadState(window?.feedList?.currentFeed!!.id, true)
+                }
             }
             window?.feedList?.items?.update()
             window?.updateCurrentFeedState()
-            GlobalScope.launch(Dispatchers.IO) {
-                Database.updateFeedReadState(window?.feedList?.currentFeed!!, true)
-            }
         }
     }
 
index 3ea05e9ce2950a3b31802e7a7aabe30f9ec495ba..30debd9ee3bcccd81feef45a003fe95013467cf0 100644 (file)
@@ -540,6 +540,21 @@ object Database {
         }
     }
 
+    public fun updateFeedGroupReadState(feedGroupId: Int, read: Boolean) {
+        dataSource.connection.use { conn ->
+            conn.prepareStatement("""
+                update items set is_read = ? where feed_id in (
+                    select feed_id from feeds f
+                    inner join feedcollections c on f.feedcollection_id = c.feedcollection_id 
+                    where group_id = ?)
+            """.trimIndent()).use { stmt ->
+                stmt.setBoolean(1, read)
+                stmt.setInt(2, feedGroupId)
+                stmt.execute()
+            }
+        }
+    }
+
     public fun updateAllItems(read: Boolean) {
         dataSource.connection.use { conn ->
             conn.prepareStatement("""
index a9abfe1fed94fa21c4e609cd4b8be7c4803f0d05..7d090f7f7fe7614c09346c8e4f9bb1462dcc9415 100644 (file)
@@ -347,8 +347,14 @@ class MainWindow() {
     }
 
     fun updateCurrentFeedState() {
-        if(currentFeedIndex >= 0 && currentSublistIndex >= 0) {
-            sourceList.groups[currentSublistIndex].feeds.update(currentFeedIndex)
+        if(currentSublistIndex >= 0) {
+            if(currentFeedIndex >= 0) {
+                // feedcollection selected
+                sourceList.groups[currentSublistIndex].feeds.update(currentFeedIndex)
+            } else {
+                // feedgroup selected
+                sourceList.groups[currentSublistIndex].feeds.update()
+            }
         }
     }