+ /**
+ * Notifies the web interface that a new {@link PostReply} was found.
+ *
+ * @param newPostReplyFoundEvent
+ * The event
+ */
+ @Subscribe
+ public void newReplyFound(NewPostReplyFoundEvent newPostReplyFoundEvent) {
+ PostReply reply = newPostReplyFoundEvent.postReply();
+ boolean isLocal = reply.getSone().isLocal();
+ if (isLocal) {
+ localReplyNotification.add(reply);
+ } else {
+ newReplyNotification.add(reply);
+ }
+ if (!hasFirstStartNotification()) {
+ notificationManager.addNotification(isLocal ? localReplyNotification : newReplyNotification);
+ if (!getMentionedSones(reply.getText()).isEmpty() && !isLocal && reply.getPost().isPresent() && (reply.getTime() <= System.currentTimeMillis())) {
+ mentionNotification.add(reply.getPost().get());
+ notificationManager.addNotification(mentionNotification);
+ }
+ } else {
+ reply.modify().setKnown().update(getCore().postReplyUpdated());
+ }
+ }
+
+ /**
+ * Notifies the web interface that a {@link Sone} was marked as known.
+ *
+ * @param markSoneKnownEvent
+ * The event
+ */
+ @Subscribe
+ public void markSoneKnown(MarkSoneKnownEvent markSoneKnownEvent) {
+ newSoneNotification.remove(markSoneKnownEvent.sone());
+ }
+
+ /**
+ * Notifies the web interface that a {@link Post} was marked as known.
+ *
+ * @param markPostKnownEvent
+ * The event
+ */
+ @Subscribe
+ public void markPostKnown(MarkPostKnownEvent markPostKnownEvent) {
+ newPostNotification.remove(markPostKnownEvent.post());
+ localPostNotification.remove(markPostKnownEvent.post());
+ mentionNotification.remove(markPostKnownEvent.post());
+ }
+
+ /**
+ * Notifies the web interface that a {@link PostReply} was marked as known.
+ *
+ * @param markPostReplyKnownEvent
+ * The event
+ */
+ @Subscribe
+ public void markReplyKnown(MarkPostReplyKnownEvent markPostReplyKnownEvent) {
+ newReplyNotification.remove(markPostReplyKnownEvent.postReply());
+ localReplyNotification.remove(markPostReplyKnownEvent.postReply());
+ mentionNotification.remove(markPostReplyKnownEvent.postReply().getPost().get());
+ }
+
+ /**
+ * Notifies the web interface that a {@link Sone} was removed.
+ *
+ * @param soneRemovedEvent
+ * The event
+ */
+ @Subscribe
+ public void soneRemoved(SoneRemovedEvent soneRemovedEvent) {
+ newSoneNotification.remove(soneRemovedEvent.sone());
+ }
+
+ /**
+ * Notifies the web interface that a {@link Post} was removed.
+ *
+ * @param postRemovedEvent
+ * The event
+ */
+ @Subscribe
+ public void postRemoved(PostRemovedEvent postRemovedEvent) {
+ newPostNotification.remove(postRemovedEvent.post());
+ localPostNotification.remove(postRemovedEvent.post());
+ mentionNotification.remove(postRemovedEvent.post());
+ }
+
+ /**
+ * Notifies the web interface that a {@link PostReply} was removed.
+ *
+ * @param postReplyRemovedEvent
+ * The event
+ */
+ @Subscribe
+ public void replyRemoved(PostReplyRemovedEvent postReplyRemovedEvent) {
+ PostReply reply = postReplyRemovedEvent.postReply();
+ newReplyNotification.remove(reply);
+ localReplyNotification.remove(reply);
+ if (!getMentionedSones(reply.getText()).isEmpty() && reply.getPost().isPresent()) {
+ boolean isMentioned = false;
+ for (PostReply existingReply : reply.getPost().transform(Post.TO_REPLIES).get()) {
+ isMentioned |= !reply.isKnown() && !getMentionedSones(existingReply.getText()).isEmpty();
+ }
+ if (!isMentioned) {
+ mentionNotification.remove(reply.getPost().get());
+ }
+ }
+ }
+
+ /**
+ * Notifies the web interface that a Sone was locked.
+ *
+ * @param soneLockedEvent
+ * The event
+ */
+ @Subscribe
+ public void soneLocked(SoneLockedEvent soneLockedEvent) {
+ final Sone sone = soneLockedEvent.sone();
+ ScheduledFuture<?> tickerObject = ticker.schedule(new Runnable() {
+
+ @Override
+ @SuppressWarnings("synthetic-access")
+ public void run() {
+ lockedSonesNotification.add(sone);
+ notificationManager.addNotification(lockedSonesNotification);
+ }
+ }, 5, TimeUnit.MINUTES);
+ lockedSonesTickerObjects.put(sone, tickerObject);
+ }
+
+ /**
+ * Notifies the web interface that a Sone was unlocked.
+ *
+ * @param soneUnlockedEvent
+ * The event
+ */
+ @Subscribe
+ public void soneUnlocked(SoneUnlockedEvent soneUnlockedEvent) {
+ lockedSonesNotification.remove(soneUnlockedEvent.sone());
+ lockedSonesTickerObjects.remove(soneUnlockedEvent.sone()).cancel(false);
+ }
+
+ /**
+ * Notifies the web interface that a {@link Sone} is being inserted.
+ *
+ * @param soneInsertingEvent
+ * The event
+ */
+ @Subscribe
+ public void soneInserting(SoneInsertingEvent soneInsertingEvent) {
+ TemplateNotification soneInsertNotification = getSoneInsertNotification(soneInsertingEvent.sone());
+ soneInsertNotification.set("soneStatus", "inserting");
+ if (soneInsertingEvent.sone().getOptions().getBooleanOption("EnableSoneInsertNotifications").get()) {
+ notificationManager.addNotification(soneInsertNotification);
+ }
+ }
+
+ /**
+ * Notifies the web interface that a {@link Sone} was inserted.
+ *
+ * @param soneInsertedEvent
+ * The event
+ */
+ @Subscribe
+ public void soneInserted(SoneInsertedEvent soneInsertedEvent) {
+ TemplateNotification soneInsertNotification = getSoneInsertNotification(soneInsertedEvent.sone());
+ soneInsertNotification.set("soneStatus", "inserted");
+ soneInsertNotification.set("insertDuration", soneInsertedEvent.insertDuration() / 1000);
+ if (soneInsertedEvent.sone().getOptions().getBooleanOption("EnableSoneInsertNotifications").get()) {
+ notificationManager.addNotification(soneInsertNotification);
+ }
+ }
+
+ /**
+ * Notifies the web interface that a {@link Sone} insert was aborted.
+ *
+ * @param soneInsertAbortedEvent
+ * The event
+ */
+ @Subscribe
+ public void soneInsertAborted(SoneInsertAbortedEvent soneInsertAbortedEvent) {
+ TemplateNotification soneInsertNotification = getSoneInsertNotification(soneInsertAbortedEvent.sone());
+ soneInsertNotification.set("soneStatus", "insert-aborted");
+ soneInsertNotification.set("insert-error", soneInsertAbortedEvent.cause());
+ if (soneInsertAbortedEvent.sone().getOptions().getBooleanOption("EnableSoneInsertNotifications").get()) {
+ notificationManager.addNotification(soneInsertNotification);
+ }
+ }
+
+ /**
+ * Notifies the web interface that a new Sone version was found.
+ *
+ * @param updateFoundEvent
+ * The event
+ */
+ @Subscribe
+ public void updateFound(UpdateFoundEvent updateFoundEvent) {
+ newVersionNotification.getTemplateContext().set("latestVersion", updateFoundEvent.version());
+ newVersionNotification.getTemplateContext().set("latestEdition", updateFoundEvent.latestEdition());
+ newVersionNotification.getTemplateContext().set("releaseTime", updateFoundEvent.releaseTime());
+ notificationManager.addNotification(newVersionNotification);
+ }
+
+ /**
+ * Notifies the web interface that an image insert was started
+ *
+ * @param imageInsertStartedEvent
+ * The event
+ */
+ @Subscribe
+ public void imageInsertStarted(ImageInsertStartedEvent imageInsertStartedEvent) {
+ insertingImagesNotification.add(imageInsertStartedEvent.image());
+ notificationManager.addNotification(insertingImagesNotification);
+ }
+
+ /**
+ * Notifies the web interface that an {@link Image} insert was aborted.
+ *
+ * @param imageInsertAbortedEvent
+ * The event
+ */
+ @Subscribe
+ public void imageInsertAborted(ImageInsertAbortedEvent imageInsertAbortedEvent) {
+ insertingImagesNotification.remove(imageInsertAbortedEvent.image());
+ }
+
+ /**
+ * Notifies the web interface that an {@link Image} insert is finished.
+ *
+ * @param imageInsertFinishedEvent
+ * The event
+ */
+ @Subscribe
+ public void imageInsertFinished(ImageInsertFinishedEvent imageInsertFinishedEvent) {
+ insertingImagesNotification.remove(imageInsertFinishedEvent.image());
+ insertedImagesNotification.add(imageInsertFinishedEvent.image());
+ notificationManager.addNotification(insertedImagesNotification);
+ }
+
+ /**
+ * Notifies the web interface that an {@link Image} insert has failed.
+ *
+ * @param imageInsertFailedEvent
+ * The event
+ */
+ @Subscribe
+ public void imageInsertFailed(ImageInsertFailedEvent imageInsertFailedEvent) {
+ insertingImagesNotification.remove(imageInsertFailedEvent.image());
+ imageInsertFailedNotification.add(imageInsertFailedEvent.image());
+ notificationManager.addNotification(imageInsertFailedNotification);
+ }
+