mirror of https://github.com/readrops/Readrops.git
Use separate state when needed to get new items unread count
This commit is contained in:
parent
4382bbb061
commit
d51cf041b8
|
@ -12,7 +12,11 @@ class GetFoldersWithFeeds(
|
||||||
private val database: Database,
|
private val database: Database,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun get(accountId: Int, mainFilter: MainFilter, useSeparateState: Boolean): Flow<Map<Folder?, List<Feed>>> {
|
fun get(
|
||||||
|
accountId: Int,
|
||||||
|
mainFilter: MainFilter,
|
||||||
|
useSeparateState: Boolean
|
||||||
|
): Flow<Map<Folder?, List<Feed>>> {
|
||||||
val query = FeedUnreadCountQueryBuilder.build(accountId, mainFilter, useSeparateState)
|
val query = FeedUnreadCountQueryBuilder.build(accountId, mainFilter, useSeparateState)
|
||||||
|
|
||||||
return combine(
|
return combine(
|
||||||
|
@ -56,4 +60,11 @@ class GetFoldersWithFeeds(
|
||||||
foldersWithFeeds.toSortedMap(nullsLast(Folder::compareTo))
|
foldersWithFeeds.toSortedMap(nullsLast(Folder::compareTo))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getNewItemsUnreadCount(accountId: Int, useSeparateState: Boolean): Flow<Int> =
|
||||||
|
if (useSeparateState) {
|
||||||
|
database.newItemDao().selectUnreadNewItemsCountByItemState(accountId)
|
||||||
|
} else {
|
||||||
|
database.newItemDao().selectUnreadNewItemsCount(accountId)
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -97,12 +97,13 @@ class TimelineScreenModel(
|
||||||
}
|
}
|
||||||
|
|
||||||
screenModelScope.launch(dispatcher) {
|
screenModelScope.launch(dispatcher) {
|
||||||
accountEvent.flatMapConcat { database.newItemDao().selectUnreadNewItemsCount(it.id) }
|
accountEvent.flatMapConcat {
|
||||||
.collectLatest { count ->
|
getFoldersWithFeeds.getNewItemsUnreadCount(it.id, it.config.useSeparateState)
|
||||||
_timelineState.update {
|
}.collectLatest { count ->
|
||||||
it.copy(unreadNewItemsCount = count)
|
_timelineState.update {
|
||||||
}
|
it.copy(unreadNewItemsCount = count)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,10 +51,16 @@ abstract class NewItemDao : NewBaseDao<Item> {
|
||||||
"On Feed.folder_id = Folder.id Where Folder.id = :folderId And Folder.account_id = :accountId)")
|
"On Feed.folder_id = Folder.id Where Folder.id = :folderId And Folder.account_id = :accountId)")
|
||||||
abstract suspend fun setAllItemsReadByFolder(folderId: Int, accountId: Int)
|
abstract suspend fun setAllItemsReadByFolder(folderId: Int, accountId: Int)
|
||||||
|
|
||||||
@Query("Select count(*) From Item Inner Join Feed On Item.feed_id = Feed.id Where read = 0 and account_id = :accountId " +
|
@Query("""Select count(*) From Item Inner Join Feed On Item.feed_id = Feed.id Where read = 0
|
||||||
"And DateTime(Round(Item.pub_date / 1000), 'unixepoch') Between DateTime(DateTime(\"now\"), \"-24 hour\") And DateTime(\"now\")")
|
And account_id = :accountId And DateTime(Round(Item.pub_date / 1000), 'unixepoch')
|
||||||
|
Between DateTime(DateTime("now"), "-24 hour") And DateTime("now")""")
|
||||||
abstract fun selectUnreadNewItemsCount(accountId: Int): Flow<Int>
|
abstract fun selectUnreadNewItemsCount(accountId: Int): Flow<Int>
|
||||||
|
|
||||||
|
@Query("""Select count(*) From ItemState Inner Join Item On Item.remoteId = ItemState.remote_id
|
||||||
|
Where ItemState.read = 0 and account_id = :accountId And DateTime(Round(Item.pub_date / 1000), 'unixepoch')
|
||||||
|
Between DateTime(DateTime("now"), "-24 hour") And DateTime("now")""")
|
||||||
|
abstract fun selectUnreadNewItemsCountByItemState(accountId: Int): Flow<Int>
|
||||||
|
|
||||||
@RawQuery(observedEntities = [Item::class, ItemState::class])
|
@RawQuery(observedEntities = [Item::class, ItemState::class])
|
||||||
abstract fun selectFeedUnreadItemsCount(query: SupportSQLiteQuery):
|
abstract fun selectFeedUnreadItemsCount(query: SupportSQLiteQuery):
|
||||||
Flow<Map<@MapColumn(columnName = "feed_id") Int, @MapColumn(columnName = "item_count") Int>>
|
Flow<Map<@MapColumn(columnName = "feed_id") Int, @MapColumn(columnName = "item_count") Int>>
|
||||||
|
|
|
@ -106,7 +106,7 @@ interface NewItemStateDao : NewBaseDao<ItemState> {
|
||||||
Between DateTime(DateTime("now"), "-24 hour") And DateTime("now"))""")
|
Between DateTime(DateTime("now"), "-24 hour") And DateTime("now"))""")
|
||||||
suspend fun setAllNewItemsReadByUpdate(accountId: Int)
|
suspend fun setAllNewItemsReadByUpdate(accountId: Int)
|
||||||
|
|
||||||
@Query("""Insert Into ItemState(read, starred, remote_id, account_id) Select 1 as read, 0 as starred,
|
@Query("""Insert Or Ignore Into ItemState(read, starred, remote_id, account_id) Select 1 as read, 0 as starred,
|
||||||
Item.remoteId As remote_id, account_id From Item Inner Join Feed On Feed.id = Item.feed_id
|
Item.remoteId As remote_id, account_id From Item Inner Join Feed On Feed.id = Item.feed_id
|
||||||
Where Feed.account_id = :accountId And DateTime(Round(Item.pub_date / 1000), 'unixepoch')
|
Where Feed.account_id = :accountId And DateTime(Round(Item.pub_date / 1000), 'unixepoch')
|
||||||
Between DateTime(DateTime("now"), "-24 hour") And DateTime("now")""")
|
Between DateTime(DateTime("now"), "-24 hour") And DateTime("now")""")
|
||||||
|
|
Loading…
Reference in New Issue