import net.pterodactylus.sone.core.Options.DefaultOption;
import net.pterodactylus.sone.core.Options.Option;
import net.pterodactylus.sone.core.Options.OptionWatcher;
+import net.pterodactylus.sone.core.event.NewPostFoundEvent;
+import net.pterodactylus.sone.core.event.NewSoneFoundEvent;
import net.pterodactylus.sone.data.Album;
import net.pterodactylus.sone.data.Client;
import net.pterodactylus.sone.data.Image;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
+import com.google.common.eventbus.EventBus;
+import com.google.inject.Inject;
+
import freenet.keys.FreenetURI;
/**
/** The core listener manager. */
private final CoreListenerManager coreListenerManager = new CoreListenerManager(this);
+ /** The event bus. */
+ private final EventBus eventBus;
+
/** The configuration. */
private Configuration configuration;
* The identity manager
* @param webOfTrustUpdater
* The WebOfTrust updater
+ * @param eventBus
+ * The event bus
*/
- public Core(Configuration configuration, FreenetInterface freenetInterface, IdentityManager identityManager, WebOfTrustUpdater webOfTrustUpdater) {
+ @Inject
+ public Core(Configuration configuration, FreenetInterface freenetInterface, IdentityManager identityManager, WebOfTrustUpdater webOfTrustUpdater, EventBus eventBus) {
super("Sone Core");
this.configuration = configuration;
this.freenetInterface = freenetInterface;
this.imageInserter = new ImageInserter(this, freenetInterface);
this.updateChecker = new UpdateChecker(freenetInterface);
this.webOfTrustUpdater = webOfTrustUpdater;
+ this.eventBus = eventBus;
}
//
sone = new Sone(id, true);
sones.put(id, sone);
}
- if (!sone.isLocal()) {
+ if ((sone != null) && !sone.isLocal()) {
sone = new Sone(id, true);
sones.put(id, sone);
}
}
sone.setKnown(!newSone);
if (newSone) {
- coreListenerManager.fireNewSoneFound(sone);
+ eventBus.post(new NewSoneFoundEvent(sone));
for (Sone localSone : getLocalSones()) {
if (localSone.getOptions().getBooleanOption("AutoFollow").get()) {
followSone(localSone, sone);
knownPosts.add(post.getId());
post.setKnown(true);
} else if (!knownPosts.contains(post.getId())) {
- coreListenerManager.fireNewPostFound(post);
+ eventBus.post(new NewPostFoundEvent(post));
}
}
posts.put(post.getId(), post);
synchronized (posts) {
posts.put(post.getId(), post);
}
- coreListenerManager.fireNewPostFound(post);
+ eventBus.post(new NewPostFoundEvent(post));
sone.addPost(post);
touchConfiguration();
localElementTicker.registerEvent(System.currentTimeMillis() + 10 * 1000, new Runnable() {
loadConfiguration();
updateChecker.addUpdateListener(this);
updateChecker.start();
+ identityManager.addIdentityListener(this);
+ identityManager.start();
+ webOfTrustUpdater.init();
webOfTrustUpdater.start();
}
updateChecker.stop();
updateChecker.removeUpdateListener(this);
soneDownloader.stop();
+ identityManager.removeIdentityListener(this);
+ identityManager.stop();
}
//