Return replies to old post ID in compatibility mode
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 31 Jul 2015 15:00:34 +0000 (17:00 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 31 Jul 2015 15:00:34 +0000 (17:00 +0200)
src/main/java/net/pterodactylus/sone/core/Core.java

index 140d80c..e56eede 100644 (file)
@@ -103,8 +103,11 @@ import com.google.common.base.Optional;
 import com.google.common.base.Predicate;
 import com.google.common.collect.FluentIterable;
 import com.google.common.collect.HashMultimap;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
 import com.google.common.collect.Multimap;
 import com.google.common.collect.Multimaps;
+import com.google.common.collect.Ordering;
 import com.google.common.eventbus.EventBus;
 import com.google.common.eventbus.Subscribe;
 import com.google.inject.Inject;
@@ -489,7 +492,14 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
         */
        @Override
        public List<PostReply> getReplies(final String postId) {
-               return database.getReplies(postId);
+               Builder<PostReply> postReplies = ImmutableList.<PostReply>builder().addAll(database.getReplies(postId));
+               if (isCompatibilityMode(CompatibilityMode.oldElementIds)) {
+                       Optional<Post> post = getPost(postId);
+                       if (post.isPresent()) {
+                               postReplies.addAll(database.getReplies(post.get().getInternalId()));
+                       }
+               }
+               return Ordering.from(Reply.TIME_COMPARATOR).sortedCopy(postReplies.build());
        }
 
        /**