X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FCore.java;h=459431ced7ee5dc24b9e8f8a775f7ead52aa48cf;hp=48976b172d7f83d47b1575e2b56d085692c27e96;hb=94041feaf2a141b8c75725301f06d7e4bc617a12;hpb=d429bc07de2c62921323f300024c2df348ae71cf diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 48976b1..459431c 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -106,7 +106,7 @@ public class Core extends AbstractService { */ public Core freenetInterface(FreenetInterface freenetInterface) { this.freenetInterface = freenetInterface; - soneDownloader = new SoneDownloader(freenetInterface); + soneDownloader = new SoneDownloader(this, freenetInterface); soneDownloader.start(); return this; } @@ -136,6 +136,34 @@ public class Core extends AbstractService { return soneCache.get(soneId); } + /** + * Creates a new post. + * + * @param sone + * The sone that creates the post + * @param text + * The text of the post + * @return The created post + */ + public Post createPost(Sone sone, String text) { + return createPost(sone, System.currentTimeMillis(), text); + } + + /** + * Creates a new post. + * + * @param sone + * The Sone that creates the post + * @param time + * The time of the post + * @param text + * The text of the post + * @return The created post + */ + public Post createPost(Sone sone, long time, String text) { + return getPost(UUID.randomUUID().toString()).setSone(sone).setTime(time).setText(text); + } + // // ACTIONS // @@ -239,6 +267,36 @@ public class Core extends AbstractService { localSones.remove(sone); } + /** + * Returns the post with the given ID. If no post exists yet with the given + * ID, a new post is returned. + * + * @param postId + * The ID of the post + * @return The post + */ + public Post getPost(String postId) { + if (!postCache.containsKey(postId)) { + postCache.put(postId, new Post(postId)); + } + return postCache.get(postId); + } + + /** + * Returns the reply with the given ID. If no reply exists yet with the + * given ID, a new reply is returned. + * + * @param replyId + * The ID of the reply + * @return The reply + */ + public Reply getReply(String replyId) { + if (!replyCache.containsKey(replyId)) { + replyCache.put(replyId, new Reply(replyId)); + } + return replyCache.get(replyId); + } + // // SERVICE METHODS // @@ -307,8 +365,7 @@ public class Core extends AbstractService { } long time = configuration.getLongValue(postPrefix + "/Time").getValue(null); String text = configuration.getStringValue(postPrefix + "/Text").getValue(null); - Post post = new Post(id, sone, time, text); - postCache.put(id, post); + Post post = getPost(id).setSone(sone).setTime(time).setText(text); sone.addPost(post); } while (true); int replyCounter = 0; @@ -325,7 +382,7 @@ public class Core extends AbstractService { Post replyPost = postCache.get(configuration.getStringValue(replyPrefix + "/Post").getValue(null)); long replyTime = configuration.getLongValue(replyPrefix + "/Time").getValue(null); String replyText = configuration.getStringValue(replyPrefix + "/Text").getValue(null); - Reply reply = new Reply(replyId, replySone, replyPost, replyTime, replyText); + Reply reply = getReply(replyId).setSone(replySone).setPost(replyPost).setTime(replyTime).setText(replyText); replyCache.put(replyId, reply); } while (true);