Skip to content

Commit

Permalink
feat(rss): support batch mark articles as read (#640)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashinch committed Mar 8, 2024
1 parent 7a90aa3 commit df23902
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
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

0 comments on commit df23902

Please sign in to comment.