From 64abaf4ca1924732a99eeb9f1f461acbeda82a43 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 24 Jul 2015 16:47:58 +0200 Subject: [PATCH] Use compatibility mode when getting posts --- src/main/java/net/pterodactylus/sone/core/Core.java | 14 ++++++++++++-- src/main/java/net/pterodactylus/sone/data/Sone.java | 7 +++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 90fc314..c1d51a3 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -99,6 +99,7 @@ import net.pterodactylus.util.thread.NamedThreadFactory; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; 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.Multimap; @@ -435,8 +436,17 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, * {@inheritDoc} */ @Override - public Optional getPost(String postId) { - return database.getPost(postId); + public Optional getPost(final String postId) { + Optional post = database.getPost(postId); + if (post.isPresent() || !isCompatibilityMode(CompatibilityMode.oldElementIds)) { + return post; + } + return FluentIterable.from(getSones()).transformAndConcat(Sone.toAllPosts).filter(new Predicate() { + @Override + public boolean apply(Post input) { + return (input != null) && input.getInternalId().equals(postId); + } + }).first(); } /** diff --git a/src/main/java/net/pterodactylus/sone/data/Sone.java b/src/main/java/net/pterodactylus/sone/data/Sone.java index 4d0905f..7acdb7f 100644 --- a/src/main/java/net/pterodactylus/sone/data/Sone.java +++ b/src/main/java/net/pterodactylus/sone/data/Sone.java @@ -189,6 +189,13 @@ public interface Sone extends Identified, Fingerprintable, Comparable { } }; + Function> toAllPosts = new Function>() { + @Override + public Collection apply(@Nullable Sone sone) { + return (sone != null) ? sone.getPosts() : Collections.emptyList(); + } + }; + /** * Returns the identity of this Sone. * -- 2.7.4