From: David ‘Bombe’ Roden Date: Thu, 11 Nov 2010 05:33:09 +0000 (+0100) Subject: Don’t check for Sones but for their IDs. X-Git-Tag: 0.2.1~9 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=6f1e7806171eb6af95c8669f2ac0801e34b9246a Don’t check for Sones but for their IDs. --- 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); }