From: David ‘Bombe’ Roden Date: Thu, 11 Nov 2010 20:41:18 +0000 (+0100) Subject: Mark new replies. X-Git-Tag: 0.2.1~2 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=19ff2e20cd414bfa9e600ff01500c8aed44f8519;p=Sone.git Mark new replies. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 37d1741..895f45e 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -126,6 +126,12 @@ public class Core implements IdentityListener { /** All replies. */ private Map replies = new HashMap(); + /** All new replies. */ + private Set newReplies = new HashSet(); + + /** All known replies. */ + private Set knownReplies = new HashSet(); + /** * Creates a new core. * @@ -468,6 +474,22 @@ public class Core implements IdentityListener { } /** + * Returns whether the reply with the given ID is new. + * + * @param replyId + * The ID of the reply to check + * @return {@code true} if the reply is considered to be new, {@code false} + * otherwise + */ + public boolean isNewReply(String replyId) { + synchronized (newReplies) { + boolean isNew = !knownReplies.contains(replyId) && newReplies.remove(replyId); + knownReplies.add(replyId); + return isNew; + } + } + + /** * Returns all Sones that have liked the given post. * * @param post @@ -654,8 +676,13 @@ public class Core implements IdentityListener { for (Reply reply : storedSone.getReplies()) { replies.remove(reply.getId()); } - for (Reply reply : sone.getReplies()) { - replies.put(reply.getId(), reply); + synchronized (newReplies) { + for (Reply reply : sone.getReplies()) { + if (!storedSone.getReplies().contains(reply) && !knownSones.contains(reply.getId())) { + newReplies.add(reply.getId()); + } + replies.put(reply.getId(), reply); + } } } synchronized (storedSone) { @@ -818,6 +845,11 @@ public class Core implements IdentityListener { knownPosts.add(post.getId()); } } + synchronized (newReplies) { + for (Reply reply : replies) { + knownReplies.add(reply.getId()); + } + } } /** @@ -993,6 +1025,9 @@ public class Core implements IdentityListener { synchronized (replies) { replies.put(reply.getId(), reply); } + synchronized (newReplies) { + knownReplies.add(reply.getId()); + } sone.addReply(reply); saveSone(sone); } @@ -1093,6 +1128,18 @@ public class Core implements IdentityListener { } } + /* load known replies. */ + int replyCounter = 0; + while (true) { + String knownReplyId = configuration.getStringValue("KnownReplies/" + replyCounter++ + "/ID").getValue(null); + if (knownReplyId == null) { + break; + } + synchronized (newReplies) { + knownReplies.add(knownReplyId); + } + } + } /** @@ -1123,6 +1170,15 @@ public class Core implements IdentityListener { configuration.getStringValue("KnownPosts/" + postCounter + "/ID").setValue(null); } + /* save known replies. */ + int replyCounter = 0; + synchronized (newReplies) { + for (String knownReplyId : knownReplies) { + configuration.getStringValue("KnownReplies/" + replyCounter++ + "/ID").setValue(knownReplyId); + } + configuration.getStringValue("KnownReplies/" + replyCounter + "/ID").setValue(null); + } + } catch (ConfigurationException ce1) { logger.log(Level.SEVERE, "Could not store configuration!", ce1); } diff --git a/src/main/java/net/pterodactylus/sone/template/ReplyAccessor.java b/src/main/java/net/pterodactylus/sone/template/ReplyAccessor.java index 53c5448..08c91c7 100644 --- a/src/main/java/net/pterodactylus/sone/template/ReplyAccessor.java +++ b/src/main/java/net/pterodactylus/sone/template/ReplyAccessor.java @@ -56,6 +56,8 @@ public class ReplyAccessor extends ReflectionAccessor { } else if (member.equals("liked")) { Sone currentSone = (Sone) dataProvider.getData("currentSone"); return (currentSone != null) && (currentSone.isLikedReplyId(reply.getId())); + } else if (member.equals("new")) { + return core.isNewReply(reply.getId()); } return super.get(dataProvider, object, member); } diff --git a/src/main/resources/static/css/sone.css b/src/main/resources/static/css/sone.css index b05a1f1..9e33575 100644 --- a/src/main/resources/static/css/sone.css +++ b/src/main/resources/static/css/sone.css @@ -234,6 +234,10 @@ textarea { padding: 1ex; } +#sone .post .reply.new { + background-color: #ffffa0; +} + #sone .post .reply .time { float: none; display: inline; diff --git a/src/main/resources/templates/include/viewPost.html b/src/main/resources/templates/include/viewPost.html index f3d4696..ddb3dbd 100644 --- a/src/main/resources/templates/include/viewPost.html +++ b/src/main/resources/templates/include/viewPost.html @@ -37,7 +37,7 @@
<%foreach post.replies reply> -
+
Avatar Image