Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/me/ash/reader/domain/service/FeverRssService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down
Loading