Don’t check for Sones but for their IDs.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 11 Nov 2010 05:33:09 +0000 (06:33 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 11 Nov 2010 05:33:09 +0000 (06:33 +0100)
src/main/java/net/pterodactylus/sone/data/Sone.java
src/main/java/net/pterodactylus/sone/template/SoneAccessor.java
src/main/java/net/pterodactylus/sone/web/UnfollowSonePage.java
src/main/java/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.java

index 2bb5a3e..b14c28f 100644 (file)
@@ -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;
        }
 
index edc0eec..a9ee78b 100644 (file)
@@ -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);
index 7b7c7eb..396e263 100644 (file)
@@ -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);
                }
        }
index 509f629..6092643 100644 (file)
@@ -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);
        }