Add Sones as new when they are first added.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / Core.java
index abebdd7..132e4a6 100644 (file)
@@ -106,6 +106,9 @@ public class Core implements IdentityListener {
        /* synchronize access on this on itself. */
        private Map<String, Sone> remoteSones = new HashMap<String, Sone>();
 
+       /** All new Sones. */
+       private Set<Sone> newSones = new HashSet<Sone>();
+
        /** All posts. */
        private Map<String, Post> posts = new HashMap<String, Post>();
 
@@ -306,6 +309,20 @@ public class Core implements IdentityListener {
        }
 
        /**
+        * Returns whether the Sone with the given ID is a remote Sone.
+        *
+        * @param id
+        *            The ID of the Sone to check
+        * @return {@code true} if the Sone with the given ID is a remote Sone,
+        *         {@code false} otherwise
+        */
+       public boolean isRemoteSone(String id) {
+               synchronized (remoteSones) {
+                       return remoteSones.containsKey(id);
+               }
+       }
+
+       /**
         * Returns the post with the given ID.
         *
         * @param postId
@@ -494,11 +511,18 @@ public class Core implements IdentityListener {
                        return null;
                }
                synchronized (remoteSones) {
+                       boolean newSone = !isRemoteSone(identity.getId());
                        final Sone sone = getRemoteSone(identity.getId()).setIdentity(identity);
                        sone.setRequestUri(getSoneUri(identity.getRequestUri()));
                        sone.setLatestEdition(Numbers.safeParseLong(identity.getProperty("Sone.LatestEdition"), (long) 0));
+                       if (newSone) {
+                               synchronized (newSones) {
+                                       newSones.add(sone);
+                               }
+                       }
                        remoteSones.put(identity.getId(), sone);
                        soneDownloader.addSone(sone);
+                       setSoneStatus(sone, SoneStatus.unknown);
                        new Thread(new Runnable() {
 
                                @Override
@@ -508,7 +532,6 @@ public class Core implements IdentityListener {
                                }
 
                        }, "Sone Downloader").start();
-                       setSoneStatus(sone, SoneStatus.idle);
                        return sone;
                }
        }
@@ -550,8 +573,8 @@ public class Core implements IdentityListener {
                                storedSone.setLikePostIds(sone.getLikedPostIds());
                                storedSone.setLikeReplyIds(sone.getLikedReplyIds());
                                storedSone.setLatestEdition(sone.getRequestUri().getEdition());
+                               storedSone.setModificationCounter(0);
                        }
-                       saveSone(storedSone);
                }
        }