Don’t store posts by recipient, generate them on the fly.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / Core.java
index 9e20c00..7d38ed9 100644 (file)
@@ -78,6 +78,7 @@ import net.pterodactylus.sone.data.TemporaryImage;
 import net.pterodactylus.sone.database.AlbumBuilder;
 import net.pterodactylus.sone.database.Database;
 import net.pterodactylus.sone.database.DatabaseException;
+import net.pterodactylus.sone.database.ImageBuilder;
 import net.pterodactylus.sone.database.PostBuilder;
 import net.pterodactylus.sone.database.PostProvider;
 import net.pterodactylus.sone.database.PostReplyBuilder;
@@ -610,6 +611,10 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                return database.getAlbum(albumId).orNull();
        }
 
+       public ImageBuilder imageBuilder() {
+               return database.newImageBuilder();
+       }
+
        /**
         * Returns the image with the given ID, creating it if necessary.
         *
@@ -1009,7 +1014,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                        for (PostReply newPostReply : newPostReplies) {
                                eventBus.post(new NewPostReplyFoundEvent(newPostReply));
                        }
-                       for (Album album : sone.getRootAlbum().getAlbums()) {
+                       for (Album album : toAllAlbums.apply(sone)) {
                                database.storeAlbum(album);
                                for (Image image : album.getImages()) {
                                        database.storeImage(image);
@@ -1947,19 +1952,14 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                OwnIdentity ownIdentity = identityRemovedEvent.ownIdentity();
                Identity identity = identityRemovedEvent.identity();
                trustedIdentities.remove(ownIdentity, identity);
-               boolean foundIdentity = false;
                for (Entry<OwnIdentity, Collection<Identity>> trustedIdentity : trustedIdentities.asMap().entrySet()) {
                        if (trustedIdentity.getKey().equals(ownIdentity)) {
                                continue;
                        }
                        if (trustedIdentity.getValue().contains(identity)) {
-                               foundIdentity = true;
+                               return;
                        }
                }
-               if (foundIdentity) {
-                       /* some local identity still trusts this identity, don’t remove. */
-                       return;
-               }
                Optional<Sone> sone = getSone(identity.getId());
                if (!sone.isPresent()) {
                        /* TODO - we don’t have the Sone anymore. should this happen? */