Downlad SSKs instead of USKs to prevent triggering another search.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / SoneDownloader.java
index c883301..56c1e4a 100644 (file)
@@ -25,6 +25,7 @@ import java.util.Set;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import net.pterodactylus.sone.core.Core.Preferences;
 import net.pterodactylus.sone.core.Core.SoneStatus;
 import net.pterodactylus.sone.data.Client;
 import net.pterodactylus.sone.data.Post;
@@ -92,9 +93,10 @@ public class SoneDownloader extends AbstractService {
         *            The Sone to add
         */
        public void addSone(Sone sone) {
-               if (sones.add(sone)) {
-                       freenetInterface.registerUsk(sone, this);
+               if (!sones.add(sone)) {
+                       freenetInterface.unregisterUsk(sone);
                }
+               freenetInterface.registerUsk(sone, this);
        }
 
        /**
@@ -117,13 +119,13 @@ public class SoneDownloader extends AbstractService {
         *            The Sone to fetch
         */
        public void fetchSone(Sone sone) {
-               fetchSone(sone, sone.getRequestUri());
+               fetchSone(sone, sone.getRequestUri().sskForUSK());
        }
 
        /**
         * Fetches the updated Sone. This method can be used to fetch a Sone from a
-        * specific URI (which happens when {@link Core#isSoneRescueMode() „Sone
-        * rescue mode“} is active).
+        * specific URI (which happens when {@link Preferences#isSoneRescueMode()
+        * „Sone rescue mode“} is active).
         *
         * @param sone
         *            The Sone to fetch
@@ -131,9 +133,6 @@ public class SoneDownloader extends AbstractService {
         *            The URI to fetch the Sone from
         */
        public void fetchSone(Sone sone, FreenetURI soneUri) {
-               if (core.getSoneStatus(sone) == SoneStatus.downloading) {
-                       return;
-               }
                logger.log(Level.FINE, "Starting fetch for Sone “%s” from %s…", new Object[] { sone, soneUri });
                FreenetURI requestUri = soneUri.setMetaString(new String[] { "sone.xml" });
                core.setSoneStatus(sone, SoneStatus.downloading);
@@ -146,6 +145,7 @@ public class SoneDownloader extends AbstractService {
                        logger.log(Level.FINEST, "Got %d bytes back.", fetchResults.getRight().size());
                        Sone parsedSone = parseSone(sone, fetchResults.getRight(), fetchResults.getLeft());
                        if (parsedSone != null) {
+                               addSone(parsedSone);
                                core.updateSone(parsedSone);
                        }
                } finally {