X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FWebInterface.java;h=06da982513a0d198ccaf9779033a3f9bb2b22766;hp=6807b35c4a93aab0621b8b20b7fa7324af487ee1;hb=89ab5e83e3fa9afb983093ac4ab8445f83348ea3;hpb=f083ad3957357d2f861e87128ee355e842c70762 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);