feat: start to implement group list info classes and wrappers and refactor to use library based hashes

This commit is contained in:
0x330a
2023-02-27 17:31:40 +11:00
parent c06c7eab19
commit c351cd6038
9 changed files with 142 additions and 38 deletions

View File

@@ -73,7 +73,7 @@ data class ConfigurationSyncJob(val destination: Destination): Job {
}
val toDeleteRequest = configsRequiringPush.map { base ->
configFactory.getHashesFor(base)
base.obsoleteHashes()
// accumulate by adding together
}.reduce(List<String>::plus).let { toDeleteFromAllNamespaces ->
if (toDeleteFromAllNamespaces.isEmpty()) null
@@ -137,11 +137,9 @@ data class ConfigurationSyncJob(val destination: Destination): Job {
// confirm pushed seqno
val thisSeqNo = toPushMessage.seqNo
config.confirmPushed(thisSeqNo, insertHash)
config.
// wipe any of the existing hashes which we deleted (they may or may not be in this namespace)
if (configFactory.removeHashesFor(config, deletedHashes.toSet())) {
Log.d(TAG, "Successfully removed the deleted hashes from ${config.javaClass.simpleName}")
}
config.removeObsoleteHashes(deletedHashes.toTypedArray())
Log.d(TAG, "Successfully removed the deleted hashes from ${config.javaClass.simpleName}")
// dump and write config after successful
if (config.needsDump()) { // usually this will be true?
configFactory.persist(config)

View File

@@ -137,7 +137,7 @@ class Poller(private val configFactory: ConfigFactoryProtocol, debounceTimer: Ti
namespace,
updateLatestHash = false,
updateStoredHashes = false,
).filter { (_, hash) -> !configFactory.getHashesFor(forConfigObject).contains(hash) }
).filter { (_, hash) -> !forConfigObject.obsoleteHashes().contains(hash) }
if (messages.isEmpty()) {
// no new messages to process
@@ -153,8 +153,7 @@ class Poller(private val configFactory: ConfigFactoryProtocol, debounceTimer: Ti
return@forEach
}
Log.d("Loki-DBG", "Merging config of kind ${message.kind} into ${forConfigObject.javaClass.simpleName}")
forConfigObject.merge(message.data)
configFactory.appendHash(forConfigObject, hash!!)
forConfigObject.merge(hash!! to message.data)
} catch (e: Exception) {
Log.e("Loki", e)
}

View File

@@ -10,9 +10,6 @@ interface ConfigFactoryProtocol {
val contacts: Contacts?
val convoVolatile: ConversationVolatileConfig?
fun persist(forConfigObject: ConfigBase)
fun appendHash(configObject: ConfigBase, hash: String)
fun getHashesFor(forConfigObject: ConfigBase): List<String>
fun removeHashesFor(config: ConfigBase, deletedHashes: Set<String>): Boolean
}
interface ConfigFactoryUpdateListener {