From 017c1d62562d45ecb7d01faf2f320a9d87673506 Mon Sep 17 00:00:00 2001 From: Marcus Fihlon Date: Sat, 30 Nov 2024 20:22:59 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20identify=20replies=20#23?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/social/bluesky/BlueSkyPlugin.java | 3 ++- .../plugin/social/bluesky/BlueSkyPluginTest.java | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/swiss/fihlon/apus/plugin/social/bluesky/BlueSkyPlugin.java b/src/main/java/swiss/fihlon/apus/plugin/social/bluesky/BlueSkyPlugin.java index 74484e0..8ddcac0 100644 --- a/src/main/java/swiss/fihlon/apus/plugin/social/bluesky/BlueSkyPlugin.java +++ b/src/main/java/swiss/fihlon/apus/plugin/social/bluesky/BlueSkyPlugin.java @@ -93,6 +93,7 @@ private Post createPost(final @NotNull JSONObject post) { final var postRecord = post.getJSONObject("record"); final var text = postRecord.getString("text"); + final var isReply = postRecord.has("reply"); final var date = ZonedDateTime.parse(postRecord.getString("createdAt")).toLocalDateTime(); final var imageLinks = new ArrayList(); @@ -106,6 +107,6 @@ private Post createPost(final @NotNull JSONObject post) { } } - return new Post(id, date, displayName, avatar, handle, text, imageLinks, false, false); + return new Post(id, date, displayName, avatar, handle, text, imageLinks, isReply, false); } } diff --git a/src/test/java/swiss/fihlon/apus/plugin/social/bluesky/BlueSkyPluginTest.java b/src/test/java/swiss/fihlon/apus/plugin/social/bluesky/BlueSkyPluginTest.java index 08de9af..ca672fa 100644 --- a/src/test/java/swiss/fihlon/apus/plugin/social/bluesky/BlueSkyPluginTest.java +++ b/src/test/java/swiss/fihlon/apus/plugin/social/bluesky/BlueSkyPluginTest.java @@ -24,7 +24,6 @@ import org.jetbrains.annotations.Nullable; import org.json.JSONArray; import org.json.JSONObject; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -185,7 +184,6 @@ void getPostsCatchesException() { } @Test - @Disabled("Replies are not jet implemented for BlueSky posts.") void testReplyConversion() { final var configuration = mock(Configuration.class); final var blueSkyConfig = new BlueSkyConfig("localhost", "foobar", "https://%s/q=%s"); @@ -233,6 +231,16 @@ private static final class TestBlueSkyLoader implements BlueSkyLoader { private JSONObject createPost(final int i) { final var createdAt = ZonedDateTime.of(LocalDateTime.now().minusMinutes(i), ZoneId.systemDefault()); + final var fakeReply = """ + "reply": { + "parent": { + "uri": "ID 1" + }, + "root": { + "uri": "ID 1" + } + }, + """; final var postJSON = """ { @@ -244,6 +252,7 @@ private JSONObject createPost(final int i) { }, "record": { "createdAt": "${createdAt}", + ${reply} "text": "Content for post #${i}" }, "embed": { @@ -260,7 +269,8 @@ private JSONObject createPost(final int i) { } """ .replaceAll(Pattern.quote("${i}"), Integer.toString(i)) - .replaceAll(Pattern.quote("${createdAt}"), createdAt.format(DATE_TIME_FORMATTER)); + .replaceAll(Pattern.quote("${createdAt}"), createdAt.format(DATE_TIME_FORMATTER)) + .replaceAll(Pattern.quote("${reply}"), i == 5 ? fakeReply : ""); return new JSONObject(postJSON); }