From 74223530641d7581c7d8f572e98eff1a01946ebd Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 18 Jun 2011 16:24:20 +0200 Subject: [PATCH] Mark local elements as known from the core, not from the client. --- .../java/net/pterodactylus/sone/core/Core.java | 28 ++++++++++++++++++++-- src/main/resources/static/javascript/sone.js | 5 ---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 1c67231..3c99eef 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -54,6 +54,7 @@ import net.pterodactylus.util.config.Configuration; import net.pterodactylus.util.config.ConfigurationException; import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.number.Numbers; +import net.pterodactylus.util.thread.Ticker; import net.pterodactylus.util.validation.IntegerRangeValidator; import net.pterodactylus.util.validation.Validation; import net.pterodactylus.util.version.Version; @@ -179,6 +180,9 @@ public class Core implements IdentityListener, UpdateListener, SoneProvider, Pos /** Trusted identities, sorted by own identities. */ private Map> trustedIdentities = Collections.synchronizedMap(new HashMap>()); + /** Ticker for threads that mark own elements as known. */ + private Ticker localElementTicker = new Ticker(); + /** * Creates a new core. * @@ -1502,7 +1506,7 @@ public class Core implements IdentityListener, UpdateListener, SoneProvider, Pos logger.log(Level.FINE, "Tried to create post for non-local Sone: %s", sone); return null; } - Post post = new Post(sone, time, text); + final Post post = new Post(sone, time, text); if (recipient != null) { post.setRecipient(recipient); } @@ -1515,6 +1519,16 @@ public class Core implements IdentityListener, UpdateListener, SoneProvider, Pos } sone.addPost(post); saveSone(sone); + localElementTicker.registerEvent(System.currentTimeMillis() + 10 * 1000, new Runnable() { + + /** + * {@inheritDoc} + */ + @Override + public void run() { + markPostKnown(post); + } + }, "Mark " + post + " read."); return post; } @@ -1635,7 +1649,7 @@ public class Core implements IdentityListener, UpdateListener, SoneProvider, Pos logger.log(Level.FINE, "Tried to create reply for non-local Sone: %s", sone); return null; } - Reply reply = new Reply(sone, post, System.currentTimeMillis(), text); + final Reply reply = new Reply(sone, post, System.currentTimeMillis(), text); synchronized (replies) { replies.put(reply.getId(), reply); } @@ -1645,6 +1659,16 @@ public class Core implements IdentityListener, UpdateListener, SoneProvider, Pos } sone.addReply(reply); saveSone(sone); + localElementTicker.registerEvent(System.currentTimeMillis() + 10 * 1000, new Runnable() { + + /** + * {@inheritDoc} + */ + @Override + public void run() { + markReplyKnown(reply); + } + }, "Mark " + reply + " read."); return reply; } diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index dd33308..d5db8ef 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -1239,11 +1239,6 @@ function loadNewPost(postId, soneId, recipientId, time) { newPost = $(data.post.html).addClass("hidden"); if ($(".post-author-local", newPost).text() == "true") { newPost.removeClass("new"); - (function(newPost) { - setTimeout(function() { - markPostAsKnown(newPost, false); - }, 5000); - })(newPost); } if (firstOlderPost != null) { newPost.insertBefore(firstOlderPost); -- 2.7.4