feat(rss): support batch mark articles as read (#640)

This commit is contained in:
Ash 2024-03-08 18:30:02 +08:00 committed by GitHub
parent 7a90aa3a98
commit df239022e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 35 additions and 2 deletions

View File

@ -161,6 +161,14 @@ abstract class AbstractRssRepository(
}
}
open suspend fun batchMarkAsRead(articleIds: Set<String>, isUnread: Boolean) {
val accountId = context.currentAccountId
articleIds.takeIf { it.isNotEmpty() }?.chunked(500)?.forEachIndexed { index, it ->
Log.d("RLog", "sync markAsRead: ${(index * 500) + it.size}/${articleIds.size} num")
articleDao.markAsReadByIdSet(accountId, it.toSet(), isUnread)
}
}
open suspend fun markAsStarred(articleId: String, isStarred: Boolean) {
val accountId = context.currentAccountId
articleDao.markAsStarredByArticleId(accountId, articleId, isStarred)

View File

@ -323,6 +323,18 @@ class FeverRssService @Inject constructor(
}
}
override suspend fun batchMarkAsRead(articleIds: Set<String>, isUnread: Boolean) {
super.batchMarkAsRead(articleIds, isUnread)
val feverAPI = getFeverAPI()
articleIds.takeIf { it.isNotEmpty() }?.forEachIndexed { index, it ->
Log.d("RLog", "sync markAsRead: ${index}/${articleIds.size} num")
feverAPI.markItem(
status = if (isUnread) FeverDTO.StatusEnum.Unread else FeverDTO.StatusEnum.Read,
id = it.dollarLast(),
)
}
}
override suspend fun markAsStarred(articleId: String, isStarred: Boolean) {
super.markAsStarred(articleId, isStarred)
val feverAPI = getFeverAPI()

View File

@ -476,8 +476,8 @@ class GoogleReaderRssService @Inject constructor(
}
}
super.markAsRead(groupId, feedId, articleId, before, isUnread)
markList.takeIf { it.isNotEmpty() }?.chunked(500)?.forEach {
Log.d("RLog", "sync markAsRead: ${it.size} num")
markList.takeIf { it.isNotEmpty() }?.chunked(500)?.forEachIndexed { index, it ->
Log.d("RLog", "sync markAsRead: ${(index * 500) + it.size}/${markList.size} num")
googleReaderAPI.editTag(
itemIds = it,
mark = if (!isUnread) GoogleReaderAPI.Stream.READ.tag else null,
@ -486,6 +486,19 @@ class GoogleReaderRssService @Inject constructor(
}
}
override suspend fun batchMarkAsRead(articleIds: Set<String>, isUnread: Boolean) {
super.batchMarkAsRead(articleIds, isUnread)
val googleReaderAPI = getGoogleReaderAPI()
articleIds.takeIf { it.isNotEmpty() }?.chunked(500)?.forEachIndexed { index, it ->
Log.d("RLog", "sync markAsRead: ${(index * 500) + it.size}/${articleIds.size} num")
googleReaderAPI.editTag(
itemIds = it.map { it.dollarLast() },
mark = if (!isUnread) GoogleReaderAPI.Stream.READ.tag else null,
unmark = if (isUnread) GoogleReaderAPI.Stream.READ.tag else null,
)
}
}
override suspend fun markAsStarred(articleId: String, isStarred: Boolean) {
super.markAsStarred(articleId, isStarred)
getGoogleReaderAPI().editTag(