Process albums and images during rescue mode, too.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / Core.java
index e67bf68..8aac5d7 100644 (file)
@@ -712,7 +712,6 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
         */
        public List<Reply> getReplies(Post post) {
                Set<Sone> sones = getSones();
-               @SuppressWarnings("hiding")
                List<Reply> replies = new ArrayList<Reply>();
                for (Sone sone : sones) {
                        for (Reply reply : sone.getReplies()) {
@@ -805,7 +804,6 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
         * @return All bookmarked posts
         */
        public Set<Post> getBookmarkedPosts() {
-               @SuppressWarnings("hiding")
                Set<Post> posts = new HashSet<Post>();
                synchronized (bookmarkedPosts) {
                        for (String bookmarkedPostId : bookmarkedPosts) {
@@ -1225,6 +1223,22 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                                        }
                                }
                        }
+                       synchronized (albums) {
+                               synchronized (images) {
+                                       for (Album album : storedSone.getAlbums()) {
+                                               albums.remove(album.getId());
+                                               for (Image image : album.getImages()) {
+                                                       images.remove(image.getId());
+                                               }
+                                       }
+                                       for (Album album : sone.getAlbums()) {
+                                               albums.put(album.getId(), album);
+                                               for (Image image : album.getImages()) {
+                                                       images.put(image.getId(), image);
+                                               }
+                                       }
+                               }
+                       }
                        synchronized (storedSone) {
                                if (!soneRescueMode || (sone.getTime() > storedSone.getTime())) {
                                        storedSone.setTime(sone.getTime());
@@ -1244,6 +1258,9 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                                        for (String likedReplyId : sone.getLikedReplyIds()) {
                                                storedSone.addLikedReplyId(likedReplyId);
                                        }
+                                       for (Album album : sone.getAlbums()) {
+                                               storedSone.addAlbum(album);
+                                       }
                                } else {
                                        storedSone.setPosts(sone.getPosts());
                                        storedSone.setReplies(sone.getReplies());
@@ -1356,7 +1373,6 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                }
 
                /* load posts. */
-               @SuppressWarnings("hiding")
                Set<Post> posts = new HashSet<Post>();
                while (true) {
                        String postPrefix = sonePrefix + "/Posts/" + posts.size();
@@ -1379,7 +1395,6 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                }
 
                /* load replies. */
-               @SuppressWarnings("hiding")
                Set<Reply> replies = new HashSet<Reply>();
                while (true) {
                        String replyPrefix = sonePrefix + "/Replies/" + replies.size();
@@ -1439,11 +1454,12 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                        String albumTitle = configuration.getStringValue(albumPrefix + "/Title").getValue(null);
                        String albumDescription = configuration.getStringValue(albumPrefix + "/Description").getValue(null);
                        String albumParentId = configuration.getStringValue(albumPrefix + "/Parent").getValue(null);
+                       String albumImageId = configuration.getStringValue(albumPrefix + "/AlbumImage").getValue(null);
                        if ((albumTitle == null) || (albumDescription == null)) {
                                logger.log(Level.WARNING, "Invalid album found, aborting load!");
                                return;
                        }
-                       Album album = getAlbum(albumId).setSone(sone).setTitle(albumTitle).setDescription(albumDescription);
+                       Album album = getAlbum(albumId).setSone(sone).setTitle(albumTitle).setDescription(albumDescription).setAlbumImage(albumImageId);
                        if (albumParentId != null) {
                                Album parentAlbum = getAlbum(albumParentId, false);
                                if (parentAlbum == null) {
@@ -2090,6 +2106,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                                configuration.getStringValue(albumPrefix + "/Title").setValue(album.getTitle());
                                configuration.getStringValue(albumPrefix + "/Description").setValue(album.getDescription());
                                configuration.getStringValue(albumPrefix + "/Parent").setValue(album.getParent() == null ? null : album.getParent().getId());
+                               configuration.getStringValue(albumPrefix + "/AlbumImage").setValue(album.getAlbumImage() == null ? null : album.getAlbumImage().getId());
                        }
                        configuration.getStringValue(sonePrefix + "/Albums/" + albumCounter + "/ID").setValue(null);