Skip to content

Commit

Permalink
fix(fever): resolve issue with orphaned articles during sync (#534)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashinch committed Jan 18, 2024
1 parent 2b43ce2 commit f6fd923
Showing 1 changed file with 21 additions and 11 deletions.
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

0 comments on commit f6fd923

Please sign in to comment.