From: David ‘Bombe’ Roden Date: Tue, 6 Dec 2022 21:42:31 +0000 (+0100) Subject: ♻️ Use new filter class instead of filtering inline X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=b8ff66197e789af7aead1e2a332ad00f0b6a3c95;p=Sone.git ♻️ Use new filter class instead of filtering inline --- 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 - }