From 90859947ac40748b788e5dc023ba7f054398e80d Mon Sep 17 00:00:00 2001 From: Ash Date: Mon, 18 Mar 2024 16:49:09 +0800 Subject: [PATCH] fix(rss): ignore starred articles by default when clean feed or group (#652) --- .../java/me/ash/reader/domain/repository/ArticleDao.kt | 6 ++++-- .../ash/reader/domain/service/AbstractRssRepository.kt | 10 +++++----- .../infrastructure/rss/provider/fever/FeverAPI.kt | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/me/ash/reader/domain/repository/ArticleDao.kt b/app/src/main/java/me/ash/reader/domain/repository/ArticleDao.kt index eb7541b..ce20601 100644 --- a/app/src/main/java/me/ash/reader/domain/repository/ArticleDao.kt +++ b/app/src/main/java/me/ash/reader/domain/repository/ArticleDao.kt @@ -370,9 +370,10 @@ interface ArticleDao { DELETE FROM article WHERE accountId = :accountId AND feedId = :feedId + AND (isStarred = :includeStarred OR :includeStarred = 1) """ ) - suspend fun deleteByFeedId(accountId: Int, feedId: String) + suspend fun deleteByFeedId(accountId: Int, feedId: String, includeStarred: Boolean = false) @Query( """ @@ -383,10 +384,11 @@ interface ArticleDao { AND a.feedId = b.id AND b.groupId = c.id AND c.id = :groupId + AND (a.isStarred = :includeStarred OR :includeStarred = 1) ) """ ) - suspend fun deleteByGroupId(accountId: Int, groupId: String) + suspend fun deleteByGroupId(accountId: Int, groupId: String, includeStarred: Boolean = false) @Query( """ diff --git a/app/src/main/java/me/ash/reader/domain/service/AbstractRssRepository.kt b/app/src/main/java/me/ash/reader/domain/service/AbstractRssRepository.kt index 2dd209a..906c5bc 100644 --- a/app/src/main/java/me/ash/reader/domain/service/AbstractRssRepository.kt +++ b/app/src/main/java/me/ash/reader/domain/service/AbstractRssRepository.kt @@ -334,7 +334,7 @@ abstract class AbstractRssRepository( ) { return } - deleteArticles(group = group) + deleteArticles(group = group, includeStarred = true) feedDao.deleteByGroupId(accountId, group.id) groupDao.delete(group) } @@ -345,14 +345,14 @@ abstract class AbstractRssRepository( ) { return } - deleteArticles(feed = feed) + deleteArticles(feed = feed, includeStarred = true) feedDao.delete(feed) } - suspend fun deleteArticles(group: Group? = null, feed: Feed? = null) { + suspend fun deleteArticles(group: Group? = null, feed: Feed? = null, includeStarred: Boolean = false) { when { - group != null -> articleDao.deleteByGroupId(context.currentAccountId, group.id) - feed != null -> articleDao.deleteByFeedId(context.currentAccountId, feed.id) + group != null -> articleDao.deleteByGroupId(context.currentAccountId, group.id, includeStarred) + feed != null -> articleDao.deleteByFeedId(context.currentAccountId, feed.id, includeStarred) } } diff --git a/app/src/main/java/me/ash/reader/infrastructure/rss/provider/fever/FeverAPI.kt b/app/src/main/java/me/ash/reader/infrastructure/rss/provider/fever/FeverAPI.kt index 0c31265..32388e7 100644 --- a/app/src/main/java/me/ash/reader/infrastructure/rss/provider/fever/FeverAPI.kt +++ b/app/src/main/java/me/ash/reader/infrastructure/rss/provider/fever/FeverAPI.kt @@ -83,14 +83,14 @@ class FeverAPI private constructor( postRequest("saved_item_ids").apply { checkAuth(auth) } suspend fun markItem(status: FeverDTO.StatusEnum, id: String): FeverDTO.Common = - postRequest("&mark=item&as=${status.value}&id=$id").apply { checkAuth(auth) } + postRequest("mark=item&as=${status.value}&id=$id").apply { checkAuth(auth) } private suspend fun markFeedOrGroup( act: String, status: FeverDTO.StatusEnum, id: Long, before: Long, - ): FeverDTO.Common = postRequest("&mark=$act&as=${status.value}&id=$id&before=$before") + ): FeverDTO.Common = postRequest("mark=$act&as=${status.value}&id=$id&before=$before") .apply { checkAuth(auth) } suspend fun markGroup(status: FeverDTO.StatusEnum, id: Long, before: Long) =