X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffreenet%2Fwot%2FIdentityManager.java;h=065aa47477020bcf0b66a485543003c5e7f6f5b8;hb=284d89c3bfd97ebbd21ad8b39093ee318c125ae3;hp=acd863321840523eb19be2558d339ef038843395;hpb=24b9e199169393b14c13d7bae5ef55ad7e880e2b;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManager.java b/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManager.java index acd8633..065aa47 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManager.java +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManager.java @@ -181,6 +181,7 @@ public class IdentityManager extends AbstractService { Map currentOwnIdentities = new HashMap(); Set ownIdentities = null; + boolean identitiesLoaded = false; try { /* get all identities with the wanted context from WoT. */ ownIdentities = webOfTrustConnector.loadAllOwnIdentities(); @@ -199,12 +200,12 @@ public class IdentityManager extends AbstractService { identities.put(identity.getId(), identity); } } + identitiesLoaded = true; } catch (WebOfTrustException wote1) { logger.log(Level.WARNING, "WoT has disappeared!", wote1); - ownIdentities = null; } - if (ownIdentities != null) { + if (identitiesLoaded) { /* check for changes. */ checkOwnIdentities(currentOwnIdentities); @@ -294,15 +295,17 @@ public class IdentityManager extends AbstractService { /* find removed own identities: */ for (OwnIdentity oldOwnIdentity : currentOwnIdentities.values()) { - if (!newOwnIdentities.containsKey(oldOwnIdentity.getId())) { - identityListenerManager.fireOwnIdentityRemoved(oldOwnIdentity); + OwnIdentity newOwnIdentity = newOwnIdentities.get(oldOwnIdentity.getId()); + if ((newOwnIdentity == null) || ((context != null) && oldOwnIdentity.hasContext(context) && !newOwnIdentity.hasContext(context))) { + identityListenerManager.fireOwnIdentityRemoved(new DefaultOwnIdentity(webOfTrustConnector, oldOwnIdentity)); } } /* find added own identities. */ for (OwnIdentity currentOwnIdentity : newOwnIdentities.values()) { - if (!currentOwnIdentities.containsKey(currentOwnIdentity.getId())) { - identityListenerManager.fireOwnIdentityAdded(currentOwnIdentity); + OwnIdentity oldOwnIdentity = currentOwnIdentities.get(currentOwnIdentity.getId()); + if (((oldOwnIdentity == null) && ((context == null) || currentOwnIdentity.hasContext(context))) || ((oldOwnIdentity != null) && (context != null) && (!oldOwnIdentity.hasContext(context) && currentOwnIdentity.hasContext(context)))) { + identityListenerManager.fireOwnIdentityAdded(new DefaultOwnIdentity(webOfTrustConnector, currentOwnIdentity)); } }