From: David ‘Bombe’ Roden Date: Fri, 24 Jul 2015 14:47:58 +0000 (+0200) Subject: Use compatibility mode when getting posts X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=64abaf4ca1924732a99eeb9f1f461acbeda82a43;p=Sone.git Use compatibility mode when getting posts --- 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. *