Skip to content

Commit

Permalink
Update: Re-sync source after relevant update.
Browse files Browse the repository at this point in the history
  • Loading branch information
machiav3lli committed Dec 16, 2024
1 parent 7fb2f82 commit 470a84b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ import com.saulhdev.feeder.db.dao.insertOrUpdate
import com.saulhdev.feeder.db.models.Feed
import com.saulhdev.feeder.db.models.FeedArticle
import com.saulhdev.feeder.db.models.FeedItemIdWithLink
import com.saulhdev.feeder.models.scheduleFullTextParse
import com.saulhdev.feeder.sdk.FeedItem
import com.saulhdev.feeder.sync.FeedSyncer
import com.saulhdev.feeder.sync.requestFeedSync
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -73,12 +75,14 @@ class ArticleRepository(context: Context) {
}
}

fun updateFeed(feed: Feed) {
fun updateFeed(feed: Feed, resync: Boolean = false) {
scope.launch {
val list: List<Feed> = feedSourceDao.findFeedById(feed.id)
if (list.isNotEmpty()) {
feed.lastSync = ZonedDateTime.now().toInstant()
feedSourceDao.update(feed)
if (resync) requestFeedSync(feed.id)
if (feed.fullTextByDefault) scheduleFullTextParse()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fun scheduleFullTextParse() {
val workManager: WorkManager by inject(WorkManager::class.java)
workManager.enqueueUniqueWork(
"FullTextWorker",
ExistingWorkPolicy.KEEP,
ExistingWorkPolicy.REPLACE,
workRequest.build()
)
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/saulhdev/feeder/sync/FeedSyncer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ fun requestFeedSync(

workManager.enqueueUniqueWork(
"feeder_sync_onetime_$feedId",
ExistingWorkPolicy.KEEP,
ExistingWorkPolicy.REPLACE,
workRequest.build()
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ class EditFeedViewModel : ViewModel() {

fun updateFeed(state: EditFeedViewState) {
repository.updateFeed(
feed.value.copy(
feed = feed.value.copy(
title = state.title,
url = sloppyLinkToStrictURL(state.url),
fullTextByDefault = state.fullTextByDefault,
isEnabled = state.isEnabled,
)
),
resync = feed.value.fullTextByDefault != state.fullTextByDefault
|| feed.value.isEnabled != state.isEnabled
)
}

Expand Down

0 comments on commit 470a84b

Please sign in to comment.