Skip to content

Commit

Permalink
✨ identify replies #23
Browse files Browse the repository at this point in the history
  • Loading branch information
McPringle committed Nov 30, 2024
1 parent 2edf571 commit 017c1d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>();
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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 = """
{
Expand All @@ -244,6 +252,7 @@ private JSONObject createPost(final int i) {
},
"record": {
"createdAt": "${createdAt}",
${reply}
"text": "Content for post #${i}"
},
"embed": {
Expand All @@ -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);
}
Expand Down

0 comments on commit 017c1d6

Please sign in to comment.