import java.util.Set;
import java.util.TimeZone;
import java.util.UUID;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.core.ElementLoader;
import net.pterodactylus.sone.core.event.*;
-import net.pterodactylus.sone.data.Image;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.PostReply;
import net.pterodactylus.sone.data.Sone;
/** Notifications for sone inserts. */
private final Map<Sone, TemplateNotification> soneInsertNotifications = new HashMap<>();
- /** The “inserting images” notification. */
- private final ListNotification<Image> insertingImagesNotification;
-
- /** The “inserted images” notification. */
- private final ListNotification<Image> insertedImagesNotification;
-
- /** The “image insert failed” notification. */
- private final ListNotification<Image> imageInsertFailedNotification;
-
- /** Scheduled executor for time-based notifications. */
- private final ScheduledExecutorService ticker = Executors.newScheduledThreadPool(1);
-
@Inject
public WebInterface(SonePlugin sonePlugin, Loaders loaders, ListNotificationFilter listNotificationFilter,
PostVisibilityFilter postVisibilityFilter, ReplyVisibilityFilter replyVisibilityFilter,
Template mentionNotificationTemplate = loaders.loadTemplate("/templates/notify/mentionNotification.html");
mentionNotification = new ListNotification<>("mention-notification", "posts", mentionNotificationTemplate, false);
-
- Template insertingImagesTemplate = loaders.loadTemplate("/templates/notify/inserting-images-notification.html");
- insertingImagesNotification = new ListNotification<>("inserting-images-notification", "images", insertingImagesTemplate);
-
- Template insertedImagesTemplate = loaders.loadTemplate("/templates/notify/inserted-images-notification.html");
- insertedImagesNotification = new ListNotification<>("inserted-images-notification", "images", insertedImagesTemplate);
-
- Template imageInsertFailedTemplate = loaders.loadTemplate("/templates/notify/image-insert-failed-notification.html");
- imageInsertFailedNotification = new ListNotification<>("image-insert-failed-notification", "images", imageInsertFailedTemplate);
}
//
return from(allNewReplies).filter(replyVisibilityFilter.isVisible(currentSone)).toSet();
}
- /**
- * Sets whether the current start of the plugin is the first start. It is
- * considered a first start if the configuration file does not exist.
- *
- * @param firstStart
- * {@code true} if no configuration file existed when Sone was
- * loaded, {@code false} otherwise
- */
- public void setFirstStart(boolean firstStart) {
- if (firstStart) {
- Template firstStartNotificationTemplate = loaders.loadTemplate("/templates/notify/firstStartNotification.html");
- Notification firstStartNotification = new TemplateNotification("first-start-notification", firstStartNotificationTemplate);
- notificationManager.addNotification(firstStartNotification);
- }
- }
-
- /**
- * Sets whether Sone was started with a fresh configuration file.
- *
- * @param newConfig
- * {@code true} if Sone was started with a fresh configuration,
- * {@code false} if the existing configuration could be read
- */
- public void setNewConfig(boolean newConfig) {
- if (newConfig && !hasFirstStartNotification()) {
- Template configNotReadNotificationTemplate = loaders.loadTemplate("/templates/notify/configNotReadNotification.html");
- Notification configNotReadNotification = new TemplateNotification("config-not-read-notification", configNotReadNotificationTemplate);
- notificationManager.addNotification(configNotReadNotification);
- }
- }
-
//
// PRIVATE ACCESSORS
//
*/
public void start() {
registerToadlets();
-
- /* notification templates. */
- Template startupNotificationTemplate = loaders.loadTemplate("/templates/notify/startupNotification.html");
-
- final TemplateNotification startupNotification = new TemplateNotification("startup-notification", startupNotificationTemplate);
- notificationManager.addNotification(startupNotification);
-
- ticker.schedule(new Runnable() {
-
- @Override
- public void run() {
- startupNotification.dismiss();
- }
- }, 2, TimeUnit.MINUTES);
-
- Template wotMissingNotificationTemplate = loaders.loadTemplate("/templates/notify/wotMissingNotification.html");
- final TemplateNotification wotMissingNotification = new TemplateNotification("wot-missing-notification", wotMissingNotificationTemplate);
- ticker.scheduleAtFixedRate(new Runnable() {
-
- @Override
- @SuppressWarnings("synthetic-access")
- public void run() {
- if (getCore().getIdentityManager().isConnected()) {
- wotMissingNotification.dismiss();
- } else {
- notificationManager.addNotification(wotMissingNotification);
- }
- }
-
- }, 15, 15, TimeUnit.SECONDS);
}
/**
*/
public void stop() {
pageToadletRegistry.unregisterToadlets();
- ticker.shutdownNow();
}
//
}
}
- /**
- * Notifies the web interface that an image insert was started
- *
- * @param imageInsertStartedEvent
- * The event
- */
- @Subscribe
- public void imageInsertStarted(ImageInsertStartedEvent imageInsertStartedEvent) {
- insertingImagesNotification.add(imageInsertStartedEvent.getImage());
- 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.getImage());
- }
-
- /**
- * Notifies the web interface that an {@link Image} insert is finished.
- *
- * @param imageInsertFinishedEvent
- * The event
- */
- @Subscribe
- public void imageInsertFinished(ImageInsertFinishedEvent imageInsertFinishedEvent) {
- insertingImagesNotification.remove(imageInsertFinishedEvent.getImage());
- insertedImagesNotification.add(imageInsertFinishedEvent.getImage());
- 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.getImage());
- imageInsertFailedNotification.add(imageInsertFailedEvent.getImage());
- notificationManager.addNotification(imageInsertFailedNotification);
- }
-
@Subscribe
public void debugActivated(@Nonnull DebugActivatedEvent debugActivatedEvent) {
pageToadletRegistry.activateDebugMode();