From a7c7118b60516be41b759d4cc41d61e2bc074ebb Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 14 Oct 2011 07:30:44 +0200 Subject: [PATCH] Store locality of a Sone in the Sone itself, remove related methods from Database. --- .../java/net/pterodactylus/sone/core/Core.java | 97 +++++++++------------- .../pterodactylus/sone/core/SoneDownloader.java | 2 +- .../java/net/pterodactylus/sone/data/Sone.java | 19 ++++- .../net/pterodactylus/sone/database/Database.java | 56 ------------- .../sone/database/memory/MemoryDatabase.java | 52 ++---------- .../pterodactylus/sone/fcp/DeletePostCommand.java | 2 +- .../pterodactylus/sone/fcp/DeleteReplyCommand.java | 2 +- .../sone/template/ProfileAccessor.java | 2 +- .../pterodactylus/sone/template/SoneAccessor.java | 2 - .../pterodactylus/sone/text/SoneTextParser.java | 2 +- .../pterodactylus/sone/web/DeleteAlbumPage.java | 2 +- .../pterodactylus/sone/web/DeleteImagePage.java | 2 +- .../net/pterodactylus/sone/web/DeletePostPage.java | 2 +- .../pterodactylus/sone/web/DeleteReplyPage.java | 2 +- .../net/pterodactylus/sone/web/EditAlbumPage.java | 2 +- .../net/pterodactylus/sone/web/EditImagePage.java | 2 +- .../net/pterodactylus/sone/web/WebInterface.java | 18 ++-- .../sone/web/ajax/DeletePostAjaxPage.java | 2 +- .../sone/web/ajax/DeleteReplyAjaxPage.java | 2 +- .../sone/web/ajax/EditAlbumAjaxPage.java | 2 +- .../sone/web/ajax/EditImageAjaxPage.java | 2 +- .../sone/text/SoneTextParserTest.java | 2 +- 22 files changed, 84 insertions(+), 192 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index a574a59..d552f7f 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -279,7 +279,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis * @return The Sone rescuer for the given Sone */ public SoneRescuer getSoneRescuer(Sone sone) { - Validation.begin().isNotNull("Sone", sone).check().is("Local Sone", isLocalSone(sone)).check(); + Validation.begin().isNotNull("Sone", sone).check().is("Local Sone", sone.isLocal()).check(); synchronized (soneRescuers) { SoneRescuer soneRescuer = soneRescuers.get(sone); if (soneRescuer == null) { @@ -353,30 +353,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis * otherwise */ public boolean hasSone(String id) { - return database.isLocalSone(id) || database.isRemoteSone(id); - } - - /** - * Returns whether the given Sone is a local Sone. - * - * @param sone - * The Sone to check for its locality - * @return {@code true} if the given Sone is local, {@code false} otherwise - */ - public boolean isLocalSone(Sone sone) { - return database.isLocalSone(sone); - } - - /** - * Returns whether the given ID is the ID of a local Sone. - * - * @param id - * The Sone ID to check for its locality - * @return {@code true} if the given ID is a local Sone, {@code false} - * otherwise - */ - public boolean isLocalSone(String id) { - return database.isLocalSone(id); + return database.getSone(id, false) != null; } /** @@ -437,30 +414,6 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis } /** - * Returns whether the given Sone is a remote Sone. - * - * @param sone - * The Sone to check - * @return {@code true} if the given Sone is a remote Sone, {@code false} - * otherwise - */ - public boolean isRemoteSone(Sone sone) { - return database.isRemoteSone(sone); - } - - /** - * Returns whether the Sone with the given ID is a remote Sone. - * - * @param id - * The ID of the Sone to check - * @return {@code true} if the Sone with the given ID is a remote Sone, - * {@code false} otherwise - */ - public boolean isRemoteSone(String id) { - return database.isRemoteSone(id); - } - - /** * Returns whether the given Sone has been modified. * * @param sone @@ -810,6 +763,30 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis } /** +<<<<<<< HEAD +======= + * Adds a local Sone from the given ID which has to be the ID of an own + * identity. + * + * @param id + * The ID of an own identity to add a Sone for + * @return The added (or already existing) Sone + */ + public Sone addLocalSone(String id) { + if (database.getLocalSone(id, false) != null) { + logger.log(Level.FINE, "Tried to add known local Sone: %s", id); + return database.getLocalSone(id, false); + } + OwnIdentity ownIdentity = identityManager.getOwnIdentity(id); + if (ownIdentity == null) { + logger.log(Level.INFO, "Invalid Sone ID: %s", id); + return null; + } + return addLocalSone(ownIdentity); + } + + /** +>>>>>>> 4f36598... Store locality of a Sone in the Sone itself, remove related methods from Database. * Adds a local Sone from the given own identity. * * @param ownIdentity @@ -1014,7 +991,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis * @return The trust relationship */ public Trust getTrust(Sone origin, Sone target) { - if (!isLocalSone(origin)) { + if (!origin.isLocal()) { logger.log(Level.WARNING, String.format("Tried to get trust from remote Sone: %s", origin)); return null; } @@ -1234,7 +1211,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis logger.log(Level.WARNING, String.format("Tried to delete Sone of non-own identity: %s", sone)); return; } - if (!database.isLocalSone(sone)) { + if (!sone.isLocal()) { logger.log(Level.WARNING, String.format("Tried to delete non-local Sone: %s", sone)); return; } @@ -1281,7 +1258,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis * The Sone to load and update */ public void loadSone(Sone sone) { - if (!isLocalSone(sone)) { + if (!sone.isLocal()) { logger.log(Level.FINE, String.format("Tried to load non-local Sone: %s", sone)); return; } @@ -1558,7 +1535,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis * @return The created post */ public Post createPost(Sone sone, Sone recipient, long time, String text) { - if (!isLocalSone(sone)) { + if (!sone.isLocal()) { logger.log(Level.FINE, String.format("Tried to create post for non-local Sone: %s", sone)); return null; } @@ -1592,7 +1569,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis * The post to delete */ public void deletePost(Post post) { - if (!isLocalSone(post.getSone())) { + if (!post.getSone().isLocal()) { logger.log(Level.WARNING, String.format("Tried to delete post of non-local Sone: %s", post.getSone())); return; } @@ -1698,7 +1675,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis * @return The created reply */ public PostReply createReply(Sone sone, Post post, long time, String text) { - if (!isLocalSone(sone)) { + if (!sone.isLocal()) { logger.log(Level.FINE, String.format("Tried to create reply for non-local Sone: %s", sone)); return null; } @@ -1732,7 +1709,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis */ public void deleteReply(PostReply reply) { Sone sone = reply.getSone(); - if (!isLocalSone(sone)) { + if (!sone.isLocal()) { logger.log(Level.FINE, String.format("Tried to delete non-local reply: %s", reply)); return; } @@ -1807,7 +1784,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis * The album to remove */ public void deleteAlbum(Album album) { - Validation.begin().isNotNull("Album", album).check().is("Local Sone", isLocalSone(album.getSone())).check(); + Validation.begin().isNotNull("Album", album).check().is("Local Sone", album.getSone().isLocal()).check(); if (!album.isEmpty()) { return; } @@ -1834,7 +1811,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis * @return The newly created image */ public Image createImage(Sone sone, Album album, TemporaryImage temporaryImage) { - Validation.begin().isNotNull("Sone", sone).isNotNull("Album", album).isNotNull("Temporary Image", temporaryImage).check().is("Local Sone", isLocalSone(sone)).check().isEqual("Owner and Album Owner", sone, album.getSone()).check(); + Validation.begin().isNotNull("Sone", sone).isNotNull("Album", album).isNotNull("Temporary Image", temporaryImage).check().is("Local Sone", sone.isLocal()).check().isEqual("Owner and Album Owner", sone, album.getSone()).check(); Image image = new Image(temporaryImage.getId()).setSone(sone).setCreationTime(System.currentTimeMillis()); album.addImage(image); synchronized (images) { @@ -1853,7 +1830,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis * The image to delete */ public void deleteImage(Image image) { - Validation.begin().isNotNull("Image", image).check().is("Local Sone", isLocalSone(image.getSone())).check(); + Validation.begin().isNotNull("Image", image).check().is("Local Sone", image.getSone().isLocal()).check(); deleteTemporaryImage(image.getId()); image.getAlbum().removeImage(image); synchronized (images) { @@ -1976,7 +1953,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis * The Sone to save */ private synchronized void saveSone(Sone sone) { - if (!isLocalSone(sone)) { + if (!sone.isLocal()) { logger.log(Level.FINE, String.format("Tried to save non-local Sone: %s", sone)); return; } diff --git a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java index 72ff008..d9b318c 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java @@ -236,7 +236,7 @@ public class SoneDownloader extends AbstractService { return null; } - Sone sone = new Sone(originalSone.getId()).setIdentity(originalSone.getIdentity()); + Sone sone = new Sone(originalSone.getId(), originalSone.isLocal()).setIdentity(originalSone.getIdentity()); SimpleXML soneXml; try { diff --git a/src/main/java/net/pterodactylus/sone/data/Sone.java b/src/main/java/net/pterodactylus/sone/data/Sone.java index ac6e41a..d515424 100644 --- a/src/main/java/net/pterodactylus/sone/data/Sone.java +++ b/src/main/java/net/pterodactylus/sone/data/Sone.java @@ -150,7 +150,7 @@ public class Sone implements Fingerprintable, Comparable { } }; - /** Filter that matches all {@link Core#isLocalSone(Sone) local Sones}. */ + /** Filter that matches all {@link Core#getLocalSones() local Sones}. */ public static final Filter LOCAL_SONE_FILTER = new Filter() { @Override @@ -175,6 +175,9 @@ public class Sone implements Fingerprintable, Comparable { /** The ID of this Sone. */ private final String id; + /** Whether this is a local Sone. */ + private final boolean local; + /** The identity of this Sone. */ private Identity identity; @@ -229,9 +232,12 @@ public class Sone implements Fingerprintable, Comparable { * * @param id * The ID of the Sone + * @param local + * {@code true} if this Sone is local, {@code false} otherwise */ - public Sone(String id) { + public Sone(String id, boolean local) { this.id = id; + this.local = local; } // @@ -275,6 +281,15 @@ public class Sone implements Fingerprintable, Comparable { } /** + * Returns whether this Sone is local. + * + * @return {@code true} if this Sone is local, {@code false} otherwise + */ + public boolean isLocal() { + return local; + } + + /** * Returns the name of this Sone. * * @return The name of this Sone diff --git a/src/main/java/net/pterodactylus/sone/database/Database.java b/src/main/java/net/pterodactylus/sone/database/Database.java index 7b48151..0ff7dfb 100644 --- a/src/main/java/net/pterodactylus/sone/database/Database.java +++ b/src/main/java/net/pterodactylus/sone/database/Database.java @@ -29,62 +29,6 @@ import net.pterodactylus.sone.data.Sone; public interface Database { /** - * Returns whether the given Sone is a local Sone. - * - * @param sone - * The Sone to check - * @return {@code true} if the given Sone is a local Sone, {@code false} - * otherwise - * @throws IllegalArgumentException - * if {@code sone} is {@code null} - * @throws DatabaseException - * if a database error occurs - */ - public boolean isLocalSone(Sone sone) throws DatabaseException; - - /** - * Returns whether the given Sone ID belongs to a local Sone. - * - * @param id - * The Sone ID to check - * @return {@code true} if the given Sone ID belongs to a local Sone, - * {@code false} otherwise - * @throws IllegalArgumentException - * if {@code id} is {@code null} - * @throws DatabaseException - * if a database error occurs - */ - public boolean isLocalSone(String id) throws DatabaseException; - - /** - * Returns whether the given Sone is a remote Sone. - * - * @param sone - * The Sone to check - * @return {@code true} if the given Sone is a remote Sone, {@code false} - * otherwise - * @throws IllegalArgumentException - * if {@code sone} is {@code null} - * @throws DatabaseException - * if a database error occurs - */ - public boolean isRemoteSone(Sone sone) throws DatabaseException; - - /** - * Returns whether the given Sone ID belongs to a remote Sone. - * - * @param id - * The Sone ID to check - * @return {@code true} if the given Sone ID belongs to a remote Sone, - * {@code false} otherwise - * @throws IllegalArgumentException - * if {@code id} is {@code null} - * @throws DatabaseException - * if a database error occurs - */ - public boolean isRemoteSone(String id) throws DatabaseException; - - /** * Returns the Sone with the given ID, creating a new Sone if a Sone with * the given ID does not exist and {@code create} is {@code true}. When * searching for a Sone with the given IDs, local Sones are preferred. 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 d87a712..3c32f71 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java @@ -48,48 +48,8 @@ public class MemoryDatabase implements Database { * {@inheritDoc} */ @Override - public boolean isLocalSone(Sone sone) throws DatabaseException { - Validation.begin().isNotNull("Sone", sone).check(); - return isLocalSone(sone.getId()); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isLocalSone(String id) throws DatabaseException { - Validation.begin().isNotNull("Sone ID", id).check(); - synchronized (localSones) { - return localSones.containsKey(id); - } - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isRemoteSone(Sone sone) throws DatabaseException { - Validation.begin().isNotNull("Sone", sone).check(); - return isRemoteSone(sone.getId()); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isRemoteSone(String id) throws DatabaseException { - Validation.begin().isNotNull("Sone ID", id).check(); - synchronized (remoteSones) { - return remoteSones.containsKey(id); - } - } - - /** - * {@inheritDoc} - */ - @Override public Sone getSone(String id, boolean create) throws DatabaseException { - if (isLocalSone(id)) { + if (getLocalSone(id, false) != null) { return getLocalSone(id, create); } return getRemoteSone(id, create); @@ -131,7 +91,7 @@ public class MemoryDatabase implements Database { Validation.begin().isNotNull("Sone ID", id).check(); synchronized (localSones) { if (!localSones.containsKey(id) && create) { - localSones.put(id, new Sone(id)); + localSones.put(id, new Sone(id, true)); } return localSones.get(id); } @@ -145,7 +105,7 @@ public class MemoryDatabase implements Database { Validation.begin().isNotNull("Sone ID", id).check(); synchronized (remoteSones) { if (!remoteSones.containsKey(id) && create) { - remoteSones.put(id, new Sone(id)); + remoteSones.put(id, new Sone(id, false)); } return remoteSones.get(id); } @@ -156,7 +116,7 @@ public class MemoryDatabase implements Database { */ @Override public void saveSone(Sone sone) throws DatabaseException { - if (isLocalSone(sone)) { + if (sone.isLocal()) { synchronized (localSones) { localSones.put(sone.getId(), sone); } @@ -173,7 +133,7 @@ public class MemoryDatabase implements Database { */ @Override public void removeSone(Sone sone) throws DatabaseException { - Map sones = isLocalSone(sone) ? localSones : remoteSones; + Map sones = sone.isLocal() ? localSones : remoteSones; synchronized (sones) { sones.remove(sone.getId()); } @@ -184,7 +144,7 @@ public class MemoryDatabase implements Database { */ @Override public void removeSone(String id) throws DatabaseException { - Map sones = isLocalSone(id) ? localSones : remoteSones; + Map sones = ((getSone(id, false) != null) && getSone(id, false).isLocal()) ? localSones : remoteSones; synchronized (sones) { sones.remove(id); } diff --git a/src/main/java/net/pterodactylus/sone/fcp/DeletePostCommand.java b/src/main/java/net/pterodactylus/sone/fcp/DeletePostCommand.java index 54f01c8..8d929f3 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/DeletePostCommand.java +++ b/src/main/java/net/pterodactylus/sone/fcp/DeletePostCommand.java @@ -48,7 +48,7 @@ public class DeletePostCommand extends AbstractSoneCommand { @Override public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException { Post post = getPost(parameters, "Post"); - if (!getCore().isLocalSone(post.getSone())) { + if (!post.getSone().isLocal()) { return new ErrorResponse(401, "Not allowed."); } return new Response("PostDeleted", new SimpleFieldSetBuilder().get()); diff --git a/src/main/java/net/pterodactylus/sone/fcp/DeleteReplyCommand.java b/src/main/java/net/pterodactylus/sone/fcp/DeleteReplyCommand.java index daed26d..33374d9 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/DeleteReplyCommand.java +++ b/src/main/java/net/pterodactylus/sone/fcp/DeleteReplyCommand.java @@ -48,7 +48,7 @@ public class DeleteReplyCommand extends AbstractSoneCommand { @Override public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException { PostReply reply = getReply(parameters, "Reply"); - if (!getCore().isLocalSone(reply.getSone())) { + if (!reply.getSone().isLocal()) { return new ErrorResponse(401, "Not allowed."); } return new Response("ReplyDeleted", new SimpleFieldSetBuilder().get()); diff --git a/src/main/java/net/pterodactylus/sone/template/ProfileAccessor.java b/src/main/java/net/pterodactylus/sone/template/ProfileAccessor.java index 1f29b65..ceb3e22 100644 --- a/src/main/java/net/pterodactylus/sone/template/ProfileAccessor.java +++ b/src/main/java/net/pterodactylus/sone/template/ProfileAccessor.java @@ -69,7 +69,7 @@ public class ProfileAccessor extends ReflectionAccessor { return null; } Sone remoteSone = profile.getSone(); - if (core.isLocalSone(remoteSone)) { + if (remoteSone.isLocal()) { /* always show your own avatars. */ return avatarId; } diff --git a/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java b/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java index eac8a93..ffad018 100644 --- a/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java +++ b/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java @@ -75,8 +75,6 @@ public class SoneAccessor extends ReflectionAccessor { Sone sone = (Sone) object; if (member.equals("niceName")) { return getNiceName(sone); - } else if (member.equals("local")) { - return core.isLocalSone(sone); } else if (member.equals("friend")) { Sone currentSone = (Sone) templateContext.get("currentSone"); return (currentSone != null) && currentSone.hasFriend(sone.getId()); diff --git a/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java b/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java index dd0da28..cb23948 100644 --- a/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java +++ b/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java @@ -207,7 +207,7 @@ public class SoneTextParser implements Parser { * don’t use create=true above, we don’t want the * empty shell. */ - sone = new Sone(soneId); + sone = new Sone(soneId, false); } parts.add(new SonePart(sone)); line = line.substring(50); diff --git a/src/main/java/net/pterodactylus/sone/web/DeleteAlbumPage.java b/src/main/java/net/pterodactylus/sone/web/DeleteAlbumPage.java index 2f2b766..e175870 100644 --- a/src/main/java/net/pterodactylus/sone/web/DeleteAlbumPage.java +++ b/src/main/java/net/pterodactylus/sone/web/DeleteAlbumPage.java @@ -54,7 +54,7 @@ public class DeleteAlbumPage extends SoneTemplatePage { if (album == null) { throw new RedirectException("invalid.html"); } - if (!webInterface.getCore().isLocalSone(album.getSone())) { + if (!album.getSone().isLocal()) { throw new RedirectException("noPermission.html"); } if (request.getHttpRequest().isPartSet("abortDelete")) { diff --git a/src/main/java/net/pterodactylus/sone/web/DeleteImagePage.java b/src/main/java/net/pterodactylus/sone/web/DeleteImagePage.java index 3bbaf3d..69b1d27 100644 --- a/src/main/java/net/pterodactylus/sone/web/DeleteImagePage.java +++ b/src/main/java/net/pterodactylus/sone/web/DeleteImagePage.java @@ -57,7 +57,7 @@ public class DeleteImagePage extends SoneTemplatePage { if (image == null) { throw new RedirectException("invalid.html"); } - if (!webInterface.getCore().isLocalSone(image.getSone())) { + if (!image.getSone().isLocal()) { throw new RedirectException("noPermission.html"); } if (request.getMethod() == Method.POST) { diff --git a/src/main/java/net/pterodactylus/sone/web/DeletePostPage.java b/src/main/java/net/pterodactylus/sone/web/DeletePostPage.java index 6689061..314689e 100644 --- a/src/main/java/net/pterodactylus/sone/web/DeletePostPage.java +++ b/src/main/java/net/pterodactylus/sone/web/DeletePostPage.java @@ -63,7 +63,7 @@ public class DeletePostPage extends SoneTemplatePage { String postId = request.getHttpRequest().getPartAsStringFailsafe("post", 36); String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256); Post post = webInterface.getCore().getPost(postId); - if (!webInterface.getCore().isLocalSone(post.getSone())) { + if (!post.getSone().isLocal()) { throw new RedirectException("noPermission.html"); } if (request.getHttpRequest().isPartSet("confirmDelete")) { diff --git a/src/main/java/net/pterodactylus/sone/web/DeleteReplyPage.java b/src/main/java/net/pterodactylus/sone/web/DeleteReplyPage.java index 900acd9..b07dead 100644 --- a/src/main/java/net/pterodactylus/sone/web/DeleteReplyPage.java +++ b/src/main/java/net/pterodactylus/sone/web/DeleteReplyPage.java @@ -56,7 +56,7 @@ public class DeleteReplyPage extends SoneTemplatePage { PostReply reply = webInterface.getCore().getReply(replyId); String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256); if (request.getMethod() == Method.POST) { - if (!webInterface.getCore().isLocalSone(reply.getSone())) { + if (!reply.getSone().isLocal()) { throw new RedirectException("noPermission.html"); } if (request.getHttpRequest().isPartSet("confirmDelete")) { diff --git a/src/main/java/net/pterodactylus/sone/web/EditAlbumPage.java b/src/main/java/net/pterodactylus/sone/web/EditAlbumPage.java index d028f8d..fd28e41 100644 --- a/src/main/java/net/pterodactylus/sone/web/EditAlbumPage.java +++ b/src/main/java/net/pterodactylus/sone/web/EditAlbumPage.java @@ -57,7 +57,7 @@ public class EditAlbumPage extends SoneTemplatePage { if (album == null) { throw new RedirectException("invalid.html"); } - if (!webInterface.getCore().isLocalSone(album.getSone())) { + if (!album.getSone().isLocal()) { throw new RedirectException("noPermission.html"); } if ("true".equals(request.getHttpRequest().getPartAsStringFailsafe("moveLeft", 4))) { diff --git a/src/main/java/net/pterodactylus/sone/web/EditImagePage.java b/src/main/java/net/pterodactylus/sone/web/EditImagePage.java index b0297a8..0207f8c 100644 --- a/src/main/java/net/pterodactylus/sone/web/EditImagePage.java +++ b/src/main/java/net/pterodactylus/sone/web/EditImagePage.java @@ -60,7 +60,7 @@ public class EditImagePage extends SoneTemplatePage { if (image == null) { throw new RedirectException("invalid.html"); } - if (!webInterface.getCore().isLocalSone(image.getSone())) { + if (!image.getSone().isLocal()) { throw new RedirectException("noPermission.html"); } if ("true".equals(request.getHttpRequest().getPartAsStringFailsafe("moveLeft", 4))) { diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 5cc7aff..7654776 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -731,8 +731,8 @@ public class WebInterface implements CoreListener { } /** - * Returns all {@link Core#isLocalSone(Sone) local Sone}s that are - * referenced by {@link SonePart}s in the given text (after parsing it using + * Returns all {@link Core#getLocalSones() local Sone}s that are referenced + * by {@link SonePart}s in the given text (after parsing it using * {@link SoneTextParser}). * * @param text @@ -795,15 +795,14 @@ public class WebInterface implements CoreListener { */ @Override public void newPostFound(Post post) { - boolean isLocal = getCore().isLocalSone(post.getSone()); - if (isLocal) { + if (post.getSone().isLocal()) { localPostNotification.add(post); } else { newPostNotification.add(post); } if (!hasFirstStartNotification()) { - notificationManager.addNotification(isLocal ? localPostNotification : newPostNotification); - if (!getMentionedSones(post.getText()).isEmpty() && !isLocal) { + notificationManager.addNotification(post.getSone().isLocal() ? localPostNotification : newPostNotification); + if (!getMentionedSones(post.getText()).isEmpty() && !post.getSone().isLocal()) { mentionNotification.add(post); notificationManager.addNotification(mentionNotification); } @@ -817,15 +816,14 @@ public class WebInterface implements CoreListener { */ @Override public void newReplyFound(PostReply reply) { - boolean isLocal = getCore().isLocalSone(reply.getSone()); - if (isLocal) { + if (reply.getSone().isLocal()) { localReplyNotification.add(reply); } else { newReplyNotification.add(reply); } if (!hasFirstStartNotification()) { - notificationManager.addNotification(isLocal ? localReplyNotification : newReplyNotification); - if (!getMentionedSones(reply.getText()).isEmpty() && !isLocal && (reply.getPost().getSone() != null) && (reply.getTime() <= System.currentTimeMillis())) { + notificationManager.addNotification(reply.getSone().isLocal() ? localReplyNotification : newReplyNotification); + if (!getMentionedSones(reply.getText()).isEmpty() && !reply.getSone().isLocal() && (reply.getPost().getSone() != null) && (reply.getTime() <= System.currentTimeMillis())) { mentionNotification.add(reply.getPost()); notificationManager.addNotification(mentionNotification); } diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/DeletePostAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/DeletePostAjaxPage.java index ea2310c..b822e52 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/DeletePostAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/DeletePostAjaxPage.java @@ -53,7 +53,7 @@ public class DeletePostAjaxPage extends JsonPage { if ((post == null) || (post.getSone() == null)) { return createErrorJsonObject("invalid-post-id"); } - if (!webInterface.getCore().isLocalSone(post.getSone())) { + if (!post.getSone().isLocal()) { return createErrorJsonObject("not-authorized"); } webInterface.getCore().deletePost(post); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/DeleteReplyAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/DeleteReplyAjaxPage.java index 0442117..6bccf0b 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/DeleteReplyAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/DeleteReplyAjaxPage.java @@ -53,7 +53,7 @@ public class DeleteReplyAjaxPage extends JsonPage { if (reply == null) { return createErrorJsonObject("invalid-reply-id"); } - if (!webInterface.getCore().isLocalSone(reply.getSone())) { + if (!reply.getSone().isLocal()) { return createErrorJsonObject("not-authorized"); } webInterface.getCore().deleteReply(reply); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/EditAlbumAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/EditAlbumAjaxPage.java index 92e1e48..0e72ea5 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/EditAlbumAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/EditAlbumAjaxPage.java @@ -54,7 +54,7 @@ public class EditAlbumAjaxPage extends JsonPage { if (album == null) { return createErrorJsonObject("invalid-album-id"); } - if (!webInterface.getCore().isLocalSone(album.getSone())) { + if (!album.getSone().isLocal()) { return createErrorJsonObject("not-authorized"); } if ("true".equals(request.getHttpRequest().getParam("moveLeft"))) { diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/EditImageAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/EditImageAjaxPage.java index 9e04a30..b549718 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/EditImageAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/EditImageAjaxPage.java @@ -63,7 +63,7 @@ public class EditImageAjaxPage extends JsonPage { if (image == null) { return createErrorJsonObject("invalid-image-id"); } - if (!webInterface.getCore().isLocalSone(image.getSone())) { + if (!image.getSone().isLocal()) { return createErrorJsonObject("not-authorized"); } if ("true".equals(request.getHttpRequest().getParam("moveLeft"))) { diff --git a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java index 7de50fb..9b1d11d 100644 --- a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java +++ b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java @@ -161,7 +161,7 @@ public class SoneTextParserTest extends TestCase { */ @Override public Sone getSone(final String soneId, boolean create) { - return new Sone(soneId) { + return new Sone(soneId, false) { /** * {@inheritDoc} -- 2.7.4