From b3d8b88791743298e897d7f5400304a54f6e2ba4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 13 Nov 2011 19:51:50 +0100 Subject: [PATCH] =?utf8?q?Don=E2=80=99t=20set=20friends=20directly,=20use?= =?utf8?q?=20Core=E2=80=99s=20follow()=20methods.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/main/java/net/pterodactylus/sone/core/Core.java | 9 +++++---- src/main/java/net/pterodactylus/sone/data/Sone.java | 13 ------------- .../java/net/pterodactylus/sone/web/FollowSonePage.java | 6 ++++-- .../java/net/pterodactylus/sone/web/UnfollowSonePage.java | 3 +-- .../net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.java | 4 ++-- .../pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.java | 3 +-- 6 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index b42fc34..2112e18 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -1032,7 +1032,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis sone.getOptions().addBooleanOption("ShowNotification/NewSones", new DefaultOption(true)); sone.getOptions().addBooleanOption("ShowNotification/NewPosts", new DefaultOption(true)); sone.getOptions().addBooleanOption("ShowNotification/NewReplies", new DefaultOption(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); } diff --git a/src/main/java/net/pterodactylus/sone/data/Sone.java b/src/main/java/net/pterodactylus/sone/data/Sone.java index ca970c2..006765a 100644 --- a/src/main/java/net/pterodactylus/sone/data/Sone.java +++ b/src/main/java/net/pterodactylus/sone/data/Sone.java @@ -380,19 +380,6 @@ public class Sone implements Fingerprintable, Comparable { } /** - * 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 friends) { - friendSones.clear(); - friendSones.addAll(friends); - return this; - } - - /** * Returns whether this Sone has the given Sone as a friend Sone. * * @param friendSoneId diff --git a/src/main/java/net/pterodactylus/sone/web/FollowSonePage.java b/src/main/java/net/pterodactylus/sone/web/FollowSonePage.java index 143e0ba..4083b99 100644 --- a/src/main/java/net/pterodactylus/sone/web/FollowSonePage.java +++ b/src/main/java/net/pterodactylus/sone/web/FollowSonePage.java @@ -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); } } diff --git a/src/main/java/net/pterodactylus/sone/web/UnfollowSonePage.java b/src/main/java/net/pterodactylus/sone/web/UnfollowSonePage.java index d8e53ce..f07880d 100644 --- a/src/main/java/net/pterodactylus/sone/web/UnfollowSonePage.java +++ b/src/main/java/net/pterodactylus/sone/web/UnfollowSonePage.java @@ -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); } } diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.java index 5c3e5f4..764fa28 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.java @@ -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(); } 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 26f1a11..5d94d52 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.java @@ -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(); } -- 2.7.4