X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FCore.java;h=264390e13628eb39759d78dfad9a049fad72d648;hb=1dfe9f0daba9a1103c5566b81af5bed7791dde5c;hp=8a2b3cb08d9bc912acb185b4f8d915da98a7ab3c;hpb=a35e361e1d6e395d45d9bca8e2996fa911763949;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 8a2b3cb..264390e 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -38,6 +38,7 @@ import net.pterodactylus.sone.data.Album; import net.pterodactylus.sone.data.Client; import net.pterodactylus.sone.data.Image; import net.pterodactylus.sone.data.Post; +import net.pterodactylus.sone.data.PostReply; import net.pterodactylus.sone.data.Profile; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; @@ -173,7 +174,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis private Set knownPosts = new HashSet(); /** All replies. */ - private Map replies = new HashMap(); + private Map replies = new HashMap(); /** All new replies. */ private Set newReplies = new HashSet(); @@ -676,7 +677,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis * The ID of the reply to get * @return The reply */ - public Reply getReply(String replyId) { + public PostReply getReply(String replyId) { return getReply(replyId, true); } @@ -692,11 +693,11 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis * to return {@code null} if no reply can be found * @return The reply, or {@code null} if there is no such reply */ - public Reply getReply(String replyId, boolean create) { + public PostReply getReply(String replyId, boolean create) { synchronized (replies) { - Reply reply = replies.get(replyId); + PostReply reply = replies.get(replyId); if (create && (reply == null)) { - reply = new Reply(replyId); + reply = new PostReply(replyId); replies.put(replyId, reply); } return reply; @@ -710,11 +711,11 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis * The post to get all replies for * @return All replies for the given post */ - public List getReplies(Post post) { + public List getReplies(Post post) { Set sones = getSones(); - List replies = new ArrayList(); + List replies = new ArrayList(); for (Sone sone : sones) { - for (Reply reply : sone.getReplies()) { + for (PostReply reply : sone.getReplies()) { if (reply.getPost().equals(post)) { replies.add(reply); } @@ -762,7 +763,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis * The reply to get the liking Sones for * @return The Sones that like the given reply */ - public Set getLikes(Reply reply) { + public Set getLikes(PostReply reply) { Set sones = new HashSet(); for (Sone sone : getSones()) { if (sone.getLikedReplyIds().contains(reply.getId())) { @@ -1007,6 +1008,10 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis } Sone sone = addLocalSone(ownIdentity); sone.getOptions().addBooleanOption("AutoFollow", new DefaultOption(false)); + sone.getOptions().addBooleanOption("EnableSoneInsertNotifications", new DefaultOption(false)); + sone.getOptions().addBooleanOption("ShowNotification/NewSones", new DefaultOption(true)); + sone.getOptions().addBooleanOption("ShowNotification/NewPosts", new DefaultOption(true)); + sone.getOptions().addBooleanOption("ShowNotification/NewReplies", new DefaultOption(true)); sone.addFriend("nwa8lHa271k2QvJ8aa0Ov7IHAV-DFOCFgmDt3X6BpCI"); touchConfiguration(); return sone; @@ -1204,16 +1209,16 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis } synchronized (replies) { if (!soneRescueMode) { - for (Reply reply : storedSone.getReplies()) { + for (PostReply reply : storedSone.getReplies()) { replies.remove(reply.getId()); if (!sone.getReplies().contains(reply)) { coreListenerManager.fireReplyRemoved(reply); } } } - Set storedReplies = storedSone.getReplies(); + Set storedReplies = storedSone.getReplies(); synchronized (newReplies) { - for (Reply reply : sone.getReplies()) { + for (PostReply reply : sone.getReplies()) { reply.setSone(storedSone); if (!storedReplies.contains(reply) && !knownReplies.contains(reply.getId())) { newReplies.add(reply.getId()); @@ -1249,7 +1254,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis for (Post post : sone.getPosts()) { storedSone.addPost(post); } - for (Reply reply : sone.getReplies()) { + for (PostReply reply : sone.getReplies()) { storedSone.addReply(reply); } for (String likedPostId : sone.getLikedPostIds()) { @@ -1342,6 +1347,9 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis /* initialize options. */ sone.getOptions().addBooleanOption("AutoFollow", new DefaultOption(false)); sone.getOptions().addBooleanOption("EnableSoneInsertNotifications", new DefaultOption(false)); + sone.getOptions().addBooleanOption("ShowNotification/NewSones", new DefaultOption(true)); + sone.getOptions().addBooleanOption("ShowNotification/NewPosts", new DefaultOption(true)); + sone.getOptions().addBooleanOption("ShowNotification/NewReplies", new DefaultOption(true)); /* load Sone. */ String sonePrefix = "Sone/" + sone.getId(); @@ -1395,7 +1403,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis } /* load replies. */ - Set replies = new HashSet(); + Set replies = new HashSet(); while (true) { String replyPrefix = sonePrefix + "/Replies/" + replies.size(); String replyId = configuration.getStringValue(replyPrefix + "/ID").getValue(null); @@ -1528,7 +1536,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis } } synchronized (newReplies) { - for (Reply reply : replies) { + for (PostReply reply : replies) { knownReplies.add(reply.getId()); } } @@ -1718,7 +1726,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis * The text of the reply * @return The created reply */ - public Reply createReply(Sone sone, Post post, String text) { + public PostReply createReply(Sone sone, Post post, String text) { return createReply(sone, post, System.currentTimeMillis(), text); } @@ -1735,12 +1743,12 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis * The text of the reply * @return The created reply */ - public Reply createReply(Sone sone, Post post, long time, String text) { + public PostReply createReply(Sone sone, Post post, long time, String text) { if (!isLocalSone(sone)) { logger.log(Level.FINE, "Tried to create reply for non-local Sone: %s", sone); return null; } - final Reply reply = new Reply(sone, post, System.currentTimeMillis(), text); + final PostReply reply = new PostReply(sone, post, System.currentTimeMillis(), text); synchronized (replies) { replies.put(reply.getId(), reply); } @@ -1769,7 +1777,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis * @param reply * The reply to delete */ - public void deleteReply(Reply reply) { + public void deleteReply(PostReply reply) { Sone sone = reply.getSone(); if (!isLocalSone(sone)) { logger.log(Level.FINE, "Tried to delete non-local reply: %s", reply); @@ -1793,7 +1801,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis * @param reply * The reply to mark as known */ - public void markReplyKnown(Reply reply) { + public void markReplyKnown(PostReply reply) { synchronized (newReplies) { if (newReplies.remove(reply.getId())) { knownReplies.add(reply.getId()); @@ -2028,8 +2036,6 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis logger.log(Level.INFO, "Saving Sone: %s", sone); try { - ((OwnIdentity) sone.getIdentity()).setProperty("Sone.LatestEdition", String.valueOf(sone.getLatestEdition())); - /* save Sone into configuration. */ String sonePrefix = "Sone/" + sone.getId(); configuration.getLongValue(sonePrefix + "/Time").setValue(sone.getTime()); @@ -2066,7 +2072,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis /* save replies. */ int replyCounter = 0; - for (Reply reply : sone.getReplies()) { + for (PostReply reply : sone.getReplies()) { String replyPrefix = sonePrefix + "/Replies/" + replyCounter++; configuration.getStringValue(replyPrefix + "/ID").setValue(reply.getId()); configuration.getStringValue(replyPrefix + "/Post/ID").setValue(reply.getPost().getId()); @@ -2097,7 +2103,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis configuration.getStringValue(sonePrefix + "/Friends/" + friendCounter + "/ID").setValue(null); /* save albums. first, collect in a flat structure, top-level first. */ - List albums = Sone.flattenAlbums(sone.getAlbums()); + List albums = sone.getAllAlbums(); int albumCounter = 0; for (Album album : albums) { @@ -2132,9 +2138,15 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis /* save options. */ configuration.getBooleanValue(sonePrefix + "/Options/AutoFollow").setValue(sone.getOptions().getBooleanOption("AutoFollow").getReal()); + configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewSones").setValue(sone.getOptions().getBooleanOption("ShowNotification/NewSones").getReal()); + configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewPosts").setValue(sone.getOptions().getBooleanOption("ShowNotification/NewPosts").getReal()); + configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewReplies").setValue(sone.getOptions().getBooleanOption("ShowNotification/NewReplies").getReal()); configuration.getBooleanValue(sonePrefix + "/Options/EnableSoneInsertNotifications").setValue(sone.getOptions().getBooleanOption("EnableSoneInsertNotifications").getReal()); configuration.save(); + + ((OwnIdentity) sone.getIdentity()).setProperty("Sone.LatestEdition", String.valueOf(sone.getLatestEdition())); + logger.log(Level.INFO, "Sone %s saved.", sone); } catch (ConfigurationException ce1) { logger.log(Level.WARNING, "Could not save Sone: " + sone, ce1); @@ -2456,7 +2468,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis } synchronized (replies) { synchronized (newReplies) { - for (Reply reply : sone.getReplies()) { + for (PostReply reply : sone.getReplies()) { replies.remove(reply.getId()); newReplies.remove(reply.getId()); coreListenerManager.fireReplyRemoved(reply);