X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FGetNotificationAjaxPage.java;h=6cdbf12166ed64a60e241ca45bd8bfe53cf16e9d;hb=28193a97b676d7e78ba9b8de02dd9ba221b9fde9;hp=bd1457f34eb7df05c75d31751d0bad34f171f65e;hpb=aea033be47314458fd157b1a9933753eb56bdf01;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationAjaxPage.java index bd1457f..6cdbf12 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationAjaxPage.java @@ -21,12 +21,13 @@ import java.io.IOException; import java.io.StringWriter; import net.pterodactylus.sone.data.Post; -import net.pterodactylus.sone.data.Reply; +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; @@ -75,16 +76,22 @@ public class GetNotificationAjaxPage extends JsonPage { */ @Override @SuppressWarnings("unchecked") - protected JsonObject createJsonObject(Request request) { + protected JsonObject createJsonObject(FreenetRequest request) { String[] notificationIds = request.getHttpRequest().getParam("notifications").split(","); JsonObject jsonNotifications = new JsonObject(); - Sone currentSone = webInterface.getCurrentSone(request.getToadletContext(), false); + 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) notification, currentSone); + notification = ListNotificationFilters.filterNewPostNotification((ListNotification) notification, currentSone, false); } else if ("new-reply-notification".equals(notificationId)) { - notification = ListNotificationFilters.filterNewReplyNotification((ListNotification) notification, currentSone); + notification = ListNotificationFilters.filterNewReplyNotification((ListNotification) notification, currentSone); + } else if ("mention-notification".equals(notificationId)) { + notification = ListNotificationFilters.filterNewPostNotification((ListNotification) notification, currentSone, false); } if (notification == null) { // TODO - show error @@ -108,13 +115,14 @@ public class GetNotificationAjaxPage extends JsonPage { * The notification to create a JSON object * @return The JSON object */ - private JsonObject createJsonNotification(Request request, Notification notification) { + 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);