Remove Sones do not need to be saved.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / Core.java
index 9f76223..52b885e 100644 (file)
@@ -451,6 +451,15 @@ public class Core implements IdentityListener {
                        soneInserter.start();
                        setSoneStatus(sone, SoneStatus.idle);
                        loadSone(sone);
+                       new Thread(new Runnable() {
+
+                               @Override
+                               @SuppressWarnings("synthetic-access")
+                               public void run() {
+                                       soneDownloader.fetchSone(sone);
+                               }
+
+                       }, "Sone Downloader").start();
                        return sone;
                }
        }
@@ -486,7 +495,8 @@ public class Core implements IdentityListener {
                }
                synchronized (remoteSones) {
                        final Sone sone = getRemoteSone(identity.getId()).setIdentity(identity);
-                       sone.setRequestUri(getSoneUri(identity.getRequestUri(), identity.getProperty("Sone.LatestEdition")));
+                       sone.setRequestUri(getSoneUri(identity.getRequestUri()));
+                       sone.setLatestEdition(Numbers.safeParseLong(identity.getProperty("Sone.LatestEdition"), (long) 0));
                        remoteSones.put(identity.getId(), sone);
                        soneDownloader.addSone(sone);
                        new Thread(new Runnable() {
@@ -540,8 +550,8 @@ public class Core implements IdentityListener {
                                storedSone.setLikePostIds(sone.getLikedPostIds());
                                storedSone.setLikeReplyIds(sone.getLikedReplyIds());
                                storedSone.setLatestEdition(sone.getRequestUri().getEdition());
+                               storedSone.setModificationCounter(0);
                        }
-                       saveSone(storedSone);
                }
        }
 
@@ -569,7 +579,7 @@ public class Core implements IdentityListener {
                identityManager.removeContext((OwnIdentity) sone.getIdentity(), "Sone");
                identityManager.removeProperty((OwnIdentity) sone.getIdentity(), "Sone.LatestEdition");
                try {
-                       configuration.getStringValue("Sone/" + sone.getId() + "/Time").setValue(null);
+                       configuration.getLongValue("Sone/" + sone.getId() + "/Time").setValue(null);
                } catch (ConfigurationException ce1) {
                        logger.log(Level.WARNING, "Could not remove Sone from configuration!", ce1);
                }
@@ -592,7 +602,7 @@ public class Core implements IdentityListener {
                String sonePrefix = "Sone/" + sone.getId();
                Long soneTime = configuration.getLongValue(sonePrefix + "/Time").getValue(null);
                if (soneTime == null) {
-                       logger.log(Level.INFO, "Could not load Sone because there is no Sone has been saved.");
+                       logger.log(Level.INFO, "Could not load Sone because no Sone has been saved.");
                        return;
                }
                long soneModificationCounter = configuration.getLongValue(sonePrefix + "/ModificationCounter").getValue((long) 0);
@@ -957,13 +967,11 @@ public class Core implements IdentityListener {
         *
         * @param uriString
         *            The URI to derive the Sone URI from
-        * @param latestEditionString
-        *            The latest edition as a {@link String}, or {@code null}
         * @return The derived URI
         */
-       private FreenetURI getSoneUri(String uriString, String latestEditionString) {
+       private FreenetURI getSoneUri(String uriString) {
                try {
-                       FreenetURI uri = new FreenetURI(uriString).setDocName("Sone").setMetaString(new String[0]).setSuggestedEdition(Numbers.safeParseLong(latestEditionString, (long) 0));
+                       FreenetURI uri = new FreenetURI(uriString).setDocName("Sone").setMetaString(new String[0]);
                        return uri;
                } catch (MalformedURLException mue1) {
                        logger.log(Level.WARNING, "Could not create Sone URI from URI: " + uriString, mue1);
@@ -991,7 +999,7 @@ public class Core implements IdentityListener {
         */
        @Override
        public void ownIdentityRemoved(OwnIdentity ownIdentity) {
-               /* TODO */
+               logger.log(Level.FINEST, "Removing OwnIdentity: " + ownIdentity);
        }
 
        /**
@@ -1007,8 +1015,16 @@ public class Core implements IdentityListener {
         * {@inheritDoc}
         */
        @Override
-       public void identityUpdated(Identity identity) {
-               /* TODO */
+       public void identityUpdated(final Identity identity) {
+               new Thread(new Runnable() {
+
+                       @Override
+                       @SuppressWarnings("synthetic-access")
+                       public void run() {
+                               Sone sone = getRemoteSone(identity.getId());
+                               soneDownloader.fetchSone(sone);
+                       }
+               }).start();
        }
 
        /**