Use event bus to change FCP interface configuration.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / Core.java
index ef05eba..12e700e 100644 (file)
@@ -23,7 +23,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.primitives.Longs.tryParse;
 import static java.lang.String.format;
 import static java.util.logging.Level.WARNING;
-import static net.pterodactylus.sone.data.Sone.toAllAlbums;
 
 import java.util.Collection;
 import java.util.HashMap;
@@ -47,7 +46,6 @@ import net.pterodactylus.sone.core.ConfigurationSoneParser.InvalidPostReplyFound
 import net.pterodactylus.sone.core.Options.DefaultOption;
 import net.pterodactylus.sone.core.SoneChangeDetector.PostProcessor;
 import net.pterodactylus.sone.core.SoneChangeDetector.PostReplyProcessor;
-import net.pterodactylus.sone.core.SoneInserter.SetInsertionDelay;
 import net.pterodactylus.sone.core.event.ImageInsertFinishedEvent;
 import net.pterodactylus.sone.core.event.MarkPostKnownEvent;
 import net.pterodactylus.sone.core.event.MarkPostReplyKnownEvent;
@@ -71,7 +69,6 @@ import net.pterodactylus.sone.data.Reply;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.data.Sone.ShowCustomAvatars;
 import net.pterodactylus.sone.data.Sone.SoneStatus;
-import net.pterodactylus.sone.data.SoneImpl;
 import net.pterodactylus.sone.data.TemporaryImage;
 import net.pterodactylus.sone.database.AlbumBuilder;
 import net.pterodactylus.sone.database.Database;
@@ -131,7 +128,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
        private final Options options = new Options();
 
        /** The preferences. */
-       private final Preferences preferences = new Preferences(options);
+       private final Preferences preferences;
 
        /** The event bus. */
        private final EventBus eventBus;
@@ -231,6 +228,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                this.webOfTrustUpdater = webOfTrustUpdater;
                this.eventBus = eventBus;
                this.database = database;
+               preferences = new Preferences(this.eventBus, options);
        }
 
        @VisibleForTesting
@@ -245,6 +243,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                this.webOfTrustUpdater = webOfTrustUpdater;
                this.eventBus = eventBus;
                this.database = database;
+               preferences = new Preferences(this.eventBus, options);
        }
 
        //
@@ -688,6 +687,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                sone.setKnown(true);
                /* TODO - load posts ’n stuff */
                SoneInserter soneInserter = new SoneInserter(this, eventBus, freenetInterface, ownIdentity.getId());
+               eventBus.register(soneInserter);
                synchronized (soneInserters) {
                        soneInserters.put(sone, soneInserter);
                }
@@ -736,7 +736,6 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                }
                boolean newSone = !existingSone.isPresent();
                Sone sone = !newSone ? existingSone.get() : database.newSoneBuilder().from(identity).build();
-               sone.setRequestUri(SoneUri.create(identity.getRequestUri()));
                sone.setLatestEdition(latestEdition);
                if (newSone) {
                        synchronized (knownSones) {
@@ -1721,7 +1720,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
         */
        private void loadConfiguration() {
                /* create options. */
-               options.addIntegerOption("InsertionDelay", new DefaultOption<Integer>(60, new IntegerRangePredicate(0, Integer.MAX_VALUE), new SetInsertionDelay()));
+               options.addIntegerOption("InsertionDelay", new DefaultOption<Integer>(60, new IntegerRangePredicate(0, Integer.MAX_VALUE)));
                options.addIntegerOption("PostsPerPage", new DefaultOption<Integer>(10, new IntegerRangePredicate(1, Integer.MAX_VALUE)));
                options.addIntegerOption("ImagesPerPage", new DefaultOption<Integer>(9, new IntegerRangePredicate(1, Integer.MAX_VALUE)));
                options.addIntegerOption("CharactersPerPost", new DefaultOption<Integer>(400, Predicates.<Integer> or(new IntegerRangePredicate(50, Integer.MAX_VALUE), Predicates.equalTo(-1))));
@@ -1730,8 +1729,8 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                options.addIntegerOption("PositiveTrust", new DefaultOption<Integer>(75, new IntegerRangePredicate(0, 100)));
                options.addIntegerOption("NegativeTrust", new DefaultOption<Integer>(-25, new IntegerRangePredicate(-100, 100)));
                options.addStringOption("TrustComment", new DefaultOption<String>("Set from Sone Web Interface"));
-               options.addBooleanOption("ActivateFcpInterface", new DefaultOption<Boolean>(false, fcpInterface.new SetActive()));
-               options.addIntegerOption("FcpFullAccessRequired", new DefaultOption<Integer>(2, fcpInterface.new SetFullAccessRequired()));
+               options.addBooleanOption("ActivateFcpInterface", new DefaultOption<Boolean>(false));
+               options.addIntegerOption("FcpFullAccessRequired", new DefaultOption<Integer>(2));
 
                loadConfigurationValue("InsertionDelay");
                loadConfigurationValue("PostsPerPage");