From b8ff66197e789af7aead1e2a332ad00f0b6a3c95 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 6 Dec 2022 22:42:31 +0100 Subject: [PATCH] =?utf8?q?=E2=99=BB=EF=B8=8F=20Use=20new=20filter=20class?= =?utf8?q?=20instead=20of=20filtering=20inline?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../sone/freenet/wot/IdentityManagerImpl.kt | 25 ++-------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/src/main/kotlin/net/pterodactylus/sone/freenet/wot/IdentityManagerImpl.kt b/src/main/kotlin/net/pterodactylus/sone/freenet/wot/IdentityManagerImpl.kt index 829affc..eac1fa9 100644 --- a/src/main/kotlin/net/pterodactylus/sone/freenet/wot/IdentityManagerImpl.kt +++ b/src/main/kotlin/net/pterodactylus/sone/freenet/wot/IdentityManagerImpl.kt @@ -49,6 +49,7 @@ class IdentityManagerImpl @Inject constructor( private val currentOwnIdentities = mutableSetOf() private val strictFiltering = AtomicBoolean(false) + private val noNegativeIdentityFilter = NoNegativeIdentityFilter() override val isConnected: Boolean get() = notThrowing { webOfTrustConnector.ping() } @@ -87,22 +88,7 @@ class IdentityManagerImpl @Inject constructor( private fun Map>.applyStrictFiltering() = if (strictFiltering.get()) { - val identitiesWithTrust = values.flatten() - .groupBy { it.id } - .mapValues { (_, identities) -> - identities.reduce { accIdentity, identity -> - identity.trust.forEach { (ownIdentity: OwnIdentity?, trust: Trust?) -> - accIdentity.setTrust(ownIdentity, trust) - } - accIdentity - } - } - - mapValues { (_, trustedIdentities) -> - trustedIdentities.filter { trustedIdentity -> - identitiesWithTrust[trustedIdentity.id]!!.trust.all { it.value.hasZeroOrPositiveTrust() } - } - } + noNegativeIdentityFilter.filter(this) } else { this } @@ -128,10 +114,3 @@ private fun notThrowing(action: () -> Unit): Boolean = } catch (e: Exception) { false } - -private fun Trust.hasZeroOrPositiveTrust() = - if (explicit == null) { - implicit == null || implicit >= 0 - } else { - explicit >= 0 - } -- 2.7.4