Add mark all read items for new articles filter

This commit is contained in:
Shinokuni 2024-03-04 23:10:20 +01:00
parent 5c16ea09de
commit c52f324a13
3 changed files with 18 additions and 9 deletions

View File

@ -73,6 +73,10 @@ abstract class BaseRepository(
database.newItemDao().setAllStarredItemsRead(accountId)
}
open suspend fun setAllNewItemsRead(accountId: Int) {
database.newItemDao().setAllNewItemsRead(accountId)
}
open suspend fun setAllItemsReadByFeed(feedId: Int, accountId: Int) {
database.newItemDao().setAllItemsReadByFeed(feedId, accountId)
}

View File

@ -190,25 +190,25 @@ class TimelineScreenModel(
fun setAllItemsRead() {
screenModelScope.launch(dispatcher) {
val accountId = currentAccount!!.id
when (_timelineState.value.filters.subFilter) {
SubFilter.FEED ->
repository?.setAllItemsReadByFeed(
_timelineState.value.filters.filterFeedId,
currentAccount!!.id
feedId = _timelineState.value.filters.filterFeedId,
accountId = accountId
)
SubFilter.FOLDER -> repository?.setAllItemsReadByFolder(
_timelineState.value.filters.filterFolderId,
currentAccount!!.id
folderId = _timelineState.value.filters.filterFolderId,
accountId = accountId
)
else -> when (_timelineState.value.filters.mainFilter) {
MainFilter.STARS -> repository?.setAllStarredItemsRead(currentAccount!!.id)
MainFilter.ALL -> repository?.setAllItemsRead(currentAccount!!.id)
MainFilter.NEW -> TODO()
MainFilter.STARS -> repository?.setAllStarredItemsRead(accountId)
MainFilter.ALL -> repository?.setAllItemsRead(accountId)
MainFilter.NEW -> repository?.setAllNewItemsRead(accountId)
}
}
}
}

View File

@ -29,6 +29,11 @@ abstract class NewItemDao : NewBaseDao<Item> {
@Query("Update Item set read = 1 Where starred = 1 And feed_id IN (Select id From Feed Where account_id = :accountId)")
abstract suspend fun setAllStarredItemsRead(accountId: Int)
@Query("Update Item set read = 1 Where DateTime(Round(pub_date / 1000), 'unixepoch') " +
"Between DateTime(DateTime(\"now\"), \"-24 hour\") And DateTime(\"now\") " +
"And feed_id IN (Select id From Feed Where account_id = :accountId)")
abstract suspend fun setAllNewItemsRead(accountId: Int)
@Query("Update Item set read = 1 Where feed_id IN " +
"(Select id From Feed Where id = :feedId And account_id = :accountId)")
abstract suspend fun setAllItemsReadByFeed(feedId: Int, accountId: Int)