+ private fun Map<OwnIdentity, Set<Identity>>.mergeRemoteIdentities() =
+ values.flatten()
+ .groupBy { it.id }
+ .mapValues {
+ it.value.reduce { accIdentity, identity ->
+ identity.trust.forEach { (ownIdentity, trust) -> accIdentity.setTrust(ownIdentity, trust) }
+ accIdentity
+ }
+ }
+ .let { reducedIdentities ->
+ mapValues { it.value.map { identity -> reducedIdentities[identity.id]!! }.toSet() }
+ }
+