Add own identities to list of trusted identities.
[WoTNS.git] / src / main / java / net / pterodactylus / wotns / freenet / wot / IdentityManager.java
index e9107fe..1411ab3 100644 (file)
@@ -28,6 +28,7 @@ import java.util.logging.Logger;
 
 import net.pterodactylus.util.collection.SetBuilder;
 import net.pterodactylus.util.logging.Logging;
+import net.pterodactylus.util.object.Default;
 import net.pterodactylus.util.service.AbstractService;
 import net.pterodactylus.wotns.freenet.plugin.PluginException;
 
@@ -177,7 +178,7 @@ public class IdentityManager extends AbstractService {
                        identities.add(ownIdentity);
                }
                synchronized (syncObject) {
-                       identities.addAll(currentTrustedIdentities.get(ownIdentity));
+                       identities.addAll(Default.forNull(currentTrustedIdentities.get(ownIdentity), Collections.<Identity> emptySet()));
                }
                return identities.get();
        }
@@ -216,6 +217,17 @@ public class IdentityManager extends AbstractService {
                                        for (Identity identity : trustedIdentities) {
                                                identities.put(identity.getId(), identity);
                                        }
+
+                                       /* add own identities, too, as long as the WoT doesn’t do that. */
+                                       for (OwnIdentity additionalOwnIdentity : ownIdentities) {
+                                               if (additionalOwnIdentity == ownIdentity) {
+                                                       continue;
+                                               }
+                                               if ((context != null) && !additionalOwnIdentity.hasContext(context)) {
+                                                       continue;
+                                               }
+                                               identities.put(additionalOwnIdentity.getId(), additionalOwnIdentity);
+                                       }
                                }
                                identitiesLoaded = true;
                        } catch (WebOfTrustException wote1) {