From: David ‘Bombe’ Roden Date: Fri, 1 Jul 2011 07:03:44 +0000 (+0200) Subject: Add Sone insert events to core listener. X-Git-Tag: 0.6.6^2~35 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=89ab5e83e3fa9afb983093ac4ab8445f83348ea3;p=Sone.git Add Sone insert events to core listener. --- diff --git a/src/main/java/net/pterodactylus/sone/core/CoreListener.java b/src/main/java/net/pterodactylus/sone/core/CoreListener.java index d34ac36..0e497e8 100644 --- a/src/main/java/net/pterodactylus/sone/core/CoreListener.java +++ b/src/main/java/net/pterodactylus/sone/core/CoreListener.java @@ -137,6 +137,38 @@ public interface CoreListener extends EventListener { public void soneUnlocked(Sone sone); /** + * Notifies a listener that the insert of the given Sone has started. + * + * @see SoneInsertListener#insertStarted(Sone) + * @param sone + * The Sone that is being inserted + */ + public void soneInserting(Sone sone); + + /** + * Notifies a listener that the insert of the given Sone has finished + * successfully. + * + * @see SoneInsertListener#insertFinished(Sone, long) + * @param sone + * The Sone that has been inserted + * @param insertDuration + * The insert duration (in milliseconds) + */ + public void soneInserted(Sone sone, long insertDuration); + + /** + * Notifies a listener that the insert of the given Sone was aborted. + * + * @see SoneInsertListener#insertAborted(Sone, Throwable) + * @param sone + * The Sone that was inserted + * @param cause + * The cause for the abortion (may be {@code null}) + */ + public void soneInsertAborted(Sone sone, Throwable cause); + + /** * Notifies a listener that a new version has been found. * * @param version diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 6807b35..06da982 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -184,6 +184,9 @@ public class WebInterface implements CoreListener { /** The “Sone rescued” notification. */ private final ListNotification sonesRescuedNotification; + /** Notifications for sone inserts. */ + private final Map soneInsertNotifications = new HashMap(); + /** Sone locked notification ticker objects. */ private final Map lockedSonesTickerObjects = Collections.synchronizedMap(new HashMap()); @@ -707,6 +710,27 @@ public class WebInterface implements CoreListener { return Filters.filteredSet(mentionedSones, Sone.LOCAL_SONE_FILTER); } + /** + * Returns the Sone insert notification for the given Sone. If no + * notification for the given Sone exists, a new notification is created and + * cached. + * + * @param sone + * The Sone to get the insert notification for + * @return The Sone insert notification + */ + private TemplateNotification getSoneInsertNotification(Sone sone) { + synchronized (soneInsertNotifications) { + TemplateNotification templateNotification = soneInsertNotifications.get(sone); + if (templateNotification == null) { + templateNotification = new TemplateNotification(TemplateParser.parse(createReader("/templates/notify/soneInsertNotification.html"))); + templateNotification.set("sone", sone); + soneInsertNotifications.put(sone, templateNotification); + } + return templateNotification; + } + } + // // CORELISTENER METHODS // @@ -870,6 +894,35 @@ public class WebInterface implements CoreListener { * {@inheritDoc} */ @Override + public void soneInserting(Sone sone) { + TemplateNotification soneInsertNotification = getSoneInsertNotification(sone); + soneInsertNotification.set("soneStatus", "inserting"); + notificationManager.addNotification(soneInsertNotification); + } + + /** + * {@inheritDoc} + */ + @Override + public void soneInserted(Sone sone, long insertDuration) { + TemplateNotification soneInsertNotification = getSoneInsertNotification(sone); + soneInsertNotification.set("soneStatus", "inserted"); + soneInsertNotification.set("insertDuration", insertDuration / 1000); + notificationManager.addNotification(soneInsertNotification); + } + + /** + * {@inheritDoc} + */ + @Override + public void soneInsertAborted(Sone sone, Throwable cause) { + notificationManager.addNotification(getSoneInsertNotification(sone).set("soneStatus", "insert-aborted").set("insert-error", cause)); + } + + /** + * {@inheritDoc} + */ + @Override public void updateFound(Version version, long releaseTime, long latestEdition) { newVersionNotification.getTemplateContext().set("latestVersion", version); newVersionNotification.getTemplateContext().set("latestEdition", latestEdition); diff --git a/src/main/resources/i18n/sone.en.properties b/src/main/resources/i18n/sone.en.properties index 2277936..43bff42 100644 --- a/src/main/resources/i18n/sone.en.properties +++ b/src/main/resources/i18n/sone.en.properties @@ -332,3 +332,4 @@ Notification.LockedSones.Text=The following Sones have been locked for more than Notification.NewVersion.Text=Version {version} of the Sone plugin was found. Download it from USK@nwa8lHa271k2QvJ8aa0Ov7IHAV-DFOCFgmDt3X6BpCI,DuQSUZiI~agF8c-6tjsFFGuZ8eICrzWCILB60nT8KKo,AQACAAE/sone/{edition}​! Notification.Mention.ShortText=You have been mentioned. Notification.Mention.Text=You have been mentioned in the following posts: +Notification.SoneInsert.Duration={0,number} {0,choice,0#seconds|1#second|1 + Your Sone <%sone.niceName|html> is now being inserted. +<%elseif soneStatus|match value="inserted"> + Your Sone <%sone.niceName|html> has been inserted in <%= Notification.SoneInsert.Duration|l10n 0=insertDuration>. +<%elseif soneStatus|match value="insert-aborted"> + Inserting your Sone <%sone.niceName|html> has failed. +<%/if> \ No newline at end of file