Remove old “get notification” AJAX handler.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 25 Nov 2011 06:49:44 +0000 (07:49 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 25 Nov 2011 06:49:44 +0000 (07:49 +0100)
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationAjaxPage.java [deleted file]

index 2b3b67f..094d2a4 100644 (file)
@@ -83,7 +83,6 @@ import net.pterodactylus.sone.web.ajax.EditProfileFieldAjaxPage;
 import net.pterodactylus.sone.web.ajax.FollowSoneAjaxPage;
 import net.pterodactylus.sone.web.ajax.GetLikesAjaxPage;
 import net.pterodactylus.sone.web.ajax.GetNotificationsAjaxPage;
 import net.pterodactylus.sone.web.ajax.FollowSoneAjaxPage;
 import net.pterodactylus.sone.web.ajax.GetLikesAjaxPage;
 import net.pterodactylus.sone.web.ajax.GetNotificationsAjaxPage;
-import net.pterodactylus.sone.web.ajax.GetNotificationAjaxPage;
 import net.pterodactylus.sone.web.ajax.GetPostAjaxPage;
 import net.pterodactylus.sone.web.ajax.GetReplyAjaxPage;
 import net.pterodactylus.sone.web.ajax.GetStatusAjaxPage;
 import net.pterodactylus.sone.web.ajax.GetPostAjaxPage;
 import net.pterodactylus.sone.web.ajax.GetReplyAjaxPage;
 import net.pterodactylus.sone.web.ajax.GetStatusAjaxPage;
@@ -660,7 +659,6 @@ public class WebInterface implements CoreListener {
                pageToadlets.add(pageToadletFactory.createPageToadlet(new GetTranslationPage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new GetStatusAjaxPage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new GetNotificationsAjaxPage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new GetTranslationPage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new GetStatusAjaxPage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new GetNotificationsAjaxPage(this)));
-               pageToadlets.add(pageToadletFactory.createPageToadlet(new GetNotificationAjaxPage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new DismissNotificationAjaxPage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new CreatePostAjaxPage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateReplyAjaxPage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new DismissNotificationAjaxPage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new CreatePostAjaxPage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateReplyAjaxPage(this)));
diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationAjaxPage.java
deleted file mode 100644 (file)
index 6cdbf12..0000000
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * Sone - GetNotificationAjaxPage.java - Copyright © 2010 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web.ajax;
-
-import java.io.IOException;
-import java.io.StringWriter;
-
-import net.pterodactylus.sone.data.Post;
-import net.pterodactylus.sone.data.PostReply;
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.main.SonePlugin;
-import net.pterodactylus.sone.notify.ListNotification;
-import net.pterodactylus.sone.notify.ListNotificationFilters;
-import net.pterodactylus.sone.web.WebInterface;
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.json.JsonObject;
-import net.pterodactylus.util.notify.Notification;
-import net.pterodactylus.util.notify.TemplateNotification;
-import net.pterodactylus.util.template.TemplateContext;
-
-/**
- * The “get notification” AJAX handler returns a number of rendered
- * notifications.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class GetNotificationAjaxPage extends JsonPage {
-
-       /**
-        * Creates a new “get notification” AJAX page.
-        *
-        * @param webInterface
-        *            The Sone web interface
-        */
-       public GetNotificationAjaxPage(WebInterface webInterface) {
-               super("getNotification.ajax", webInterface);
-       }
-
-       //
-       // JSONPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected boolean needsFormPassword() {
-               return false;
-       }
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected boolean requiresLogin() {
-               return false;
-       }
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       @SuppressWarnings("unchecked")
-       protected JsonObject createJsonObject(FreenetRequest request) {
-               String[] notificationIds = request.getHttpRequest().getParam("notifications").split(",");
-               JsonObject jsonNotifications = new JsonObject();
-               Sone currentSone = getCurrentSone(request.getToadletContext(), false);
-               for (String notificationId : notificationIds) {
-                       Notification notification = webInterface.getNotifications().getNotification(notificationId);
-                       if (notification == null) {
-                               // TODO - show error
-                               continue;
-                       }
-                       if ("new-post-notification".equals(notificationId)) {
-                               notification = ListNotificationFilters.filterNewPostNotification((ListNotification<Post>) notification, currentSone, false);
-                       } else if ("new-reply-notification".equals(notificationId)) {
-                               notification = ListNotificationFilters.filterNewReplyNotification((ListNotification<PostReply>) notification, currentSone);
-                       } else if ("mention-notification".equals(notificationId)) {
-                               notification = ListNotificationFilters.filterNewPostNotification((ListNotification<Post>) notification, currentSone, false);
-                       }
-                       if (notification == null) {
-                               // TODO - show error
-                               continue;
-                       }
-                       jsonNotifications.put(notificationId, createJsonNotification(request, notification));
-               }
-               return createSuccessJsonObject().put("notifications", jsonNotifications);
-       }
-
-       //
-       // PRIVATE METHODS
-       //
-
-       /**
-        * Creates a JSON object from the given notification.
-        *
-        * @param request
-        *            The request to load the session from
-        * @param notification
-        *            The notification to create a JSON object
-        * @return The JSON object
-        */
-       private JsonObject createJsonNotification(FreenetRequest request, Notification notification) {
-               JsonObject jsonNotification = new JsonObject();
-               jsonNotification.put("id", notification.getId());
-               StringWriter notificationWriter = new StringWriter();
-               try {
-                       if (notification instanceof TemplateNotification) {
-                               TemplateContext templateContext = webInterface.getTemplateContextFactory().createTemplateContext().mergeContext(((TemplateNotification) notification).getTemplateContext());
-                               templateContext.set("core", webInterface.getCore());
-                               templateContext.set("currentSone", webInterface.getCurrentSone(request.getToadletContext(), false));
-                               templateContext.set("localSones", webInterface.getCore().getLocalSones());
-                               templateContext.set("request", request);
-                               templateContext.set("currentVersion", SonePlugin.VERSION);
-                               templateContext.set("hasLatestVersion", webInterface.getCore().getUpdateChecker().hasLatestVersion());
-                               templateContext.set("latestEdition", webInterface.getCore().getUpdateChecker().getLatestEdition());
-                               templateContext.set("latestVersion", webInterface.getCore().getUpdateChecker().getLatestVersion());
-                               templateContext.set("latestVersionTime", webInterface.getCore().getUpdateChecker().getLatestVersionDate());
-                               templateContext.set("notification", notification);
-                               ((TemplateNotification) notification).render(templateContext, notificationWriter);
-                       } else {
-                               notification.render(notificationWriter);
-                       }
-               } catch (IOException ioe1) {
-                       /* StringWriter never throws, ignore. */
-               }
-               jsonNotification.put("text", notificationWriter.toString());
-               jsonNotification.put("createdTime", notification.getCreatedTime());
-               jsonNotification.put("lastUpdatedTime", notification.getLastUpdatedTime());
-               jsonNotification.put("dismissable", notification.isDismissable());
-               return jsonNotification;
-       }
-
-}