Log when an OwnIdentity is removed.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / Core.java
index d63b938..20c5884 100644 (file)
@@ -389,7 +389,7 @@ public class Core implements IdentityListener {
        public Set<Sone> getLikes(Reply reply) {
                Set<Sone> sones = new HashSet<Sone>();
                for (Sone sone : getSones()) {
-                       if (sone.getLikedPostIds().contains(reply.getId())) {
+                       if (sone.getLikedReplyIds().contains(reply.getId())) {
                                sones.add(sone);
                        }
                }
@@ -436,10 +436,6 @@ public class Core implements IdentityListener {
                        return null;
                }
                synchronized (localSones) {
-                       if (localSones.containsKey(ownIdentity.getId())) {
-                               logger.log(Level.FINE, "Tried to add known local Sone: %s", ownIdentity);
-                               return localSones.get(ownIdentity.getId());
-                       }
                        final Sone sone;
                        try {
                                sone = getLocalSone(ownIdentity.getId()).setIdentity(ownIdentity).setInsertUri(new FreenetURI(ownIdentity.getInsertUri())).setRequestUri(new FreenetURI(ownIdentity.getRequestUri()));
@@ -490,10 +486,6 @@ public class Core implements IdentityListener {
                }
                synchronized (remoteSones) {
                        final Sone sone = getRemoteSone(identity.getId()).setIdentity(identity);
-                       if (remoteSones.containsKey(identity.getId())) {
-                               logger.log(Level.FINE, "Identity already exists: %s", identity);
-                               return remoteSones.get(identity.getId());
-                       }
                        sone.setRequestUri(getSoneUri(identity.getRequestUri(), identity.getProperty("Sone.LatestEdition")));
                        remoteSones.put(identity.getId(), sone);
                        soneDownloader.addSone(sone);
@@ -572,9 +564,15 @@ public class Core implements IdentityListener {
                                return;
                        }
                        localSones.remove(sone.getId());
-                       soneInserters.remove(sone.getId()).stop();
+                       soneInserters.remove(sone).stop();
                }
                identityManager.removeContext((OwnIdentity) sone.getIdentity(), "Sone");
+               identityManager.removeProperty((OwnIdentity) sone.getIdentity(), "Sone.LatestEdition");
+               try {
+                       configuration.getLongValue("Sone/" + sone.getId() + "/Time").setValue(null);
+               } catch (ConfigurationException ce1) {
+                       logger.log(Level.WARNING, "Could not remove Sone from configuration!", ce1);
+               }
        }
 
        /**
@@ -592,7 +590,11 @@ public class Core implements IdentityListener {
 
                /* load Sone. */
                String sonePrefix = "Sone/" + sone.getId();
-               long soneTime = configuration.getLongValue(sonePrefix + "/Time").getValue((long) 0);
+               Long soneTime = configuration.getLongValue(sonePrefix + "/Time").getValue(null);
+               if (soneTime == null) {
+                       logger.log(Level.INFO, "Could not load Sone because no Sone has been saved.");
+                       return;
+               }
                long soneModificationCounter = configuration.getLongValue(sonePrefix + "/ModificationCounter").getValue((long) 0);
 
                /* load profile. */
@@ -989,7 +991,7 @@ public class Core implements IdentityListener {
         */
        @Override
        public void ownIdentityRemoved(OwnIdentity ownIdentity) {
-               /* TODO */
+               logger.log(Level.FINEST, "Removing OwnIdentity: " + ownIdentity);
        }
 
        /**