/*
- * Sone - IdentityManagerImpl.java - Copyright © 2010–2019 David Roden
+ * Sone - IdentityManagerImpl.kt - Copyright © 2010–2020 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
while (!shouldStop()) {
try {
- val currentIdentities = identityLoader.loadIdentities()
+ val currentIdentities = identityLoader.loadAllIdentities()
+
+ val identitiesWithTrust = currentIdentities.values.flatten()
+ .groupBy { it.id }
+ .mapValues { (_, identities) ->
+ identities.reduce { accIdentity, identity ->
+ identity.trust.forEach { (ownIdentity: OwnIdentity?, trust: Trust?) ->
+ accIdentity.setTrust(ownIdentity, trust)
+ }
+ accIdentity
+ }
+ }
+
+ val onlyTrustedByAll = currentIdentities.mapValues { (_, trustedIdentities) ->
+ trustedIdentities.filter { trustedIdentity ->
+ identitiesWithTrust[trustedIdentity.id]!!.trust.all { it.value.hasZeroOrPositiveTrust() }
+ }
+ }
+ logger.log(Level.FINE, "Reduced (${currentIdentities.size},(${currentIdentities.values.joinToString { it.size.toString() }})) identities to (${onlyTrustedByAll.size},(${onlyTrustedByAll.values.joinToString { it.size.toString() }})).")
val identityChangeEventSender = IdentityChangeEventSender(eventBus, oldIdentities)
identityChangeEventSender.detectChanges(currentIdentities)
} catch (e: Exception) {
false
}
+
+private fun Trust.hasZeroOrPositiveTrust() =
+ if (explicit == null) {
+ implicit == null || implicit >= 0
+ } else {
+ explicit >= 0
+ }