From 6f1e7806171eb6af95c8669f2ac0801e34b9246a Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 11 Nov 2010 06:33:09 +0100 Subject: [PATCH] =?utf8?q?Don=E2=80=99t=20check=20for=20Sones=20but=20for?= =?utf8?q?=20their=20IDs.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/main/java/net/pterodactylus/sone/data/Sone.java | 16 ++++++++-------- .../net/pterodactylus/sone/template/SoneAccessor.java | 2 +- .../net/pterodactylus/sone/web/UnfollowSonePage.java | 7 ++----- .../sone/web/ajax/UnfollowSoneAjaxPage.java | 5 ++--- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/data/Sone.java b/src/main/java/net/pterodactylus/sone/data/Sone.java index 2bb5a3e..b14c28f 100644 --- a/src/main/java/net/pterodactylus/sone/data/Sone.java +++ b/src/main/java/net/pterodactylus/sone/data/Sone.java @@ -310,13 +310,13 @@ public class Sone { /** * Returns whether this Sone has the given Sone as a friend Sone. * - * @param friendSone - * The friend Sone to check for + * @param friendSoneId + * The ID of the Sone to check for * @return {@code true} if this Sone has the given Sone as a friend, * {@code false} otherwise */ - public boolean hasFriend(Sone friendSone) { - return friendSones.contains(friendSone); + public boolean hasFriend(String friendSoneId) { + return friendSones.contains(friendSoneId); } /** @@ -336,12 +336,12 @@ public class Sone { /** * Removes the given Sone as a friend Sone. * - * @param friendSone - * The friend Sone to remove + * @param friendSoneId + * The ID of the friend Sone to remove * @return This Sone (for method chaining) */ - public Sone removeFriend(Sone friendSone) { - friendSones.remove(friendSone); + public Sone removeFriend(String friendSoneId) { + friendSones.remove(friendSoneId); return this; } diff --git a/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java b/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java index edc0eec..a9ee78b 100644 --- a/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java +++ b/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java @@ -69,7 +69,7 @@ public class SoneAccessor extends ReflectionAccessor { return sone.getInsertUri() != null; } else if (member.equals("friend")) { Sone currentSone = (Sone) dataProvider.getData("currentSone"); - return (currentSone != null) && currentSone.hasFriend(sone); + return (currentSone != null) && currentSone.hasFriend(sone.getId()); } else if (member.equals("current")) { Sone currentSone = (Sone) dataProvider.getData("currentSone"); return (currentSone != null) && currentSone.equals(sone); diff --git a/src/main/java/net/pterodactylus/sone/web/UnfollowSonePage.java b/src/main/java/net/pterodactylus/sone/web/UnfollowSonePage.java index 7b7c7eb..396e263 100644 --- a/src/main/java/net/pterodactylus/sone/web/UnfollowSonePage.java +++ b/src/main/java/net/pterodactylus/sone/web/UnfollowSonePage.java @@ -52,11 +52,8 @@ public class UnfollowSonePage extends SoneTemplatePage { String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone", 44); String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 64); Sone currentSone = getCurrentSone(request.getToadletContext()); - Sone sone = webInterface.getCore().getSone(soneId); - if (!sone.equals(currentSone)) { - currentSone.removeFriend(sone); - webInterface.getCore().saveSone(currentSone); - } + currentSone.removeFriend(soneId); + webInterface.getCore().saveSone(currentSone); throw new RedirectException(returnPage); } } diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.java index 509f629..6092643 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.java @@ -44,15 +44,14 @@ public class UnfollowSoneAjaxPage extends JsonPage { @Override protected JsonObject createJsonObject(Request request) { String soneId = request.getHttpRequest().getParam("sone"); - Sone sone = webInterface.getCore().getSone(soneId); - if (sone == null) { + if (!webInterface.getCore().hasSone(soneId)) { return new JsonObject().put("success", false).put("error", "invalid-sone-id"); } Sone currentSone = getCurrentSone(request.getToadletContext()); if (currentSone == null) { return new JsonObject().put("success", false).put("error", "auth-required"); } - currentSone.removeFriend(sone); + currentSone.removeFriend(soneId); webInterface.getCore().saveSone(currentSone); return new JsonObject().put("success", true); } -- 2.7.4