From 06ed021f1232830b8617efdb4c2d26684a18b643 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 14 Nov 2010 21:04:56 +0100 Subject: [PATCH] Add new reply notification. --- .../sone/notify/NewReplyNotification.java | 98 ++++++++++++++++++++++ .../net/pterodactylus/sone/web/WebInterface.java | 15 +++- src/main/resources/i18n/sone.en.properties | 1 + .../templates/notify/newReplyNotification.html | 6 ++ 4 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 src/main/java/net/pterodactylus/sone/notify/NewReplyNotification.java create mode 100644 src/main/resources/templates/notify/newReplyNotification.html diff --git a/src/main/java/net/pterodactylus/sone/notify/NewReplyNotification.java b/src/main/java/net/pterodactylus/sone/notify/NewReplyNotification.java new file mode 100644 index 0000000..1b33245 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/notify/NewReplyNotification.java @@ -0,0 +1,98 @@ +/* + * Sone - NewReplyNotification.java - Copyright © 2010 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.notify; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import net.pterodactylus.sone.data.Reply; +import net.pterodactylus.util.notify.TemplateNotification; +import net.pterodactylus.util.template.Template; + +/** + * Notification that signals that new {@link Reply}s have been discovered. + * + * @author David ‘Bombe’ Roden + */ +public class NewReplyNotification extends TemplateNotification { + + /** The new replies. */ + private final List newReplies = Collections.synchronizedList(new ArrayList()); + + /** + * Creates a “new reply” notification. + * + * @param template + * The template to render + */ + public NewReplyNotification(Template template) { + super(template); + template.set("replies", newReplies); + } + + // + // ACCESSORS + // + + /** + * Returns whether there are any new replies. + * + * @return {@code true} if there are no new replies, {@code false} if there + * are new replies + */ + public boolean isEmpty() { + return newReplies.isEmpty(); + } + + /** + * Adds a discovered reply. + * + * @param reply + * The new reply + */ + public void addReply(Reply reply) { + newReplies.add(reply); + touch(); + } + + /** + * Removes the given reply from the list of new replies. + * + * @param reply + * The reply to remove + */ + public void removeReply(Reply reply) { + newReplies.remove(reply); + touch(); + } + + // + // ABSTRACTNOTIFICATION METHODS + // + + /** + * {@inheritDoc} + */ + @Override + public void dismiss() { + super.dismiss(); + newReplies.clear(); + } + +} diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 87f8238..115e0c3 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -38,6 +38,7 @@ import net.pterodactylus.sone.freenet.L10nFilter; import net.pterodactylus.sone.freenet.wot.Identity; import net.pterodactylus.sone.main.SonePlugin; import net.pterodactylus.sone.notify.NewPostNotification; +import net.pterodactylus.sone.notify.NewReplyNotification; import net.pterodactylus.sone.notify.NewSoneNotification; import net.pterodactylus.sone.template.CollectionAccessor; import net.pterodactylus.sone.template.CssClassNameFilter; @@ -114,6 +115,9 @@ public class WebInterface implements CoreListener { /** The “new post” notification. */ private final NewPostNotification newPostNotification; + /** The “new reply” notification. */ + private final NewReplyNotification newReplyNotification; + /** * Creates a new web interface. * @@ -150,6 +154,9 @@ public class WebInterface implements CoreListener { Template newPostNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/newPostNotification.html")); newPostNotification = new NewPostNotification(newPostNotificationTemplate); + + Template newReplyNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/newReplyNotification.html")); + newReplyNotification = new NewReplyNotification(newReplyNotificationTemplate); } // @@ -375,7 +382,8 @@ public class WebInterface implements CoreListener { */ @Override public void newReplyFound(Reply reply) { - /* TODO */ + newReplyNotification.addReply(reply); + notificationManager.addNotification(newReplyNotification); } /** @@ -405,7 +413,10 @@ public class WebInterface implements CoreListener { */ @Override public void markReplyKnown(Reply reply) { - /* TODO */ + newReplyNotification.removeReply(reply); + if (newReplyNotification.isEmpty()) { + newReplyNotification.dismiss(); + } } /** diff --git a/src/main/resources/i18n/sone.en.properties b/src/main/resources/i18n/sone.en.properties index eca813e..b4353b1 100644 --- a/src/main/resources/i18n/sone.en.properties +++ b/src/main/resources/i18n/sone.en.properties @@ -208,3 +208,4 @@ Notification.Startup.Text=Sone is currently starting up. It may take a while to Notification.Button.Dismiss=Dismiss Notification.NewSone.Text=New Sones have been discovered: Notification.NewPost.Text=New posts have been discovered by the following Sones: +Notification.NewReply.Text=New replies have been discovered by the following Sones: diff --git a/src/main/resources/templates/notify/newReplyNotification.html b/src/main/resources/templates/notify/newReplyNotification.html new file mode 100644 index 0000000..457e410 --- /dev/null +++ b/src/main/resources/templates/notify/newReplyNotification.html @@ -0,0 +1,6 @@ +
+ <%= Notification.NewReply.Text|l10n|html> + <%foreach replies reply> + <% reply.sone.niceName|html><%notlast>,<%/notlast><%last>.<%/last> + <%/foreach> +
-- 2.7.4