Merge branch 'release-0.9.7'
[Sone.git] / src / main / java / net / pterodactylus / sone / core / Core.java
index 5a95810..66677de 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Sone - Core.java - Copyright © 2010–2015 David Roden
+ * Sone - Core.java - Copyright © 2010–2016 David Roden
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -40,6 +40,9 @@ import java.util.concurrent.TimeUnit;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
 import net.pterodactylus.sone.core.ConfigurationSoneParser.InvalidAlbumFound;
 import net.pterodactylus.sone.core.ConfigurationSoneParser.InvalidImageFound;
 import net.pterodactylus.sone.core.ConfigurationSoneParser.InvalidParentAlbumFound;
@@ -68,8 +71,8 @@ import net.pterodactylus.sone.data.Profile;
 import net.pterodactylus.sone.data.Profile.Field;
 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.SoneOptions.LoadExternalContent;
 import net.pterodactylus.sone.data.TemporaryImage;
 import net.pterodactylus.sone.database.AlbumBuilder;
 import net.pterodactylus.sone.database.Database;
@@ -314,6 +317,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
        /**
         * {@inheritDocs}
         */
+       @Nonnull
        @Override
        public Collection<Sone> getSones() {
                return database.getSones();
@@ -534,7 +538,8 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
         * @return The album with the given ID, or {@code null} if no album with the
         *         given ID exists
         */
-       public Album getAlbum(String albumId) {
+       @Nullable
+       public Album getAlbum(@Nonnull String albumId) {
                return database.getAlbum(albumId).orNull();
        }
 
@@ -549,6 +554,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
         *            The ID of the image
         * @return The image with the given ID
         */
+       @Nullable
        public Image getImage(String imageId) {
                return getImage(imageId, true);
        }
@@ -565,6 +571,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
         * @return The image with the given ID, or {@code null} if none exists and
         *         none was created
         */
+       @Nullable
        public Image getImage(String imageId, boolean create) {
                Optional<Image> image = database.getImage(imageId);
                if (image.isPresent()) {
@@ -643,7 +650,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                Sone sone = database.newSoneBuilder().local().from(ownIdentity).build();
                String property = fromNullable(ownIdentity.getProperty("Sone.LatestEdition")).or("0");
                sone.setLatestEdition(fromNullable(tryParse(property)).or(0L));
-               sone.setClient(new Client("Sone", SonePlugin.VERSION.toString()));
+               sone.setClient(new Client("Sone", SonePlugin.getPluginVersion()));
                sone.setKnown(true);
                SoneInserter soneInserter = new SoneInserter(this, eventBus, freenetInterface, ownIdentity.getId());
                eventBus.register(soneInserter);
@@ -1070,7 +1077,8 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                sone.getOptions().setShowNewSoneNotifications(configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewSones").getValue(true));
                sone.getOptions().setShowNewPostNotifications(configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewPosts").getValue(true));
                sone.getOptions().setShowNewReplyNotifications(configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewReplies").getValue(true));
-               sone.getOptions().setShowCustomAvatars(ShowCustomAvatars.valueOf(configuration.getStringValue(sonePrefix + "/Options/ShowCustomAvatars").getValue(ShowCustomAvatars.NEVER.name())));
+               sone.getOptions().setShowCustomAvatars(LoadExternalContent.valueOf(configuration.getStringValue(sonePrefix + "/Options/ShowCustomAvatars").getValue(LoadExternalContent.NEVER.name())));
+               sone.getOptions().setLoadLinkedImages(LoadExternalContent.valueOf(configuration.getStringValue(sonePrefix + "/Options/LoadLinkedImages").getValue(LoadExternalContent.NEVER.name())));
 
                /* if we’re still here, Sone was loaded successfully. */
                synchronized (sone) {
@@ -1518,7 +1526,6 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                                configuration.getStringValue(albumPrefix + "/Title").setValue(album.getTitle());
                                configuration.getStringValue(albumPrefix + "/Description").setValue(album.getDescription());
                                configuration.getStringValue(albumPrefix + "/Parent").setValue(album.getParent().equals(sone.getRootAlbum()) ? null : album.getParent().getId());
-                               configuration.getStringValue(albumPrefix + "/AlbumImage").setValue(album.getAlbumImage() == null ? null : album.getAlbumImage().getId());
                        }
                        configuration.getStringValue(sonePrefix + "/Albums/" + albumCounter + "/ID").setValue(null);
 
@@ -1549,6 +1556,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                        configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewPosts").setValue(sone.getOptions().isShowNewPostNotifications());
                        configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewReplies").setValue(sone.getOptions().isShowNewReplyNotifications());
                        configuration.getStringValue(sonePrefix + "/Options/ShowCustomAvatars").setValue(sone.getOptions().getShowCustomAvatars().name());
+                       configuration.getStringValue(sonePrefix + "/Options/LoadLinkedImages").setValue(sone.getOptions().getLoadLinkedImages().name());
 
                        configuration.save();
 
@@ -1730,8 +1738,14 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                        /* TODO - we don’t have the Sone anymore. should this happen? */
                        return;
                }
-               database.removeSone(sone.get());
+               for (PostReply postReply : sone.get().getReplies()) {
+                       eventBus.post(new PostReplyRemovedEvent(postReply));
+               }
+               for (Post post : sone.get().getPosts()) {
+                       eventBus.post(new PostRemovedEvent(post));
+               }
                eventBus.post(new SoneRemovedEvent(sone.get()));
+               database.removeSone(sone.get());
        }
 
        /**