X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FCore.java;h=cf61941aac131122501f94aa2a68fc904d87aee0;hb=d88fbc4ce31eba494a498c3a2629f30a4a07bedd;hp=a0de3671073dfa9e3e3466a228e9ce6bb6e78602;hpb=bf5645aadca98f98d34a71cf68409188c9d79d84;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 a0de367..cf61941 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -39,6 +39,7 @@ import net.pterodactylus.util.config.Configuration; import net.pterodactylus.util.config.ConfigurationException; import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.service.AbstractService; +import freenet.client.FetchResult; import freenet.keys.FreenetURI; /** @@ -134,6 +135,7 @@ public class Core extends AbstractService { public Sone getSone(String soneId) { if (!soneCache.containsKey(soneId)) { Sone sone = new Sone(soneId); + soneDownloader.addSone(sone); soneCache.put(soneId, sone); } return soneCache.get(soneId); @@ -164,7 +166,43 @@ public class Core extends AbstractService { * @return The created post */ public Post createPost(Sone sone, long time, String text) { - return getPost(UUID.randomUUID().toString()).setSone(sone).setTime(time).setText(text); + Post post = getPost(UUID.randomUUID().toString()).setSone(sone).setTime(time).setText(text); + sone.addPost(post); + return post; + } + + /** + * Creates a reply. + * + * @param sone + * The Sone that posts the reply + * @param post + * The post the reply refers to + * @param text + * The text of the reply + * @return The created reply + */ + public Reply createReply(Sone sone, Post post, String text) { + return createReply(sone, post, System.currentTimeMillis(), text); + } + + /** + * Creates a reply. + * + * @param sone + * The Sone that posts the reply + * @param post + * The post the reply refers to + * @param time + * The time of the post + * @param text + * The text of the reply + * @return The created reply + */ + public Reply createReply(Sone sone, Post post, long time, String text) { + Reply reply = getReply(UUID.randomUUID().toString()).setSone(sone).setPost(post).setTime(time).setText(text); + sone.addReply(reply); + return reply; } // @@ -181,7 +219,7 @@ public class Core extends AbstractService { if (localSones.add(sone)) { SoneInserter soneInserter = new SoneInserter(freenetInterface, sone); soneInserter.start(); - soneDownloader.addSone(sone); + soneDownloader.removeSone(sone); soneInserters.put(sone, soneInserter); } } @@ -245,6 +283,21 @@ public class Core extends AbstractService { } /** + * Loads the Sone from the given request URI. + * + * @param requestUri + * The request URI to load the Sone from + */ + public void loadSone(String requestUri) { + try { + FetchResult fetchResult = freenetInterface.fetchUri(new FreenetURI(requestUri).setMetaString(new String[] { "sone.xml" })); + soneDownloader.parseSone(null, fetchResult); + } catch (MalformedURLException mue1) { + logger.log(Level.INFO, "Could not create URI from “" + requestUri + "”.", mue1); + } + } + + /** * Deletes the given Sone from this plugin instance. * * @param sone