2 * Sone - WebInterface.java - Copyright © 2010–2016 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.web;
20 import static com.google.common.collect.FluentIterable.from;
21 import static java.util.logging.Logger.getLogger;
22 import static net.pterodactylus.util.template.TemplateParser.parse;
24 import java.io.StringReader;
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.Collections;
28 import java.util.HashMap;
29 import java.util.HashSet;
30 import java.util.List;
33 import java.util.UUID;
34 import java.util.concurrent.Executors;
35 import java.util.concurrent.ScheduledExecutorService;
36 import java.util.concurrent.ScheduledFuture;
37 import java.util.concurrent.TimeUnit;
38 import java.util.logging.Logger;
39 import javax.annotation.Nonnull;
40 import javax.annotation.Nullable;
42 import net.pterodactylus.sone.core.Core;
43 import net.pterodactylus.sone.core.ElementLoader;
44 import net.pterodactylus.sone.core.event.ImageInsertAbortedEvent;
45 import net.pterodactylus.sone.core.event.ImageInsertFailedEvent;
46 import net.pterodactylus.sone.core.event.ImageInsertFinishedEvent;
47 import net.pterodactylus.sone.core.event.ImageInsertStartedEvent;
48 import net.pterodactylus.sone.core.event.MarkPostKnownEvent;
49 import net.pterodactylus.sone.core.event.MarkPostReplyKnownEvent;
50 import net.pterodactylus.sone.core.event.MarkSoneKnownEvent;
51 import net.pterodactylus.sone.core.event.NewPostFoundEvent;
52 import net.pterodactylus.sone.core.event.NewPostReplyFoundEvent;
53 import net.pterodactylus.sone.core.event.NewSoneFoundEvent;
54 import net.pterodactylus.sone.core.event.PostRemovedEvent;
55 import net.pterodactylus.sone.core.event.PostReplyRemovedEvent;
56 import net.pterodactylus.sone.core.event.SoneInsertAbortedEvent;
57 import net.pterodactylus.sone.core.event.SoneInsertedEvent;
58 import net.pterodactylus.sone.core.event.SoneInsertingEvent;
59 import net.pterodactylus.sone.core.event.SoneLockedEvent;
60 import net.pterodactylus.sone.core.event.SoneRemovedEvent;
61 import net.pterodactylus.sone.core.event.SoneUnlockedEvent;
62 import net.pterodactylus.sone.core.event.UpdateFoundEvent;
63 import net.pterodactylus.sone.data.Album;
64 import net.pterodactylus.sone.data.Image;
65 import net.pterodactylus.sone.data.Post;
66 import net.pterodactylus.sone.data.PostReply;
67 import net.pterodactylus.sone.data.Profile;
68 import net.pterodactylus.sone.data.Reply;
69 import net.pterodactylus.sone.data.Sone;
70 import net.pterodactylus.sone.freenet.L10nFilter;
71 import net.pterodactylus.sone.freenet.wot.Identity;
72 import net.pterodactylus.sone.freenet.wot.Trust;
73 import net.pterodactylus.sone.main.Loaders;
74 import net.pterodactylus.sone.main.ReparseFilter;
75 import net.pterodactylus.sone.main.SonePlugin;
76 import net.pterodactylus.sone.main.SonePlugin.PluginHomepage;
77 import net.pterodactylus.sone.main.SonePlugin.PluginVersion;
78 import net.pterodactylus.sone.main.SonePlugin.PluginYear;
79 import net.pterodactylus.sone.notify.ListNotification;
80 import net.pterodactylus.sone.notify.ListNotificationFilter;
81 import net.pterodactylus.sone.notify.PostVisibilityFilter;
82 import net.pterodactylus.sone.notify.ReplyVisibilityFilter;
83 import net.pterodactylus.sone.template.AlbumAccessor;
84 import net.pterodactylus.sone.template.CollectionAccessor;
85 import net.pterodactylus.sone.template.CssClassNameFilter;
86 import net.pterodactylus.sone.template.HttpRequestAccessor;
87 import net.pterodactylus.sone.template.IdentityAccessor;
88 import net.pterodactylus.sone.template.ImageAccessor;
89 import net.pterodactylus.sone.template.ImageLinkFilter;
90 import net.pterodactylus.sone.template.JavascriptFilter;
91 import net.pterodactylus.sone.template.LinkedElementRenderFilter;
92 import net.pterodactylus.sone.template.LinkedElementsFilter;
93 import net.pterodactylus.sone.template.ParserFilter;
94 import net.pterodactylus.sone.template.PostAccessor;
95 import net.pterodactylus.sone.template.ProfileAccessor;
96 import net.pterodactylus.sone.template.RenderFilter;
97 import net.pterodactylus.sone.template.ReplyAccessor;
98 import net.pterodactylus.sone.template.ReplyGroupFilter;
99 import net.pterodactylus.sone.template.RequestChangeFilter;
100 import net.pterodactylus.sone.template.ShortenFilter;
101 import net.pterodactylus.sone.template.SoneAccessor;
102 import net.pterodactylus.sone.template.SubstringFilter;
103 import net.pterodactylus.sone.template.TrustAccessor;
104 import net.pterodactylus.sone.template.UniqueElementFilter;
105 import net.pterodactylus.sone.template.UnknownDateFilter;
106 import net.pterodactylus.sone.text.Part;
107 import net.pterodactylus.sone.text.SonePart;
108 import net.pterodactylus.sone.text.SoneTextParser;
109 import net.pterodactylus.sone.text.TimeTextConverter;
110 import net.pterodactylus.sone.web.ajax.BookmarkAjaxPage;
111 import net.pterodactylus.sone.web.ajax.CreatePostAjaxPage;
112 import net.pterodactylus.sone.web.ajax.CreateReplyAjaxPage;
113 import net.pterodactylus.sone.web.ajax.DeletePostAjaxPage;
114 import net.pterodactylus.sone.web.ajax.DeleteProfileFieldAjaxPage;
115 import net.pterodactylus.sone.web.ajax.DeleteReplyAjaxPage;
116 import net.pterodactylus.sone.web.ajax.DismissNotificationAjaxPage;
117 import net.pterodactylus.sone.web.ajax.DistrustAjaxPage;
118 import net.pterodactylus.sone.web.ajax.EditAlbumAjaxPage;
119 import net.pterodactylus.sone.web.ajax.EditImageAjaxPage;
120 import net.pterodactylus.sone.web.ajax.EditProfileFieldAjaxPage;
121 import net.pterodactylus.sone.web.ajax.FollowSoneAjaxPage;
122 import net.pterodactylus.sone.web.ajax.GetLikesAjaxPage;
123 import net.pterodactylus.sone.web.ajax.GetLinkedElementAjaxPage;
124 import net.pterodactylus.sone.web.ajax.GetNotificationsAjaxPage;
125 import net.pterodactylus.sone.web.ajax.GetPostAjaxPage;
126 import net.pterodactylus.sone.web.ajax.GetReplyAjaxPage;
127 import net.pterodactylus.sone.web.ajax.GetStatusAjaxPage;
128 import net.pterodactylus.sone.web.ajax.GetTimesAjaxPage;
129 import net.pterodactylus.sone.web.ajax.GetTranslationPage;
130 import net.pterodactylus.sone.web.ajax.LikeAjaxPage;
131 import net.pterodactylus.sone.web.ajax.LockSoneAjaxPage;
132 import net.pterodactylus.sone.web.ajax.MarkAsKnownAjaxPage;
133 import net.pterodactylus.sone.web.ajax.MoveProfileFieldAjaxPage;
134 import net.pterodactylus.sone.web.ajax.TrustAjaxPage;
135 import net.pterodactylus.sone.web.ajax.UnbookmarkAjaxPage;
136 import net.pterodactylus.sone.web.ajax.UnfollowSoneAjaxPage;
137 import net.pterodactylus.sone.web.ajax.UnlikeAjaxPage;
138 import net.pterodactylus.sone.web.ajax.UnlockSoneAjaxPage;
139 import net.pterodactylus.sone.web.ajax.UntrustAjaxPage;
140 import net.pterodactylus.sone.web.page.FreenetRequest;
141 import net.pterodactylus.sone.web.page.PageToadlet;
142 import net.pterodactylus.sone.web.page.PageToadletFactory;
143 import net.pterodactylus.util.notify.Notification;
144 import net.pterodactylus.util.notify.NotificationManager;
145 import net.pterodactylus.util.notify.TemplateNotification;
146 import net.pterodactylus.util.template.CollectionSortFilter;
147 import net.pterodactylus.util.template.ContainsFilter;
148 import net.pterodactylus.util.template.DateFilter;
149 import net.pterodactylus.util.template.FormatFilter;
150 import net.pterodactylus.util.template.HtmlFilter;
151 import net.pterodactylus.util.template.MatchFilter;
152 import net.pterodactylus.util.template.ModFilter;
153 import net.pterodactylus.util.template.PaginationFilter;
154 import net.pterodactylus.util.template.ReflectionAccessor;
155 import net.pterodactylus.util.template.ReplaceFilter;
156 import net.pterodactylus.util.template.StoreFilter;
157 import net.pterodactylus.util.template.Template;
158 import net.pterodactylus.util.template.TemplateContextFactory;
159 import net.pterodactylus.util.template.TemplateProvider;
160 import net.pterodactylus.util.template.XmlFilter;
161 import net.pterodactylus.util.web.RedirectPage;
162 import net.pterodactylus.util.web.TemplatePage;
164 import freenet.clients.http.SessionManager;
165 import freenet.clients.http.SessionManager.Session;
166 import freenet.clients.http.ToadletContainer;
167 import freenet.clients.http.ToadletContext;
168 import freenet.l10n.BaseL10n;
169 import freenet.support.api.HTTPRequest;
171 import com.google.common.base.Optional;
172 import com.google.common.collect.Collections2;
173 import com.google.common.collect.ImmutableSet;
174 import com.google.common.eventbus.Subscribe;
175 import com.google.inject.Inject;
178 * Bundles functionality that a web interface of a Freenet plugin needs, e.g.
179 * references to l10n helpers.
181 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
183 public class WebInterface {
186 private static final Logger logger = getLogger(WebInterface.class.getName());
188 /** The loaders for templates, pages, and classpath providers. */
189 private final Loaders loaders;
191 /** The notification manager. */
192 private final NotificationManager notificationManager = new NotificationManager();
194 /** The Sone plugin. */
195 private final SonePlugin sonePlugin;
197 /** The registered toadlets. */
198 private final List<PageToadlet> pageToadlets = new ArrayList<PageToadlet>();
200 /** The form password. */
201 private final String formPassword;
203 /** The template context factory. */
204 private final TemplateContextFactory templateContextFactory;
206 /** The Sone text parser. */
207 private final SoneTextParser soneTextParser;
209 /** The parser filter. */
210 private final ParserFilter parserFilter;
211 private final ShortenFilter shortenFilter;
212 private final RenderFilter renderFilter;
214 private final ListNotificationFilter listNotificationFilter;
215 private final PostVisibilityFilter postVisibilityFilter;
216 private final ReplyVisibilityFilter replyVisibilityFilter;
218 private final ElementLoader elementLoader;
219 private final LinkedElementRenderFilter linkedElementRenderFilter;
220 private final TimeTextConverter timeTextConverter = new TimeTextConverter();
221 private final L10nFilter l10nFilter = new L10nFilter(this);
223 /** The “new Sone” notification. */
224 private final ListNotification<Sone> newSoneNotification;
226 /** The “new post” notification. */
227 private final ListNotification<Post> newPostNotification;
229 /** The “new reply” notification. */
230 private final ListNotification<PostReply> newReplyNotification;
232 /** The invisible “local post” notification. */
233 private final ListNotification<Post> localPostNotification;
235 /** The invisible “local reply” notification. */
236 private final ListNotification<PostReply> localReplyNotification;
238 /** The “you have been mentioned” notification. */
239 private final ListNotification<Post> mentionNotification;
241 /** Notifications for sone inserts. */
242 private final Map<Sone, TemplateNotification> soneInsertNotifications = new HashMap<Sone, TemplateNotification>();
244 /** Sone locked notification ticker objects. */
245 private final Map<Sone, ScheduledFuture<?>> lockedSonesTickerObjects = Collections.synchronizedMap(new HashMap<Sone, ScheduledFuture<?>>());
247 /** The “Sone locked” notification. */
248 private final ListNotification<Sone> lockedSonesNotification;
250 /** The “new version” notification. */
251 private final TemplateNotification newVersionNotification;
253 /** The “inserting images” notification. */
254 private final ListNotification<Image> insertingImagesNotification;
256 /** The “inserted images” notification. */
257 private final ListNotification<Image> insertedImagesNotification;
259 /** The “image insert failed” notification. */
260 private final ListNotification<Image> imageInsertFailedNotification;
262 /** Scheduled executor for time-based notifications. */
263 private final ScheduledExecutorService ticker = Executors.newScheduledThreadPool(1);
266 * Creates a new web interface.
272 public WebInterface(SonePlugin sonePlugin, Loaders loaders, ListNotificationFilter listNotificationFilter, PostVisibilityFilter postVisibilityFilter, ReplyVisibilityFilter replyVisibilityFilter, ElementLoader elementLoader) {
273 this.sonePlugin = sonePlugin;
274 this.loaders = loaders;
275 this.listNotificationFilter = listNotificationFilter;
276 this.postVisibilityFilter = postVisibilityFilter;
277 this.replyVisibilityFilter = replyVisibilityFilter;
278 this.elementLoader = elementLoader;
279 formPassword = sonePlugin.pluginRespirator().getToadletContainer().getFormPassword();
280 soneTextParser = new SoneTextParser(getCore(), getCore());
282 templateContextFactory = new TemplateContextFactory();
283 templateContextFactory.addAccessor(Object.class, new ReflectionAccessor());
284 templateContextFactory.addAccessor(Collection.class, new CollectionAccessor());
285 templateContextFactory.addAccessor(Sone.class, new SoneAccessor(getCore(), new TimeTextConverter()));
286 templateContextFactory.addAccessor(Post.class, new PostAccessor(getCore()));
287 templateContextFactory.addAccessor(Reply.class, new ReplyAccessor(getCore()));
288 templateContextFactory.addAccessor(Album.class, new AlbumAccessor());
289 templateContextFactory.addAccessor(Image.class, new ImageAccessor());
290 templateContextFactory.addAccessor(Identity.class, new IdentityAccessor(getCore()));
291 templateContextFactory.addAccessor(Trust.class, new TrustAccessor());
292 templateContextFactory.addAccessor(HTTPRequest.class, new HttpRequestAccessor());
293 templateContextFactory.addAccessor(Profile.class, new ProfileAccessor(getCore()));
294 templateContextFactory.addFilter("date", new DateFilter());
295 templateContextFactory.addFilter("html", new HtmlFilter());
296 templateContextFactory.addFilter("replace", new ReplaceFilter());
297 templateContextFactory.addFilter("store", new StoreFilter());
298 templateContextFactory.addFilter("l10n", new L10nFilter(this));
299 templateContextFactory.addFilter("substring", new SubstringFilter());
300 templateContextFactory.addFilter("xml", new XmlFilter());
301 templateContextFactory.addFilter("change", new RequestChangeFilter());
302 templateContextFactory.addFilter("match", new MatchFilter());
303 templateContextFactory.addFilter("css", new CssClassNameFilter());
304 templateContextFactory.addFilter("js", new JavascriptFilter());
305 templateContextFactory.addFilter("parse", parserFilter = new ParserFilter(getCore(), soneTextParser));
306 templateContextFactory.addFilter("shorten", shortenFilter = new ShortenFilter());
307 templateContextFactory.addFilter("render", renderFilter = new RenderFilter(getCore(), templateContextFactory));
308 templateContextFactory.addFilter("linked-elements", new LinkedElementsFilter(elementLoader));
309 templateContextFactory.addFilter("render-linked-element", linkedElementRenderFilter = new LinkedElementRenderFilter(templateContextFactory));
310 templateContextFactory.addFilter("reparse", new ReparseFilter());
311 templateContextFactory.addFilter("unknown", new UnknownDateFilter(getL10n(), "View.Sone.Text.UnknownDate"));
312 templateContextFactory.addFilter("format", new FormatFilter());
313 templateContextFactory.addFilter("sort", new CollectionSortFilter());
314 templateContextFactory.addFilter("image-link", new ImageLinkFilter(getCore(), templateContextFactory));
315 templateContextFactory.addFilter("replyGroup", new ReplyGroupFilter());
316 templateContextFactory.addFilter("in", new ContainsFilter());
317 templateContextFactory.addFilter("unique", new UniqueElementFilter());
318 templateContextFactory.addFilter("mod", new ModFilter());
319 templateContextFactory.addFilter("paginate", new PaginationFilter());
320 templateContextFactory.addProvider(TemplateProvider.TEMPLATE_CONTEXT_PROVIDER);
321 templateContextFactory.addProvider(loaders.getTemplateProvider());
322 templateContextFactory.addTemplateObject("webInterface", this);
323 templateContextFactory.addTemplateObject("formPassword", formPassword);
325 /* create notifications. */
326 Template newSoneNotificationTemplate = loaders.loadTemplate("/templates/notify/newSoneNotification.html");
327 newSoneNotification = new ListNotification<Sone>("new-sone-notification", "sones", newSoneNotificationTemplate, false);
329 Template newPostNotificationTemplate = loaders.loadTemplate("/templates/notify/newPostNotification.html");
330 newPostNotification = new ListNotification<Post>("new-post-notification", "posts", newPostNotificationTemplate, false);
332 Template localPostNotificationTemplate = loaders.loadTemplate("/templates/notify/newPostNotification.html");
333 localPostNotification = new ListNotification<Post>("local-post-notification", "posts", localPostNotificationTemplate, false);
335 Template newReplyNotificationTemplate = loaders.loadTemplate("/templates/notify/newReplyNotification.html");
336 newReplyNotification = new ListNotification<PostReply>("new-reply-notification", "replies", newReplyNotificationTemplate, false);
338 Template localReplyNotificationTemplate = loaders.loadTemplate("/templates/notify/newReplyNotification.html");
339 localReplyNotification = new ListNotification<PostReply>("local-reply-notification", "replies", localReplyNotificationTemplate, false);
341 Template mentionNotificationTemplate = loaders.loadTemplate("/templates/notify/mentionNotification.html");
342 mentionNotification = new ListNotification<Post>("mention-notification", "posts", mentionNotificationTemplate, false);
344 Template lockedSonesTemplate = loaders.loadTemplate("/templates/notify/lockedSonesNotification.html");
345 lockedSonesNotification = new ListNotification<Sone>("sones-locked-notification", "sones", lockedSonesTemplate);
347 Template newVersionTemplate = loaders.loadTemplate("/templates/notify/newVersionNotification.html");
348 newVersionNotification = new TemplateNotification("new-version-notification", newVersionTemplate);
350 Template insertingImagesTemplate = loaders.loadTemplate("/templates/notify/inserting-images-notification.html");
351 insertingImagesNotification = new ListNotification<Image>("inserting-images-notification", "images", insertingImagesTemplate);
353 Template insertedImagesTemplate = loaders.loadTemplate("/templates/notify/inserted-images-notification.html");
354 insertedImagesNotification = new ListNotification<Image>("inserted-images-notification", "images", insertedImagesTemplate);
356 Template imageInsertFailedTemplate = loaders.loadTemplate("/templates/notify/image-insert-failed-notification.html");
357 imageInsertFailedNotification = new ListNotification<Image>("image-insert-failed-notification", "images", imageInsertFailedTemplate);
365 * Returns the Sone core used by the Sone plugin.
367 * @return The Sone core
369 public Core getCore() {
370 return sonePlugin.core();
374 * Returns the template context factory of the web interface.
376 * @return The template context factory
378 public TemplateContextFactory getTemplateContextFactory() {
379 return templateContextFactory;
382 private Session getCurrentSessionWithoutCreation(ToadletContext toadletContenxt) {
383 return getSessionManager().useSession(toadletContenxt);
386 private Session getOrCreateCurrentSession(ToadletContext toadletContenxt) {
387 Session session = getCurrentSessionWithoutCreation(toadletContenxt);
388 if (session == null) {
389 session = getSessionManager().createSession(UUID.randomUUID().toString(), toadletContenxt);
394 public Sone getCurrentSoneCreatingSession(ToadletContext toadletContext) {
395 Collection<Sone> localSones = getCore().getLocalSones();
396 if (localSones.size() == 1) {
397 return localSones.iterator().next();
399 return getCurrentSone(getOrCreateCurrentSession(toadletContext));
402 public Sone getCurrentSoneWithoutCreatingSession(ToadletContext toadletContext) {
403 Collection<Sone> localSones = getCore().getLocalSones();
404 if (localSones.size() == 1) {
405 return localSones.iterator().next();
407 return getCurrentSone(getCurrentSessionWithoutCreation(toadletContext));
411 * Returns the currently logged in Sone.
415 * @return The currently logged in Sone, or {@code null} if no Sone is
416 * currently logged in
418 private Sone getCurrentSone(Session session) {
419 if (session == null) {
422 String soneId = (String) session.getAttribute("Sone.CurrentSone");
423 if (soneId == null) {
426 return getCore().getLocalSone(soneId);
430 * Sets the currently logged in Sone.
432 * @param toadletContext
433 * The toadlet context
435 * The Sone to set as currently logged in
437 public void setCurrentSone(ToadletContext toadletContext, Sone sone) {
438 Session session = getOrCreateCurrentSession(toadletContext);
440 session.removeAttribute("Sone.CurrentSone");
442 session.setAttribute("Sone.CurrentSone", sone.getId());
447 * Returns the notification manager.
449 * @return The notification manager
451 public NotificationManager getNotifications() {
452 return notificationManager;
456 public Optional<Notification> getNotification(@Nonnull String notificationId) {
457 return Optional.fromNullable(notificationManager.getNotification(notificationId));
461 public Collection<Notification> getNotifications(@Nullable Sone currentSone) {
462 return listNotificationFilter.filterNotifications(notificationManager.getNotifications(), currentSone);
466 * Returns the l10n helper of the node.
468 * @return The node’s l10n helper
470 public BaseL10n getL10n() {
471 return sonePlugin.l10n().getBase();
475 * Returns the session manager of the node.
477 * @return The node’s session manager
479 public SessionManager getSessionManager() {
480 return sonePlugin.pluginRespirator().getSessionManager("Sone");
484 * Returns the node’s form password.
486 * @return The form password
488 public String getFormPassword() {
493 * Returns the posts that have been announced as new in the
494 * {@link #newPostNotification}.
496 * @return The new posts
498 public Set<Post> getNewPosts() {
499 return ImmutableSet.<Post> builder().addAll(newPostNotification.getElements()).addAll(localPostNotification.getElements()).build();
503 public Collection<Post> getNewPosts(@Nullable Sone currentSone) {
504 Set<Post> allNewPosts = ImmutableSet.<Post> builder()
505 .addAll(newPostNotification.getElements())
506 .addAll(localPostNotification.getElements())
508 return from(allNewPosts).filter(postVisibilityFilter.isVisible(currentSone)).toSet();
512 * Returns the replies that have been announced as new in the
513 * {@link #newReplyNotification}.
515 * @return The new replies
517 public Set<PostReply> getNewReplies() {
518 return ImmutableSet.<PostReply> builder().addAll(newReplyNotification.getElements()).addAll(localReplyNotification.getElements()).build();
522 public Collection<PostReply> getNewReplies(@Nullable Sone currentSone) {
523 Set<PostReply> allNewReplies = ImmutableSet.<PostReply>builder()
524 .addAll(newReplyNotification.getElements())
525 .addAll(localReplyNotification.getElements())
527 return from(allNewReplies).filter(replyVisibilityFilter.isVisible(currentSone)).toSet();
531 * Sets whether the current start of the plugin is the first start. It is
532 * considered a first start if the configuration file does not exist.
535 * {@code true} if no configuration file existed when Sone was
536 * loaded, {@code false} otherwise
538 public void setFirstStart(boolean firstStart) {
540 Template firstStartNotificationTemplate = loaders.loadTemplate("/templates/notify/firstStartNotification.html");
541 Notification firstStartNotification = new TemplateNotification("first-start-notification", firstStartNotificationTemplate);
542 notificationManager.addNotification(firstStartNotification);
547 * Sets whether Sone was started with a fresh configuration file.
550 * {@code true} if Sone was started with a fresh configuration,
551 * {@code false} if the existing configuration could be read
553 public void setNewConfig(boolean newConfig) {
554 if (newConfig && !hasFirstStartNotification()) {
555 Template configNotReadNotificationTemplate = loaders.loadTemplate("/templates/notify/configNotReadNotification.html");
556 Notification configNotReadNotification = new TemplateNotification("config-not-read-notification", configNotReadNotificationTemplate);
557 notificationManager.addNotification(configNotReadNotification);
566 * Returns whether the first start notification is currently displayed.
568 * @return {@code true} if the first-start notification is currently
569 * displayed, {@code false} otherwise
571 private boolean hasFirstStartNotification() {
572 return notificationManager.getNotification("first-start-notification") != null;
580 * Starts the web interface and registers all toadlets.
582 public void start() {
585 /* notification templates. */
586 Template startupNotificationTemplate = loaders.loadTemplate("/templates/notify/startupNotification.html");
588 final TemplateNotification startupNotification = new TemplateNotification("startup-notification", startupNotificationTemplate);
589 notificationManager.addNotification(startupNotification);
591 ticker.schedule(new Runnable() {
595 startupNotification.dismiss();
597 }, 2, TimeUnit.MINUTES);
599 Template wotMissingNotificationTemplate = loaders.loadTemplate("/templates/notify/wotMissingNotification.html");
600 final TemplateNotification wotMissingNotification = new TemplateNotification("wot-missing-notification", wotMissingNotificationTemplate);
601 ticker.scheduleAtFixedRate(new Runnable() {
604 @SuppressWarnings("synthetic-access")
606 if (getCore().getIdentityManager().isConnected()) {
607 wotMissingNotification.dismiss();
609 notificationManager.addNotification(wotMissingNotification);
613 }, 15, 15, TimeUnit.SECONDS);
617 * Stops the web interface and unregisters all toadlets.
620 unregisterToadlets();
621 ticker.shutdownNow();
629 * Register all toadlets.
631 private void registerToadlets() {
632 Template emptyTemplate = parse(new StringReader(""));
633 Template loginTemplate = loaders.loadTemplate("/templates/login.html");
634 Template indexTemplate = loaders.loadTemplate("/templates/index.html");
635 Template newTemplate = loaders.loadTemplate("/templates/new.html");
636 Template knownSonesTemplate = loaders.loadTemplate("/templates/knownSones.html");
637 Template createSoneTemplate = loaders.loadTemplate("/templates/createSone.html");
638 Template createPostTemplate = loaders.loadTemplate("/templates/createPost.html");
639 Template createReplyTemplate = loaders.loadTemplate("/templates/createReply.html");
640 Template bookmarksTemplate = loaders.loadTemplate("/templates/bookmarks.html");
641 Template searchTemplate = loaders.loadTemplate("/templates/search.html");
642 Template editProfileTemplate = loaders.loadTemplate("/templates/editProfile.html");
643 Template editProfileFieldTemplate = loaders.loadTemplate("/templates/editProfileField.html");
644 Template deleteProfileFieldTemplate = loaders.loadTemplate("/templates/deleteProfileField.html");
645 Template viewSoneTemplate = loaders.loadTemplate("/templates/viewSone.html");
646 Template viewPostTemplate = loaders.loadTemplate("/templates/viewPost.html");
647 Template deletePostTemplate = loaders.loadTemplate("/templates/deletePost.html");
648 Template deleteReplyTemplate = loaders.loadTemplate("/templates/deleteReply.html");
649 Template deleteSoneTemplate = loaders.loadTemplate("/templates/deleteSone.html");
650 Template imageBrowserTemplate = loaders.loadTemplate("/templates/imageBrowser.html");
651 Template createAlbumTemplate = loaders.loadTemplate("/templates/createAlbum.html");
652 Template deleteAlbumTemplate = loaders.loadTemplate("/templates/deleteAlbum.html");
653 Template deleteImageTemplate = loaders.loadTemplate("/templates/deleteImage.html");
654 Template noPermissionTemplate = loaders.loadTemplate("/templates/noPermission.html");
655 Template emptyImageTitleTemplate = loaders.loadTemplate("/templates/emptyImageTitle.html");
656 Template emptyAlbumTitleTemplate = loaders.loadTemplate("/templates/emptyAlbumTitle.html");
657 Template optionsTemplate = loaders.loadTemplate("/templates/options.html");
658 Template rescueTemplate = loaders.loadTemplate("/templates/rescue.html");
659 Template aboutTemplate = loaders.loadTemplate("/templates/about.html");
660 Template invalidTemplate = loaders.loadTemplate("/templates/invalid.html");
661 Template postTemplate = loaders.loadTemplate("/templates/include/viewPost.html");
662 Template replyTemplate = loaders.loadTemplate("/templates/include/viewReply.html");
663 Template openSearchTemplate = loaders.loadTemplate("/templates/xml/OpenSearch.xml");
665 PageToadletFactory pageToadletFactory = new PageToadletFactory(sonePlugin.pluginRespirator().getHLSimpleClient(), "/Sone/");
666 pageToadlets.add(pageToadletFactory.createPageToadlet(new RedirectPage<FreenetRequest>("", "index.html")));
667 pageToadlets.add(pageToadletFactory.createPageToadlet(new IndexPage(indexTemplate, this, postVisibilityFilter), "Index"));
668 pageToadlets.add(pageToadletFactory.createPageToadlet(new NewPage(newTemplate, this), "New"));
669 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateSonePage(createSoneTemplate, this), "CreateSone"));
670 pageToadlets.add(pageToadletFactory.createPageToadlet(new KnownSonesPage(knownSonesTemplate, this), "KnownSones"));
671 pageToadlets.add(pageToadletFactory.createPageToadlet(new EditProfilePage(editProfileTemplate, this), "EditProfile"));
672 pageToadlets.add(pageToadletFactory.createPageToadlet(new EditProfileFieldPage(editProfileFieldTemplate, this)));
673 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteProfileFieldPage(deleteProfileFieldTemplate, this)));
674 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreatePostPage(createPostTemplate, this)));
675 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateReplyPage(createReplyTemplate, this)));
676 pageToadlets.add(pageToadletFactory.createPageToadlet(new ViewSonePage(viewSoneTemplate, this)));
677 pageToadlets.add(pageToadletFactory.createPageToadlet(new ViewPostPage(viewPostTemplate, this)));
678 pageToadlets.add(pageToadletFactory.createPageToadlet(new LikePage(emptyTemplate, this)));
679 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlikePage(emptyTemplate, this)));
680 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeletePostPage(deletePostTemplate, this)));
681 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteReplyPage(deleteReplyTemplate, this)));
682 pageToadlets.add(pageToadletFactory.createPageToadlet(new LockSonePage(emptyTemplate, this)));
683 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlockSonePage(emptyTemplate, this)));
684 pageToadlets.add(pageToadletFactory.createPageToadlet(new FollowSonePage(emptyTemplate, this)));
685 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnfollowSonePage(emptyTemplate, this)));
686 pageToadlets.add(pageToadletFactory.createPageToadlet(new ImageBrowserPage(imageBrowserTemplate, this), "ImageBrowser"));
687 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateAlbumPage(createAlbumTemplate, this)));
688 pageToadlets.add(pageToadletFactory.createPageToadlet(new EditAlbumPage(emptyTemplate, this)));
689 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteAlbumPage(deleteAlbumTemplate, this)));
690 pageToadlets.add(pageToadletFactory.createPageToadlet(new UploadImagePage(invalidTemplate, this)));
691 pageToadlets.add(pageToadletFactory.createPageToadlet(new EditImagePage(emptyTemplate, this)));
692 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteImagePage(deleteImageTemplate, this)));
693 pageToadlets.add(pageToadletFactory.createPageToadlet(new TrustPage(emptyTemplate, this)));
694 pageToadlets.add(pageToadletFactory.createPageToadlet(new DistrustPage(emptyTemplate, this)));
695 pageToadlets.add(pageToadletFactory.createPageToadlet(new UntrustPage(emptyTemplate, this)));
696 pageToadlets.add(pageToadletFactory.createPageToadlet(new MarkAsKnownPage(emptyTemplate, this)));
697 pageToadlets.add(pageToadletFactory.createPageToadlet(new BookmarkPage(emptyTemplate, this)));
698 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnbookmarkPage(emptyTemplate, this)));
699 pageToadlets.add(pageToadletFactory.createPageToadlet(new BookmarksPage(bookmarksTemplate, this), "Bookmarks"));
700 pageToadlets.add(pageToadletFactory.createPageToadlet(new SearchPage(searchTemplate, this)));
701 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteSonePage(deleteSoneTemplate, this), "DeleteSone"));
702 pageToadlets.add(pageToadletFactory.createPageToadlet(new LoginPage(loginTemplate, this), "Login"));
703 pageToadlets.add(pageToadletFactory.createPageToadlet(new LogoutPage(emptyTemplate, this), "Logout"));
704 pageToadlets.add(pageToadletFactory.createPageToadlet(new OptionsPage(optionsTemplate, this), "Options"));
705 pageToadlets.add(pageToadletFactory.createPageToadlet(new RescuePage(rescueTemplate, this), "Rescue"));
706 pageToadlets.add(pageToadletFactory.createPageToadlet(new AboutPage(aboutTemplate, this, new PluginVersion(SonePlugin.getPluginVersion()), new PluginYear(SonePlugin.getYear()), new PluginHomepage(SonePlugin.getHomepage())), "About"));
707 pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("noPermission.html", noPermissionTemplate, "Page.NoPermission.Title", this)));
708 pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("emptyImageTitle.html", emptyImageTitleTemplate, "Page.EmptyImageTitle.Title", this)));
709 pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("emptyAlbumTitle.html", emptyAlbumTitleTemplate, "Page.EmptyAlbumTitle.Title", this)));
710 pageToadlets.add(pageToadletFactory.createPageToadlet(new DismissNotificationPage(emptyTemplate, this)));
711 pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("invalid.html", invalidTemplate, "Page.Invalid.Title", this)));
712 pageToadlets.add(pageToadletFactory.createPageToadlet(loaders.<FreenetRequest>loadStaticPage("css/", "/static/css/", "text/css")));
713 pageToadlets.add(pageToadletFactory.createPageToadlet(loaders.<FreenetRequest>loadStaticPage("javascript/", "/static/javascript/", "text/javascript")));
714 pageToadlets.add(pageToadletFactory.createPageToadlet(loaders.<FreenetRequest>loadStaticPage("images/", "/static/images/", "image/png")));
715 pageToadlets.add(pageToadletFactory.createPageToadlet(new TemplatePage<FreenetRequest>("OpenSearch.xml", "application/opensearchdescription+xml", templateContextFactory, openSearchTemplate)));
716 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetImagePage(this)));
717 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetTranslationPage(this)));
718 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetStatusAjaxPage(this, elementLoader, timeTextConverter, l10nFilter)));
719 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetNotificationsAjaxPage(this)));
720 pageToadlets.add(pageToadletFactory.createPageToadlet(new DismissNotificationAjaxPage(this)));
721 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreatePostAjaxPage(this)));
722 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateReplyAjaxPage(this)));
723 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetReplyAjaxPage(this, replyTemplate)));
724 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetPostAjaxPage(this, postTemplate)));
725 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetLinkedElementAjaxPage(this, elementLoader, linkedElementRenderFilter)));
726 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetTimesAjaxPage(this, timeTextConverter, l10nFilter)));
727 pageToadlets.add(pageToadletFactory.createPageToadlet(new MarkAsKnownAjaxPage(this)));
728 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeletePostAjaxPage(this)));
729 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteReplyAjaxPage(this)));
730 pageToadlets.add(pageToadletFactory.createPageToadlet(new LockSoneAjaxPage(this)));
731 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlockSoneAjaxPage(this)));
732 pageToadlets.add(pageToadletFactory.createPageToadlet(new FollowSoneAjaxPage(this)));
733 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnfollowSoneAjaxPage(this)));
734 pageToadlets.add(pageToadletFactory.createPageToadlet(new EditAlbumAjaxPage(this)));
735 pageToadlets.add(pageToadletFactory.createPageToadlet(new EditImageAjaxPage(this, parserFilter, shortenFilter, renderFilter)));
736 pageToadlets.add(pageToadletFactory.createPageToadlet(new TrustAjaxPage(this)));
737 pageToadlets.add(pageToadletFactory.createPageToadlet(new DistrustAjaxPage(this)));
738 pageToadlets.add(pageToadletFactory.createPageToadlet(new UntrustAjaxPage(this)));
739 pageToadlets.add(pageToadletFactory.createPageToadlet(new LikeAjaxPage(this)));
740 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlikeAjaxPage(this)));
741 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetLikesAjaxPage(this)));
742 pageToadlets.add(pageToadletFactory.createPageToadlet(new BookmarkAjaxPage(this)));
743 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnbookmarkAjaxPage(this)));
744 pageToadlets.add(pageToadletFactory.createPageToadlet(new EditProfileFieldAjaxPage(this)));
745 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteProfileFieldAjaxPage(this)));
746 pageToadlets.add(pageToadletFactory.createPageToadlet(new MoveProfileFieldAjaxPage(this)));
748 ToadletContainer toadletContainer = sonePlugin.pluginRespirator().getToadletContainer();
749 toadletContainer.getPageMaker().addNavigationCategory("/Sone/index.html", "Navigation.Menu.Sone.Name", "Navigation.Menu.Sone.Tooltip", sonePlugin);
750 for (PageToadlet toadlet : pageToadlets) {
751 String menuName = toadlet.getMenuName();
752 if (menuName != null) {
753 toadletContainer.register(toadlet, "Navigation.Menu.Sone.Name", toadlet.path(), true, "Navigation.Menu.Sone.Item." + menuName + ".Name", "Navigation.Menu.Sone.Item." + menuName + ".Tooltip", false, toadlet);
755 toadletContainer.register(toadlet, null, toadlet.path(), true, false);
761 * Unregisters all toadlets.
763 private void unregisterToadlets() {
764 ToadletContainer toadletContainer = sonePlugin.pluginRespirator().getToadletContainer();
765 for (PageToadlet pageToadlet : pageToadlets) {
766 toadletContainer.unregister(pageToadlet);
768 toadletContainer.getPageMaker().removeNavigationCategory("Navigation.Menu.Sone.Name");
772 * Returns all {@link Sone#isLocal() local Sone}s that are referenced by
773 * {@link SonePart}s in the given text (after parsing it using
774 * {@link SoneTextParser}).
778 * @return All mentioned local Sones
780 private Collection<Sone> getMentionedSones(String text) {
781 /* we need no context to find mentioned Sones. */
782 Set<Sone> mentionedSones = new HashSet<Sone>();
783 for (Part part : soneTextParser.parse(text, null)) {
784 if (part instanceof SonePart) {
785 mentionedSones.add(((SonePart) part).getSone());
788 return Collections2.filter(mentionedSones, Sone.LOCAL_SONE_FILTER);
792 * Returns the Sone insert notification for the given Sone. If no
793 * notification for the given Sone exists, a new notification is created and
797 * The Sone to get the insert notification for
798 * @return The Sone insert notification
800 private TemplateNotification getSoneInsertNotification(Sone sone) {
801 synchronized (soneInsertNotifications) {
802 TemplateNotification templateNotification = soneInsertNotifications.get(sone);
803 if (templateNotification == null) {
804 templateNotification = new TemplateNotification(loaders.loadTemplate("/templates/notify/soneInsertNotification.html"));
805 templateNotification.set("insertSone", sone);
806 soneInsertNotifications.put(sone, templateNotification);
808 return templateNotification;
812 private boolean localSoneMentionedInNewPostOrReply(Post post) {
813 if (!post.getSone().isLocal()) {
814 if (!getMentionedSones(post.getText()).isEmpty() && !post.isKnown()) {
818 for (PostReply postReply : getCore().getReplies(post.getId())) {
819 if (postReply.getSone().isLocal()) {
822 if (!getMentionedSones(postReply.getText()).isEmpty() && !postReply.isKnown()) {
834 * Notifies the web interface that a new {@link Sone} was found.
836 * @param newSoneFoundEvent
840 public void newSoneFound(NewSoneFoundEvent newSoneFoundEvent) {
841 newSoneNotification.add(newSoneFoundEvent.sone());
842 if (!hasFirstStartNotification()) {
843 notificationManager.addNotification(newSoneNotification);
848 * Notifies the web interface that a new {@link Post} was found.
850 * @param newPostFoundEvent
854 public void newPostFound(NewPostFoundEvent newPostFoundEvent) {
855 Post post = newPostFoundEvent.post();
856 boolean isLocal = post.getSone().isLocal();
858 localPostNotification.add(post);
860 newPostNotification.add(post);
862 if (!hasFirstStartNotification()) {
863 notificationManager.addNotification(isLocal ? localPostNotification : newPostNotification);
864 if (!getMentionedSones(post.getText()).isEmpty() && !isLocal) {
865 mentionNotification.add(post);
866 notificationManager.addNotification(mentionNotification);
869 getCore().markPostKnown(post);
874 * Notifies the web interface that a new {@link PostReply} was found.
876 * @param newPostReplyFoundEvent
880 public void newReplyFound(NewPostReplyFoundEvent newPostReplyFoundEvent) {
881 PostReply reply = newPostReplyFoundEvent.postReply();
882 boolean isLocal = reply.getSone().isLocal();
884 localReplyNotification.add(reply);
886 newReplyNotification.add(reply);
888 if (!hasFirstStartNotification()) {
889 notificationManager.addNotification(isLocal ? localReplyNotification : newReplyNotification);
890 if (reply.getPost().isPresent() && localSoneMentionedInNewPostOrReply(reply.getPost().get())) {
891 mentionNotification.add(reply.getPost().get());
892 notificationManager.addNotification(mentionNotification);
895 getCore().markReplyKnown(reply);
900 * Notifies the web interface that a {@link Sone} was marked as known.
902 * @param markSoneKnownEvent
906 public void markSoneKnown(MarkSoneKnownEvent markSoneKnownEvent) {
907 newSoneNotification.remove(markSoneKnownEvent.sone());
911 public void markPostKnown(MarkPostKnownEvent markPostKnownEvent) {
912 removePost(markPostKnownEvent.post());
916 public void markReplyKnown(MarkPostReplyKnownEvent markPostReplyKnownEvent) {
917 removeReply(markPostReplyKnownEvent.postReply());
921 public void soneRemoved(SoneRemovedEvent soneRemovedEvent) {
922 newSoneNotification.remove(soneRemovedEvent.sone());
926 public void postRemoved(PostRemovedEvent postRemovedEvent) {
927 removePost(postRemovedEvent.post());
930 private void removePost(Post post) {
931 newPostNotification.remove(post);
932 localPostNotification.remove(post);
933 if (!localSoneMentionedInNewPostOrReply(post)) {
934 mentionNotification.remove(post);
939 public void replyRemoved(PostReplyRemovedEvent postReplyRemovedEvent) {
940 removeReply(postReplyRemovedEvent.postReply());
943 private void removeReply(PostReply reply) {
944 newReplyNotification.remove(reply);
945 localReplyNotification.remove(reply);
946 if (reply.getPost().isPresent() && !localSoneMentionedInNewPostOrReply(reply.getPost().get())) {
947 mentionNotification.remove(reply.getPost().get());
952 * Notifies the web interface that a Sone was locked.
954 * @param soneLockedEvent
958 public void soneLocked(SoneLockedEvent soneLockedEvent) {
959 final Sone sone = soneLockedEvent.sone();
960 ScheduledFuture<?> tickerObject = ticker.schedule(new Runnable() {
963 @SuppressWarnings("synthetic-access")
965 lockedSonesNotification.add(sone);
966 notificationManager.addNotification(lockedSonesNotification);
968 }, 5, TimeUnit.MINUTES);
969 lockedSonesTickerObjects.put(sone, tickerObject);
973 * Notifies the web interface that a Sone was unlocked.
975 * @param soneUnlockedEvent
979 public void soneUnlocked(SoneUnlockedEvent soneUnlockedEvent) {
980 lockedSonesNotification.remove(soneUnlockedEvent.sone());
981 lockedSonesTickerObjects.remove(soneUnlockedEvent.sone()).cancel(false);
985 * Notifies the web interface that a {@link Sone} is being inserted.
987 * @param soneInsertingEvent
991 public void soneInserting(SoneInsertingEvent soneInsertingEvent) {
992 TemplateNotification soneInsertNotification = getSoneInsertNotification(soneInsertingEvent.sone());
993 soneInsertNotification.set("soneStatus", "inserting");
994 if (soneInsertingEvent.sone().getOptions().isSoneInsertNotificationEnabled()) {
995 notificationManager.addNotification(soneInsertNotification);
1000 * Notifies the web interface that a {@link Sone} was inserted.
1002 * @param soneInsertedEvent
1006 public void soneInserted(SoneInsertedEvent soneInsertedEvent) {
1007 TemplateNotification soneInsertNotification = getSoneInsertNotification(soneInsertedEvent.sone());
1008 soneInsertNotification.set("soneStatus", "inserted");
1009 soneInsertNotification.set("insertDuration", soneInsertedEvent.insertDuration() / 1000);
1010 if (soneInsertedEvent.sone().getOptions().isSoneInsertNotificationEnabled()) {
1011 notificationManager.addNotification(soneInsertNotification);
1016 * Notifies the web interface that a {@link Sone} insert was aborted.
1018 * @param soneInsertAbortedEvent
1022 public void soneInsertAborted(SoneInsertAbortedEvent soneInsertAbortedEvent) {
1023 TemplateNotification soneInsertNotification = getSoneInsertNotification(soneInsertAbortedEvent.sone());
1024 soneInsertNotification.set("soneStatus", "insert-aborted");
1025 soneInsertNotification.set("insert-error", soneInsertAbortedEvent.cause());
1026 if (soneInsertAbortedEvent.sone().getOptions().isSoneInsertNotificationEnabled()) {
1027 notificationManager.addNotification(soneInsertNotification);
1032 * Notifies the web interface that a new Sone version was found.
1034 * @param updateFoundEvent
1038 public void updateFound(UpdateFoundEvent updateFoundEvent) {
1039 newVersionNotification.set("latestVersion", updateFoundEvent.version());
1040 newVersionNotification.set("latestEdition", updateFoundEvent.latestEdition());
1041 newVersionNotification.set("releaseTime", updateFoundEvent.releaseTime());
1042 newVersionNotification.set("disruptive", updateFoundEvent.disruptive());
1043 notificationManager.addNotification(newVersionNotification);
1047 * Notifies the web interface that an image insert was started
1049 * @param imageInsertStartedEvent
1053 public void imageInsertStarted(ImageInsertStartedEvent imageInsertStartedEvent) {
1054 insertingImagesNotification.add(imageInsertStartedEvent.image());
1055 notificationManager.addNotification(insertingImagesNotification);
1059 * Notifies the web interface that an {@link Image} insert was aborted.
1061 * @param imageInsertAbortedEvent
1065 public void imageInsertAborted(ImageInsertAbortedEvent imageInsertAbortedEvent) {
1066 insertingImagesNotification.remove(imageInsertAbortedEvent.image());
1070 * Notifies the web interface that an {@link Image} insert is finished.
1072 * @param imageInsertFinishedEvent
1076 public void imageInsertFinished(ImageInsertFinishedEvent imageInsertFinishedEvent) {
1077 insertingImagesNotification.remove(imageInsertFinishedEvent.image());
1078 insertedImagesNotification.add(imageInsertFinishedEvent.image());
1079 notificationManager.addNotification(insertedImagesNotification);
1083 * Notifies the web interface that an {@link Image} insert has failed.
1085 * @param imageInsertFailedEvent
1089 public void imageInsertFailed(ImageInsertFailedEvent imageInsertFailedEvent) {
1090 insertingImagesNotification.remove(imageInsertFailedEvent.image());
1091 imageInsertFailedNotification.add(imageInsertFailedEvent.image());
1092 notificationManager.addNotification(imageInsertFailedNotification);