X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FCore.java;h=055ede4a30c59c5036bdd78730861292ba92a335;hb=0dc8ce4308f55d8f13e41c7ac312c11a379418b9;hp=83f7e6c523d13a5caf43db8e08cd6092e35ccde9;hpb=d9ff777c483f3fea071a9cf8dd7c40e792fd8f1e;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 83f7e6c..055ede4 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -106,6 +106,9 @@ public class Core implements IdentityListener { /* synchronize access on this on itself. */ private Map remoteSones = new HashMap(); + /** All new Sones. */ + private Set newSones = new HashSet(); + /** All posts. */ private Map posts = new HashMap(); @@ -306,6 +309,35 @@ 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 whether the given Sone is a new Sone. After this check, the Sone + * is marked as known, i.e. a second call with the same parameters will + * always yield {@code false}. + * + * @param sone + * The sone to check for + * @return {@code true} if the given Sone is new, false otherwise + */ + public boolean isNewSone(Sone sone) { + synchronized (newSones) { + return newSones.remove(sone); + } + } + + /** * Returns the post with the given ID. * * @param postId @@ -451,6 +483,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; } } @@ -485,11 +526,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 @@ -499,7 +547,6 @@ public class Core implements IdentityListener { } }, "Sone Downloader").start(); - setSoneStatus(sone, SoneStatus.idle); return sone; } } @@ -541,8 +588,8 @@ public class Core implements IdentityListener { storedSone.setLikePostIds(sone.getLikedPostIds()); storedSone.setLikeReplyIds(sone.getLikedReplyIds()); storedSone.setLatestEdition(sone.getRequestUri().getEdition()); + storedSone.setModificationCounter(0); } - saveSone(storedSone); } }