From: David ‘Bombe’ Roden Date: Fri, 5 Dec 2014 21:13:47 +0000 (+0100) Subject: Use local Sones in more places where it’s appropriate. X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=0aa389b2493e19484530698e2ce056372dc2a1e9 Use local Sones in more places where it’s appropriate. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 90b6e2e..6ca7372 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -605,7 +605,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, * The own identity to create a Sone from * @return The added (or already existing) Sone */ - public Sone addLocalSone(OwnIdentity ownIdentity) { + public LocalSone addLocalSone(OwnIdentity ownIdentity) { if (ownIdentity == null) { logger.log(Level.WARNING, "Given OwnIdentity is null!"); return null; @@ -637,7 +637,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, logger.log(Level.SEVERE, String.format("Could not add “Sone” context to own identity: %s", ownIdentity)); return null; } - Sone sone = addLocalSone(ownIdentity); + LocalSone sone = addLocalSone(ownIdentity); followSone(sone, "nwa8lHa271k2QvJ8aa0Ov7IHAV-DFOCFgmDt3X6BpCI"); touchConfiguration(); @@ -670,7 +670,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, sone.setKnown(!newSone); if (newSone) { eventBus.post(new NewSoneFoundEvent(sone)); - for (Sone localSone : getLocalSones()) { + for (LocalSone localSone : getLocalSones()) { if (localSone.getOptions().isAutoFollow()) { followSone(localSone, sone.getId()); } @@ -691,7 +691,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, * @param soneId * The ID of the Sone to follow */ - public void followSone(Sone sone, String soneId) { + public void followSone(LocalSone sone, String soneId) { checkNotNull(sone, "sone must not be null"); checkNotNull(soneId, "soneId must not be null"); database.addFriend(sone, soneId); @@ -726,7 +726,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, * @param soneId * The ID of the Sone being unfollowed */ - public void unfollowSone(Sone sone, String soneId) { + public void unfollowSone(LocalSone sone, String soneId) { checkNotNull(sone, "sone must not be null"); checkNotNull(soneId, "soneId must not be null"); database.removeFriend(sone, soneId); diff --git a/src/main/java/net/pterodactylus/sone/database/FriendStore.java b/src/main/java/net/pterodactylus/sone/database/FriendStore.java index 38c1c80..b00550f 100644 --- a/src/main/java/net/pterodactylus/sone/database/FriendStore.java +++ b/src/main/java/net/pterodactylus/sone/database/FriendStore.java @@ -1,5 +1,6 @@ package net.pterodactylus.sone.database; +import net.pterodactylus.sone.data.LocalSone; import net.pterodactylus.sone.data.Sone; /** @@ -9,7 +10,7 @@ import net.pterodactylus.sone.data.Sone; */ public interface FriendStore { - void addFriend(Sone localSone, String friendSoneId); - void removeFriend(Sone localSone, String friendSoneId); + void addFriend(LocalSone localSone, String friendSoneId); + void removeFriend(LocalSone localSone, String friendSoneId); } diff --git a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java index bfea5e2..983f8da 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java @@ -640,18 +640,12 @@ public class MemoryDatabase extends AbstractService implements Database { } @Override - public void addFriend(Sone localSone, String friendSoneId) { - if (!localSone.isLocal()) { - return; - } + public void addFriend(LocalSone localSone, String friendSoneId) { memoryFriendDatabase.addFriend(localSone.getId(), friendSoneId); } @Override - public void removeFriend(Sone localSone, String friendSoneId) { - if (!localSone.isLocal()) { - return; - } + public void removeFriend(LocalSone localSone, String friendSoneId) { memoryFriendDatabase.removeFriend(localSone.getId(), friendSoneId); } diff --git a/src/main/java/net/pterodactylus/sone/web/FollowSonePage.java b/src/main/java/net/pterodactylus/sone/web/FollowSonePage.java index ca29fc9..8428630 100644 --- a/src/main/java/net/pterodactylus/sone/web/FollowSonePage.java +++ b/src/main/java/net/pterodactylus/sone/web/FollowSonePage.java @@ -19,6 +19,7 @@ package net.pterodactylus.sone.web; import com.google.common.base.Optional; +import net.pterodactylus.sone.data.LocalSone; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; @@ -54,7 +55,7 @@ public class FollowSonePage extends SoneTemplatePage { super.processTemplate(request, templateContext); if (request.getMethod() == Method.POST) { String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256); - Sone currentSone = getCurrentSone(request.getToadletContext()).get(); + LocalSone currentSone = getCurrentSone(request.getToadletContext()).get(); String soneIds = request.getHttpRequest().getPartAsStringFailsafe("sone", 1200); for (String soneId : soneIds.split("[ ,]+")) { Optional sone = webInterface.getCore().getSone(soneId); diff --git a/src/main/java/net/pterodactylus/sone/web/UnfollowSonePage.java b/src/main/java/net/pterodactylus/sone/web/UnfollowSonePage.java index bddfe23..c6e350c 100644 --- a/src/main/java/net/pterodactylus/sone/web/UnfollowSonePage.java +++ b/src/main/java/net/pterodactylus/sone/web/UnfollowSonePage.java @@ -17,6 +17,7 @@ package net.pterodactylus.sone.web; +import net.pterodactylus.sone.data.LocalSone; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; @@ -52,7 +53,7 @@ public class UnfollowSonePage extends SoneTemplatePage { super.processTemplate(request, templateContext); if (request.getMethod() == Method.POST) { String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256); - Sone currentSone = getCurrentSone(request.getToadletContext()).get(); + LocalSone currentSone = getCurrentSone(request.getToadletContext()).get(); String soneIds = request.getHttpRequest().getPartAsStringFailsafe("sone", 2000); for (String soneId : soneIds.split("[ ,]+")) { webInterface.getCore().unfollowSone(currentSone, soneId); 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 3b51df2..c394326 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.java @@ -19,6 +19,7 @@ package net.pterodactylus.sone.web.ajax; import com.google.common.base.Optional; +import net.pterodactylus.sone.data.LocalSone; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; @@ -50,7 +51,7 @@ public class FollowSoneAjaxPage extends JsonPage { if (!sone.isPresent()) { return createErrorJsonObject("invalid-sone-id"); } - Sone currentSone = getCurrentSone(request.getToadletContext()).get(); + LocalSone currentSone = getCurrentSone(request.getToadletContext()).get(); webInterface.getCore().followSone(currentSone, soneId); webInterface.getCore().markSoneKnown(sone.get()); 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 1e87b15..e5fc749 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.java @@ -17,6 +17,7 @@ package net.pterodactylus.sone.web.ajax; +import net.pterodactylus.sone.data.LocalSone; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; @@ -47,7 +48,7 @@ public class UnfollowSoneAjaxPage extends JsonPage { if (!webInterface.getCore().getSone(soneId).isPresent()) { return createErrorJsonObject("invalid-sone-id"); } - Sone currentSone = getCurrentSone(request.getToadletContext()).get(); + LocalSone currentSone = getCurrentSone(request.getToadletContext()).get(); if (currentSone == null) { return createErrorJsonObject("auth-required"); }