fix: checking the last read open to message and make sure that scroll behaviour matches expected, fix the config sync job not deleting ALL old hashes only latest

This commit is contained in:
0x330a
2023-05-03 19:26:40 +10:00
parent f7b4fe216f
commit 281b8dac33
2 changed files with 11 additions and 8 deletions

View File

@@ -54,17 +54,12 @@ data class ConfigurationSyncJob(val destination: Destination): Job {
if (configsRequiringPush.isEmpty()) return delegate.handleJobSucceeded(this, dispatcherName)
// need to get the current hashes before we call `push()`
val toDeleteRequest = configsRequiringPush.map { base ->
// accumulate by adding together
base.currentHashes()
}.reduce(List<String>::plus).let { toDeleteFromAllNamespaces ->
if (toDeleteFromAllNamespaces.isEmpty()) null
else SnodeAPI.buildAuthenticatedDeleteBatchInfo(destination.destinationPublicKey(), toDeleteFromAllNamespaces)
}
val toDeleteHashes = mutableListOf<String>()
// allow null results here so the list index matches configsRequiringPush
val batchObjects: List<Pair<SharedConfigurationMessage, SnodeAPI.SnodeBatchRequestInfo>?> = configsRequiringPush.map { config ->
val (data, seqNo) = config.push()
val (data, seqNo, obsoleteHashes) = config.push()
toDeleteHashes += obsoleteHashes
SharedConfigurationMessage(config.protoKindFor(), data, seqNo) to config
}.map { (message, config) ->
// return a list of batch request objects
@@ -77,6 +72,11 @@ data class ConfigurationSyncJob(val destination: Destination): Job {
message to authenticated // to keep track of seqNo for calling confirmPushed later
}
val toDeleteRequest = toDeleteHashes.let { toDeleteFromAllNamespaces ->
if (toDeleteFromAllNamespaces.isEmpty()) null
else SnodeAPI.buildAuthenticatedDeleteBatchInfo(destination.destinationPublicKey(), toDeleteFromAllNamespaces)
}
if (batchObjects.any { it == null }) {
// stop running here, something like a signing error occurred
return delegate.handleJobFailedPermanently(this, dispatcherName, NullPointerException("One or more requests had a null batch request info"))