X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FSoneInserter.java;h=8c24fc0bd135a7cc0c55d62b3bf1405791e62d6e;hb=f333f58180a7f112394cd768d86c95a3c9edf794;hp=4f74fe53d6f818e4e0482861c1d0916bab46be6c;hpb=5bcc4f8e8d920408cf0c940ba67f6a1ebf9c4228;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java index 4f74fe5..8c24fc0 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java @@ -44,6 +44,7 @@ import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.data.Sone.SoneStatus; +import net.pterodactylus.sone.database.Database; import net.pterodactylus.sone.freenet.StringBucket; import net.pterodactylus.sone.main.SonePlugin; import net.pterodactylus.util.io.Closer; @@ -100,7 +101,7 @@ public class SoneInserter extends AbstractService { /** The Freenet interface. */ private final FreenetInterface freenetInterface; - + private final Database database; private final SoneModificationDetector soneModificationDetector; private final long delay; private final String soneId; @@ -117,8 +118,8 @@ public class SoneInserter extends AbstractService { * @param soneId * The ID of the Sone to insert */ - public SoneInserter(final Core core, EventBus eventBus, FreenetInterface freenetInterface, final String soneId) { - this(core, eventBus, freenetInterface, soneId, new SoneModificationDetector(new LockableFingerprintProvider() { + public SoneInserter(final Core core, EventBus eventBus, FreenetInterface freenetInterface, Database database, final String soneId) { + this(core, eventBus, freenetInterface, database, soneId, new SoneModificationDetector(new LockableFingerprintProvider() { @Override public boolean isLocked() { final Optional sone = core.getLocalSone(soneId); @@ -140,11 +141,12 @@ public class SoneInserter extends AbstractService { } @VisibleForTesting - SoneInserter(Core core, EventBus eventBus, FreenetInterface freenetInterface, String soneId, SoneModificationDetector soneModificationDetector, long delay) { + SoneInserter(Core core, EventBus eventBus, FreenetInterface freenetInterface, Database database, String soneId, SoneModificationDetector soneModificationDetector, long delay) { super("Sone Inserter for “" + soneId + "”", false); this.core = core; this.eventBus = eventBus; this.freenetInterface = freenetInterface; + this.database = database; this.soneId = soneId; this.soneModificationDetector = soneModificationDetector; this.delay = delay; @@ -215,12 +217,12 @@ public class SoneInserter extends AbstractService { sleep(delay); if (soneModificationDetector.isEligibleForInsert()) { - Optional soneOptional = core.getSone(soneId); + Optional soneOptional = core.getLocalSone(soneId); if (!soneOptional.isPresent()) { logger.log(Level.WARNING, format("Sone %s has disappeared, exiting inserter.", soneId)); return; } - Sone sone = soneOptional.get(); + LocalSone sone = soneOptional.get(); InsertInformation insertInformation = new InsertInformation(sone); logger.log(Level.INFO, String.format("Inserting Sone “%s”…", sone.getName())); @@ -236,7 +238,7 @@ public class SoneInserter extends AbstractService { /* if so, bail out, don’t change anything. */ break; } - sone.setTime(insertTime); + database.updateSoneTime(sone, insertTime); sone.setLatestEdition(finalUri.getEdition()); core.touchConfiguration(); success = true;