From f467b490759abac38d5a0c24cc6cda8df09ff1a7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 13 Dec 2010 20:27:49 +0100 Subject: [PATCH] Show a notification if a Sone is locked for more than five minutes. --- .../net/pterodactylus/sone/web/WebInterface.java | 32 ++++++++++++++++++++-- src/main/resources/i18n/sone.en.properties | 2 +- .../templates/notify/lockedSonesNotification.html | 6 ++++ 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 src/main/resources/templates/notify/lockedSonesNotification.html diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index a5376af..58962c4 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -23,8 +23,11 @@ import java.io.Reader; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.UUID; import java.util.logging.Level; @@ -132,6 +135,12 @@ public class WebInterface implements CoreListener { /** The “Sone rescued” notification. */ private final ListNotification sonesRescuedNotification; + /** Sone locked notification ticker objects. */ + private final Map lockedSonesTickerObjects = Collections.synchronizedMap(new HashMap()); + + /** The “Sone locked” notification. */ + private final ListNotification lockedSonesNotification; + /** * Creates a new web interface. * @@ -177,6 +186,9 @@ public class WebInterface implements CoreListener { Template sonesRescuedTemplate = templateFactory.createTemplate(createReader("/templates/notify/sonesRescuedNotification.html")); sonesRescuedNotification = new ListNotification("sones-rescued-notification", "sones", sonesRescuedTemplate); + + Template lockedSonesTemplate = templateFactory.createTemplate(createReader("/templates/notify/lockedSonesNotification.html")); + lockedSonesNotification = new ListNotification("sones-locked-notification", "sones", lockedSonesTemplate); } // @@ -650,8 +662,17 @@ public class WebInterface implements CoreListener { * {@inheritDoc} */ @Override - public void soneLocked(Sone sone) { - /* TODO */ + public void soneLocked(final Sone sone) { + Object tickerObject = Ticker.getInstance().registerEvent(System.currentTimeMillis() + (5 * 60) * 1000, new Runnable() { + + @Override + @SuppressWarnings("synthetic-access") + public void run() { + lockedSonesNotification.add(sone); + notificationManager.addNotification(lockedSonesNotification); + } + }, "Sone Locked Notification"); + lockedSonesTickerObjects.put(sone, tickerObject); } /** @@ -659,7 +680,12 @@ public class WebInterface implements CoreListener { */ @Override public void soneUnlocked(Sone sone) { - /* TODO */ + Object tickerObject = lockedSonesTickerObjects.remove(sone); + if (tickerObject == null) { + return; + } + lockedSonesNotification.remove(sone); + Ticker.getInstance().deregisterEvent(tickerObject); } /** diff --git a/src/main/resources/i18n/sone.en.properties b/src/main/resources/i18n/sone.en.properties index 89af2d1..e080e4d 100644 --- a/src/main/resources/i18n/sone.en.properties +++ b/src/main/resources/i18n/sone.en.properties @@ -186,4 +186,4 @@ Notification.NewReply.Text=New replies have been discovered by the following Son Notification.SoneIsBeingRescued.Text=The following Sones are currently being rescued: Notification.SoneRescued.Text=The following Sones have been rescued: Notification.SoneRescued.Text.RememberToUnlock=Please remember to control the posts and replies you have given and don’t forget to unlock your Sones! - +Notification.LockedSones.Text=The following Sones have been locked for more than 5 minutes. Please check if you really want to keep these Sones locked: diff --git a/src/main/resources/templates/notify/lockedSonesNotification.html b/src/main/resources/templates/notify/lockedSonesNotification.html new file mode 100644 index 0000000..b2b8b95 --- /dev/null +++ b/src/main/resources/templates/notify/lockedSonesNotification.html @@ -0,0 +1,6 @@ +
+ <%= Notification.LockedSones.Text|l10n|html> + <%foreach sones sone> + <% sone.niceName|html><%notlast>,<%/notlast><%last>.<%/last> + <%/foreach> +
-- 2.7.4