Update time when inserting, store time in insert.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / Core.java
index b0dadbe..6ecd5fc 100644 (file)
@@ -350,6 +350,28 @@ public class Core extends AbstractService {
        }
 
        /**
+        * Loads and updates the given Sone.
+        *
+        * @param sone
+        *            The Sone to load
+        */
+       public void loadSone(final Sone sone) {
+               new Thread(new Runnable() {
+
+                       @Override
+                       @SuppressWarnings("synthetic-access")
+                       public void run() {
+                               FreenetURI realRequestUri = sone.getRequestUri().setMetaString(new String[] { "sone.xml" });
+                               FetchResult fetchResult = freenetInterface.fetchUri(realRequestUri);
+                               Sone parsedSone = soneDownloader.parseSone(sone, fetchResult, realRequestUri);
+                               if (parsedSone != null) {
+                                       addSone(parsedSone);
+                               }
+                       }
+               }, "Sone Downloader").start();
+       }
+
+       /**
         * Deletes the given Sone from this plugin instance.
         *
         * @param sone
@@ -514,7 +536,6 @@ public class Core extends AbstractService {
                                        String friendKey = configuration.getStringValue(friendPrefix + "/Key").getValue(null);
                                        String friendName = configuration.getStringValue(friendPrefix + "/Name").getValue(null);
                                        friendSone.setRequestUri(new FreenetURI(friendKey)).setName(friendName);
-                                       loadSone(friendKey);
                                        sone.addFriend(friendSone);
                                }
 
@@ -526,6 +547,11 @@ public class Core extends AbstractService {
                } while (true);
                logger.log(Level.INFO, "Loaded %d Sones.", getSones().size());
 
+               /* load all remote Sones. */
+               for (Sone remoteSone : getRemoteSones()) {
+                       loadSone(remoteSone);
+               }
+
                logger.exiting(Core.class.getName(), "loadConfiguration()");
        }