X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FGetLikesAjaxPage.java;fp=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FGetLikesAjaxPage.java;h=0000000000000000000000000000000000000000;hb=889b7b47200adb464d44604a812e7bbb1ba89e1f;hp=7bb75e6528ec79075e19efbd177b6fb7e95e6660;hpb=c3407a682f9f81b27d0354e59fe9e3d3d6dffcd6;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.java
deleted file mode 100644
index 7bb75e6..0000000
--- a/src/main/java/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Sone - GetLikesAjaxPage.java - Copyright © 2010â2016 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 .
- */
-
-package net.pterodactylus.sone.web.ajax;
-
-import static com.fasterxml.jackson.databind.node.JsonNodeFactory.instance;
-import static net.pterodactylus.sone.data.Sone.NICE_NAME_COMPARATOR;
-
-import java.util.Set;
-
-import net.pterodactylus.sone.data.Post;
-import net.pterodactylus.sone.data.PostReply;
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.template.SoneAccessor;
-import net.pterodactylus.sone.web.WebInterface;
-import net.pterodactylus.sone.web.page.FreenetRequest;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.google.common.base.Optional;
-import com.google.common.collect.FluentIterable;
-
-/**
- * AJAX page that retrieves the number of âlikesâ a {@link Post} has.
- *
- * @author David âBombeâ Roden
- */
-public class GetLikesAjaxPage extends JsonPage {
-
- /**
- * Creates a new âget post likesâ AJAX page.
- *
- * @param webInterface
- * The Sone web interface
- */
- public GetLikesAjaxPage(WebInterface webInterface) {
- super("getLikes.ajax", webInterface);
- }
-
- //
- // JSONPAGE METHODS
- //
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected JsonReturnObject createJsonObject(FreenetRequest request) {
- String type = request.getHttpRequest().getParam("type", null);
- String id = request.getHttpRequest().getParam(type, null);
- if ((id == null) || (id.length() == 0)) {
- return createErrorJsonObject("invalid-" + type + "-id");
- }
- if ("post".equals(type)) {
- Optional post = webInterface.getCore().getPost(id);
- if (!post.isPresent()) {
- return createErrorJsonObject("invalid-post-id");
- }
- Set sones = webInterface.getCore().getLikes(post.get());
- return createSuccessJsonObject().put("likes", sones.size()).put("sones", getSones(sones));
- } else if ("reply".equals(type)) {
- Optional reply = webInterface.getCore().getPostReply(id);
- if (!reply.isPresent()) {
- return createErrorJsonObject("invalid-reply-id");
- }
- Set sones = webInterface.getCore().getLikes(reply.get());
- return createSuccessJsonObject().put("likes", sones.size()).put("sones", getSones(sones));
- }
- return createErrorJsonObject("invalid-type");
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected boolean needsFormPassword() {
- return false;
- }
-
- //
- // PRIVATE METHODS
- //
-
- /**
- * Creates a JSON array (containing the IDs and the nice names) from the
- * given Sones, after sorting them by name.
- *
- * @param sones
- * The Sones to convert to an array
- * @return The Sones, sorted by name
- */
- private static JsonNode getSones(Set sones) {
- ArrayNode soneArray = new ArrayNode(instance);
- for (Sone sone : FluentIterable.from(sones).toSortedList(NICE_NAME_COMPARATOR)) {
- soneArray.add(new ObjectNode(instance).put("id", sone.getId()).put("name", SoneAccessor.getNiceName(sone)));
- }
- return soneArray;
- }
-
-}