Don’t set friends directly, use Core’s follow() methods.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 13 Nov 2011 18:51:50 +0000 (19:51 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 13 Nov 2011 18:51:50 +0000 (19:51 +0100)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/data/Sone.java
src/main/java/net/pterodactylus/sone/web/FollowSonePage.java
src/main/java/net/pterodactylus/sone/web/UnfollowSonePage.java
src/main/java/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.java

index b42fc34..2112e18 100644 (file)
@@ -1032,7 +1032,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                sone.getOptions().addBooleanOption("ShowNotification/NewSones", new DefaultOption<Boolean>(true));
                sone.getOptions().addBooleanOption("ShowNotification/NewPosts", new DefaultOption<Boolean>(true));
                sone.getOptions().addBooleanOption("ShowNotification/NewReplies", new DefaultOption<Boolean>(true));
-               sone.addFriend("nwa8lHa271k2QvJ8aa0Ov7IHAV-DFOCFgmDt3X6BpCI");
+               followSone(sone, getSone("nwa8lHa271k2QvJ8aa0Ov7IHAV-DFOCFgmDt3X6BpCI"));
                touchConfiguration();
                return sone;
        }
@@ -1065,8 +1065,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                                        coreListenerManager.fireNewSoneFound(sone);
                                        for (Sone localSone : getLocalSones()) {
                                                if (localSone.getOptions().getBooleanOption("AutoFollow").get()) {
-                                                       localSone.addFriend(sone.getId());
-                                                       touchConfiguration();
+                                                       followSone(localSone, sone);
                                                }
                                        }
                                }
@@ -1628,7 +1627,9 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                        sone.setReplies(replies);
                        sone.setLikePostIds(likedPostIds);
                        sone.setLikeReplyIds(likedReplyIds);
-                       sone.setFriends(friends);
+                       for (String friendId : friends) {
+                               followSone(sone, friendId);
+                       }
                        sone.setAlbums(topLevelAlbums);
                        soneInserters.get(sone).setLastInsertFingerprint(lastInsertFingerprint);
                }
index ca970c2..006765a 100644 (file)
@@ -380,19 +380,6 @@ public class Sone implements Fingerprintable, Comparable<Sone> {
        }
 
        /**
-        * Sets all friends of this Sone at once.
-        *
-        * @param friends
-        *            The new (and only) friends of this Sone
-        * @return This Sone (for method chaining)
-        */
-       public Sone setFriends(Collection<String> friends) {
-               friendSones.clear();
-               friendSones.addAll(friends);
-               return this;
-       }
-
-       /**
         * Returns whether this Sone has the given Sone as a friend Sone.
         *
         * @param friendSoneId
index 143e0ba..4083b99 100644 (file)
@@ -55,9 +55,11 @@ public class FollowSonePage extends SoneTemplatePage {
                        Sone currentSone = getCurrentSone(request.getToadletContext());
                        String soneIds = request.getHttpRequest().getPartAsStringFailsafe("sone", 1200);
                        for (String soneId : soneIds.split("[ ,]+")) {
-                               currentSone.addFriend(soneId);
+                               if (webInterface.getCore().hasSone(soneId)) {
+                                       webInterface.getCore().followSone(currentSone, soneId);
+                                       webInterface.getCore().markSoneKnown(webInterface.getCore().getSone(soneId));
+                               }
                        }
-                       webInterface.getCore().touchConfiguration();
                        throw new RedirectException(returnPage);
                }
        }
index d8e53ce..f07880d 100644 (file)
@@ -55,9 +55,8 @@ public class UnfollowSonePage extends SoneTemplatePage {
                        Sone currentSone = getCurrentSone(request.getToadletContext());
                        String soneIds = request.getHttpRequest().getPartAsStringFailsafe("sone", 2000);
                        for (String soneId : soneIds.split("[ ,]+")) {
-                               currentSone.removeFriend(soneId);
+                               webInterface.getCore().unfollowSone(currentSone, soneId);
                        }
-                       webInterface.getCore().touchConfiguration();
                        throw new RedirectException(returnPage);
                }
        }
index 5c3e5f4..764fa28 100644 (file)
@@ -52,8 +52,8 @@ public class FollowSoneAjaxPage extends JsonPage {
                if (currentSone == null) {
                        return createErrorJsonObject("auth-required");
                }
-               currentSone.addFriend(soneId);
-               webInterface.getCore().touchConfiguration();
+               webInterface.getCore().followSone(currentSone, soneId);
+               webInterface.getCore().markSoneKnown(webInterface.getCore().getSone(soneId));
                return createSuccessJsonObject();
        }
 
index 26f1a11..5d94d52 100644 (file)
@@ -52,8 +52,7 @@ public class UnfollowSoneAjaxPage extends JsonPage {
                if (currentSone == null) {
                        return createErrorJsonObject("auth-required");
                }
-               currentSone.removeFriend(soneId);
-               webInterface.getCore().touchConfiguration();
+               webInterface.getCore().unfollowSone(currentSone, soneId);
                return createSuccessJsonObject();
        }