Remove post reply management from Sone.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / SoneParser.java
index d2914da..6056a7f 100644 (file)
@@ -191,15 +191,14 @@ public class SoneParser {
                        }
                        soneBuilder.withPosts(posts);
                }
-               Sone sone = soneBuilder.build();
 
                /* parse replies. */
                SimpleXML repliesXml = soneXml.getNode("replies");
-               Set<PostReply> replies = new HashSet<PostReply>();
                if (repliesXml == null) {
                        /* TODO - mark Sone as bad. */
-                       logger.log(Level.WARNING, String.format("Downloaded Sone %s has no replies!", sone));
+                       logger.log(Level.WARNING, String.format("Downloaded Sone %s has no replies!", originalSone));
                } else {
+                       Set<PostReply> replies = new HashSet<PostReply>();
                        for (SimpleXML replyXml : repliesXml.getNodes("reply")) {
                                String replyId = replyXml.getValue("id", null);
                                String replyPostId = replyXml.getValue("post-id", null);
@@ -207,21 +206,23 @@ public class SoneParser {
                                String replyText = replyXml.getValue("text", null);
                                if ((replyId == null) || (replyPostId == null) || (replyTime == null) || (replyText == null)) {
                                        /* TODO - mark Sone as bad. */
-                                       logger.log(Level.WARNING, String.format("Downloaded reply for Sone %s with missing data! ID: %s, Post: %s, Time: %s, Text: %s", sone, replyId, replyPostId, replyTime, replyText));
+                                       logger.log(Level.WARNING, String.format("Downloaded reply for Sone %s with missing data! ID: %s, Post: %s, Time: %s, Text: %s", originalSone, replyId, replyPostId, replyTime, replyText));
                                        return null;
                                }
                                try {
                                        PostReplyBuilder postReplyBuilder = core.postReplyBuilder();
                                        /* TODO - parse time correctly. */
-                                       postReplyBuilder.withId(replyId).from(sone.getId()).to(replyPostId).withTime(Long.parseLong(replyTime)).withText(replyText);
+                                       postReplyBuilder.withId(replyId).from(originalSone.getId()).to(replyPostId).withTime(Long.parseLong(replyTime)).withText(replyText);
                                        replies.add(postReplyBuilder.build());
                                } catch (NumberFormatException nfe1) {
                                        /* TODO - mark Sone as bad. */
-                                       logger.log(Level.WARNING, String.format("Downloaded reply for Sone %s with invalid time: %s", sone, replyTime));
+                                       logger.log(Level.WARNING, String.format("Downloaded reply for Sone %s with invalid time: %s", originalSone, replyTime));
                                        return null;
                                }
                        }
+                       soneBuilder.withPostReplies(replies);
                }
+               Sone sone = soneBuilder.build();
 
                /* parse liked post IDs. */
                SimpleXML likePostIdsXml = soneXml.getNode("post-likes");
@@ -326,7 +327,6 @@ public class SoneParser {
                /* atomic setter operation on the Sone. */
                synchronized (sone) {
                        sone.setProfile(profile);
-                       sone.setReplies(replies);
                        sone.setLikePostIds(likedPostIds);
                        sone.setLikeReplyIds(likedReplyIds);
                        for (Album album : topLevelAlbums) {