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

fix(fever): resolve issue with orphaned articles during sync #534

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 21 additions & 11 deletions app/src/main/java/me/ash/reader/domain/service/FeverRssService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ class FeverRssService @Inject constructor(
* used as the starting mark for the next pull until the number of articles
* obtained is 0 or their quantity exceeds 250, at which point the pulling process stops.
*
* 1. Fetch the Fever groups
* 2. Fetch the Fever feeds (including favicons)
* 1. Fetch the Fever groups (may need to remove orphaned groups)
* 2. Fetch the Fever feeds (including favicons, may need to remove orphaned feeds)
* 3. Fetch the Fever articles
* 4. Synchronize read/unread and starred/un-starred items
*/
Expand All @@ -106,15 +106,20 @@ class FeverRssService @Inject constructor(
val feverAPI = getFeverAPI()

// 1. Fetch the Fever groups
groupDao.insertOrUpdate(
feverAPI.getGroups().groups?.map {
Group(
id = accountId.spacerDollar(it.id!!),
name = it.title ?: context.getString(R.string.empty),
accountId = accountId,
)
} ?: emptyList()
)
val groups = feverAPI.getGroups().groups?.map {
Group(
id = accountId.spacerDollar(it.id!!),
name = it.title ?: context.getString(R.string.empty),
accountId = accountId,
)
} ?: emptyList()
groupDao.insertOrUpdate(groups)
val groupIds = groups.map { it.id }
groupDao.queryAll(accountId).forEach {
if (!groupIds.contains(it.id)) {
super.deleteGroup(it)
}
}

// 2. Fetch the Fever feeds
val feedsBody = feverAPI.getFeeds()
Expand All @@ -126,6 +131,11 @@ class FeverRssService @Inject constructor(
}
}
}
feedDao.queryAll(accountId).forEach {
if (!feedsGroupsMap.contains(it.id.dollarLast())) {
super.deleteFeed(it)
}
}

// Fetch the Fever favicons
val faviconsById = feverAPI.getFavicons().favicons?.associateBy { it.id } ?: emptyMap()
Expand Down