From d4ec0f2c78e8f6c89a4d26e02d514e31cc43243a Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Sat, 29 Nov 2025 17:06:31 +0100 Subject: [PATCH] correctly update read status when a feedgroup is selected --- .../main/kotlin/de/unixwork/rssreader/App.kt | 24 ++++++++++++++----- .../kotlin/de/unixwork/rssreader/Database.kt | 15 ++++++++++++ .../de/unixwork/rssreader/MainWindow.kt | 10 ++++++-- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/App.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/App.kt index 1d7790d..e7f4b09 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/App.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/App.kt @@ -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) - } } } diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt index 3ea05e9..30debd9 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt @@ -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(""" diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt index a9abfe1..7d090f7 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt @@ -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() + } } } -- 2.47.3