X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FWebInterface.java;h=73436c760121c04ad97cb8bfc544e4adb9c075f8;hb=3fd7b8594c097f1448fe84f47f579fc9c85aaa25;hp=8eb012242245af25baf56b144efca9823e207b4e;hpb=8908979c7d8edf18c629c0d38f4a6078b639ca6b;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 8eb0122..73436c7 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -100,6 +100,7 @@ import net.pterodactylus.util.cache.CacheItem; import net.pterodactylus.util.cache.DefaultCacheItem; import net.pterodactylus.util.cache.MemoryCache; import net.pterodactylus.util.cache.ValueRetriever; +import net.pterodactylus.util.collection.SetBuilder; import net.pterodactylus.util.filter.Filters; import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.notify.Notification; @@ -168,6 +169,12 @@ public class WebInterface implements CoreListener { /** The “new reply” notification. */ private final ListNotification newReplyNotification; + /** The invisible “local post” notification. */ + private final ListNotification localPostNotification; + + /** The invisible “local reply” notification. */ + private final ListNotification localReplyNotification; + /** The “you have been mentioned” notification. */ private final ListNotification mentionNotification; @@ -196,7 +203,7 @@ public class WebInterface implements CoreListener { public WebInterface(SonePlugin sonePlugin) { this.sonePlugin = sonePlugin; formPassword = sonePlugin.pluginRespirator().getToadletContainer().getFormPassword(); - soneTextParser = new SoneTextParser(getCore()); + soneTextParser = new SoneTextParser(getCore(), getCore()); templateContextFactory = new TemplateContextFactory(); templateContextFactory.addAccessor(Object.class, new ReflectionAccessor()); @@ -236,9 +243,15 @@ public class WebInterface implements CoreListener { Template newPostNotificationTemplate = TemplateParser.parse(createReader("/templates/notify/newPostNotification.html")); newPostNotification = new ListNotification("new-post-notification", "posts", newPostNotificationTemplate, false); + Template localPostNotificationTemplate = TemplateParser.parse(createReader("/templates/notify/newPostNotification.html")); + localPostNotification = new ListNotification("local-post-notification", "posts", localPostNotificationTemplate, false); + Template newReplyNotificationTemplate = TemplateParser.parse(createReader("/templates/notify/newReplyNotification.html")); newReplyNotification = new ListNotification("new-reply-notification", "replies", newReplyNotificationTemplate, false); + Template localReplyNotificationTemplate = TemplateParser.parse(createReader("/templates/notify/newReplyNotification.html")); + localReplyNotification = new ListNotification("local-reply-notification", "replies", localReplyNotificationTemplate, false); + Template mentionNotificationTemplate = TemplateParser.parse(createReader("/templates/notify/mentionNotification.html")); mentionNotification = new ListNotification("mention-notification", "posts", mentionNotificationTemplate, false); @@ -420,7 +433,7 @@ public class WebInterface implements CoreListener { * @return The new posts */ public Set getNewPosts() { - return new HashSet(newPostNotification.getElements()); + return new SetBuilder().addAll(newPostNotification.getElements()).addAll(localPostNotification.getElements()).get(); } /** @@ -430,7 +443,7 @@ public class WebInterface implements CoreListener { * @return The new replies */ public Set getNewReplies() { - return new HashSet(newReplyNotification.getElements()); + return new SetBuilder().addAll(newReplyNotification.getElements()).addAll(localReplyNotification.getElements()).get(); } /** @@ -668,6 +681,15 @@ public class WebInterface implements CoreListener { } } + /** + * Returns all {@link Core#isLocalSone(Sone) local Sone}s that are + * referenced by {@link SonePart}s in the given text (after parsing it using + * {@link SoneTextParser}). + * + * @param text + * The text to parse + * @return All mentioned local Sones + */ private Set getMentionedSones(String text) { /* we need no context to find mentioned Sones. */ Set mentionedSones = new HashSet(); @@ -722,10 +744,15 @@ public class WebInterface implements CoreListener { */ @Override public void newPostFound(Post post) { - newPostNotification.add(post); + boolean isLocal = getCore().isLocalSone(post.getSone()); + if (isLocal) { + localPostNotification.add(post); + } else { + newPostNotification.add(post); + } if (!hasFirstStartNotification()) { - notificationManager.addNotification(newPostNotification); - if (!getMentionedSones(post.getText()).isEmpty()) { + notificationManager.addNotification(isLocal ? localPostNotification : newPostNotification); + if (!getMentionedSones(post.getText()).isEmpty() && !isLocal) { mentionNotification.add(post); notificationManager.addNotification(mentionNotification); } @@ -742,10 +769,15 @@ public class WebInterface implements CoreListener { if (reply.getPost().getSone() == null) { return; } - newReplyNotification.add(reply); + boolean isLocal = getCore().isLocalSone(reply.getSone()); + if (isLocal) { + localReplyNotification.add(reply); + } else { + newReplyNotification.add(reply); + } if (!hasFirstStartNotification()) { - notificationManager.addNotification(newReplyNotification); - if (!getMentionedSones(reply.getText()).isEmpty()) { + notificationManager.addNotification(isLocal ? localReplyNotification : newReplyNotification); + if (!getMentionedSones(reply.getText()).isEmpty() && !isLocal) { mentionNotification.add(reply.getPost()); notificationManager.addNotification(mentionNotification); } @@ -768,6 +800,7 @@ public class WebInterface implements CoreListener { @Override public void markPostKnown(Post post) { newPostNotification.remove(post); + localPostNotification.remove(post); mentionNotification.remove(post); } @@ -777,6 +810,7 @@ public class WebInterface implements CoreListener { @Override public void markReplyKnown(Reply reply) { newReplyNotification.remove(reply); + localReplyNotification.remove(reply); mentionNotification.remove(reply.getPost()); } @@ -794,6 +828,7 @@ public class WebInterface implements CoreListener { @Override public void postRemoved(Post post) { newPostNotification.remove(post); + localPostNotification.remove(post); } /** @@ -802,6 +837,7 @@ public class WebInterface implements CoreListener { @Override public void replyRemoved(Reply reply) { newReplyNotification.remove(reply); + localReplyNotification.remove(reply); } /**