|
|
@ -63,10 +63,12 @@ class OfflineFirstNewsRepository @Inject constructor(
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.map { it.map(PopulatedNewsResource::asExternalModel) }
|
|
|
|
.map { it.map(PopulatedNewsResource::asExternalModel) }
|
|
|
|
|
|
|
|
|
|
|
|
override suspend fun syncWith(synchronizer: Synchronizer) =
|
|
|
|
override suspend fun syncWith(synchronizer: Synchronizer): Boolean {
|
|
|
|
synchronizer.changeListSync(
|
|
|
|
var isFirstSync = false
|
|
|
|
|
|
|
|
return synchronizer.changeListSync(
|
|
|
|
versionReader = ChangeListVersions::newsResourceVersion,
|
|
|
|
versionReader = ChangeListVersions::newsResourceVersion,
|
|
|
|
changeListFetcher = { currentVersion ->
|
|
|
|
changeListFetcher = { currentVersion ->
|
|
|
|
|
|
|
|
isFirstSync = currentVersion <= 0
|
|
|
|
network.getNewsResourceChangeList(after = currentVersion)
|
|
|
|
network.getNewsResourceChangeList(after = currentVersion)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
versionUpdater = { latestVersion ->
|
|
|
|
versionUpdater = { latestVersion ->
|
|
|
@ -94,6 +96,12 @@ class OfflineFirstNewsRepository @Inject constructor(
|
|
|
|
else -> emptySet()
|
|
|
|
else -> emptySet()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isFirstSync) {
|
|
|
|
|
|
|
|
// When we first retrieve news, mark everything viewed, so that we aren't
|
|
|
|
|
|
|
|
// overwhelmed with all historical news.
|
|
|
|
|
|
|
|
niaPreferencesDataSource.setNewsResourcesViewed(changedIds, true)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Obtain the news resources which have changed from the network and upsert them locally
|
|
|
|
// Obtain the news resources which have changed from the network and upsert them locally
|
|
|
|
changedIds.chunked(SYNC_BATCH_SIZE).forEach { chunkedIds ->
|
|
|
|
changedIds.chunked(SYNC_BATCH_SIZE).forEach { chunkedIds ->
|
|
|
|
val networkNewsResources = network.getNewsResources(ids = chunkedIds)
|
|
|
|
val networkNewsResources = network.getNewsResources(ids = chunkedIds)
|
|
|
@ -137,4 +145,5 @@ class OfflineFirstNewsRepository @Inject constructor(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|