Store latest edition in Sone, update WoT properties after inserting.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / Core.java
index 284c6fb..b929c23 100644 (file)
@@ -408,13 +408,22 @@ public class Core implements IdentityListener {
                                return localSones.get(ownIdentity.getId());
                        }
                        String latestEdition = ownIdentity.getProperty("Sone.LatestEdition");
-                       Sone sone = new Sone(ownIdentity).setInsertUri(getSoneUri(ownIdentity.getInsertUri(), latestEdition)).setRequestUri(getSoneUri(ownIdentity.getRequestUri(), latestEdition));
+                       final Sone sone = new Sone(ownIdentity).setInsertUri(getSoneUri(ownIdentity.getInsertUri(), latestEdition)).setRequestUri(getSoneUri(ownIdentity.getRequestUri(), latestEdition));
                        /* TODO - load posts ’n stuff */
                        localSones.put(ownIdentity.getId(), sone);
                        SoneInserter soneInserter = new SoneInserter(this, freenetInterface, sone);
                        soneInserters.put(sone, soneInserter);
                        soneInserter.start();
                        setSoneStatus(sone, SoneStatus.idle);
+                       new Thread(new Runnable() {
+
+                               @Override
+                               @SuppressWarnings("synthetic-access")
+                               public void run() {
+                                       soneDownloader.fetchSone(sone);
+                               }
+
+                       }, "Sone Downloader").start();
                        return sone;
                }
        }
@@ -498,7 +507,7 @@ public class Core implements IdentityListener {
                                storedSone.setReplies(sone.getReplies());
                                storedSone.setLikePostIds(sone.getLikedPostIds());
                                storedSone.setLikeReplyIds(sone.getLikedReplyIds());
-                               storedSone.updateUris(sone.getRequestUri().getEdition());
+                               storedSone.setLatestEdition(sone.getRequestUri().getEdition());
                        }
                        saveSone(storedSone);
                }
@@ -538,7 +547,13 @@ public class Core implements IdentityListener {
        public void saveSone(Sone sone) {
                if (!isLocalSone(sone)) {
                        logger.log(Level.FINE, "Tried to save non-local Sone: %s", sone);
+                       return;
+               }
+               if (!(sone.getIdentity() instanceof OwnIdentity)) {
+                       logger.log(Level.WARNING, "Local Sone without OwnIdentity found, refusing to save: %s", sone);
+                       return;
                }
+               identityManager.setProperty((OwnIdentity) sone.getIdentity(), "Sone.LatestEdition", String.valueOf(sone.getLatestEdition()));
                /* TODO - implement saving. */
        }