From 5bcc4f8e8d920408cf0c940ba67f6a1ebf9c4228 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 2 Dec 2014 22:35:03 +0100 Subject: [PATCH] Use local Sones when handling locking. --- src/main/java/net/pterodactylus/sone/core/Core.java | 12 ++++++------ src/main/java/net/pterodactylus/sone/core/SoneInserter.java | 3 ++- .../java/net/pterodactylus/sone/template/SoneAccessor.java | 3 ++- .../net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 84e7499..ba2b15c 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -148,7 +148,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, /** Locked local Sones. */ /* synchronize on itself. */ - private final Set lockedSones = new HashSet(); + private final Set lockedSones = new HashSet(); /** Sone inserters. */ /* synchronize access on this on sones. */ @@ -289,7 +289,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, * The sone to check * @return {@code true} if the Sone is locked, {@code false} if it is not */ - public boolean isLocked(Sone sone) { + public boolean isLocked(LocalSone sone) { synchronized (lockedSones) { return lockedSones.contains(sone); } @@ -572,13 +572,13 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, /** * Locks the given Sone. A locked Sone will not be inserted by - * {@link SoneInserter} until it is {@link #unlockSone(Sone) unlocked} + * {@link SoneInserter} until it is {@link #unlockSone(LocalSone) unlocked} * again. * * @param sone * The sone to lock */ - public void lockSone(Sone sone) { + public void lockSone(LocalSone sone) { synchronized (lockedSones) { if (lockedSones.add(sone)) { eventBus.post(new SoneLockedEvent(sone)); @@ -589,11 +589,11 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, /** * Unlocks the given Sone. * - * @see #lockSone(Sone) + * @see #lockSone(LocalSone) * @param sone * The sone to unlock */ - public void unlockSone(Sone sone) { + public void unlockSone(LocalSone sone) { synchronized (lockedSones) { if (lockedSones.remove(sone)) { eventBus.post(new SoneUnlockedEvent(sone)); diff --git a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java index 33bc240..4f74fe5 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java @@ -39,6 +39,7 @@ import net.pterodactylus.sone.core.event.SoneInsertAbortedEvent; import net.pterodactylus.sone.core.event.SoneInsertedEvent; import net.pterodactylus.sone.core.event.SoneInsertingEvent; import net.pterodactylus.sone.data.Album; +import net.pterodactylus.sone.data.LocalSone; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; @@ -120,7 +121,7 @@ public class SoneInserter extends AbstractService { this(core, eventBus, freenetInterface, soneId, new SoneModificationDetector(new LockableFingerprintProvider() { @Override public boolean isLocked() { - final Optional sone = core.getSone(soneId); + final Optional sone = core.getLocalSone(soneId); if (!sone.isPresent()) { return false; } diff --git a/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java b/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java index 711332a..6c5ca06 100644 --- a/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java +++ b/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java @@ -27,6 +27,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import net.pterodactylus.sone.core.Core; +import net.pterodactylus.sone.data.LocalSone; import net.pterodactylus.sone.data.Profile; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.data.Sone.SoneStatus; @@ -102,7 +103,7 @@ public class SoneAccessor extends ReflectionAccessor { } else if (member.equals("new")) { return !sone.isKnown(); } else if (member.equals("locked")) { - return core.isLocked(sone); + return sone.isLocal() ? core.isLocked((LocalSone) sone) : false; } else if (member.equals("lastUpdatedText")) { return GetTimesAjaxPage.getTime((WebInterface) templateContext.get("webInterface"), sone.getTime()); } else if (member.equals("trust")) { diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java index 84c96dd..c269627 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java @@ -174,7 +174,7 @@ public class GetStatusAjaxPage extends JsonPage { jsonSone.put("local", sone.getInsertUri() != null); jsonSone.put("status", sone.getStatus().name()); jsonSone.put("modified", webInterface.getCore().isModifiedSone(sone)); - jsonSone.put("locked", webInterface.getCore().isLocked(sone)); + jsonSone.put("locked", sone.isLocal() ? webInterface.getCore().isLocked((LocalSone) sone) : false); jsonSone.put("lastUpdatedUnknown", sone.getTime() == 0); synchronized (dateFormat) { jsonSone.put("lastUpdated", dateFormat.format(new Date(sone.getTime()))); -- 2.7.4