From 217a8423866ccbf54e3fd9269b104c23a3713f47 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 6 Oct 2018 22:17:13 +0300 Subject: fix Note deserialization --- .../src/main/java/com/juick/server/api/activity/Profile.java | 10 ++++++---- .../src/test/java/com/juick/server/tests/ServerTests.java | 7 +++++++ 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'juick-server') diff --git a/juick-server/src/main/java/com/juick/server/api/activity/Profile.java b/juick-server/src/main/java/com/juick/server/api/activity/Profile.java index 03f6b538..a8019341 100644 --- a/juick-server/src/main/java/com/juick/server/api/activity/Profile.java +++ b/juick-server/src/main/java/com/juick/server/api/activity/Profile.java @@ -278,16 +278,18 @@ public class Profile { } } if (activity instanceof Create) { - if (activity.getObject() instanceof Note) { - Note note = (Note) activity.getObject(); - String inReplyTo = note.getInReplyTo(); + if (activity.getObject() instanceof Map) { + Map note = (Map) activity.getObject(); + String inReplyTo = (String)note.get("inReplyTo"); if (StringUtils.isNotBlank(inReplyTo)) { if (inReplyTo.startsWith(baseUri)) { UriComponents uri = UriComponentsBuilder.fromUriString(inReplyTo).build(); String postId = uri.getPath().substring(uri.getPath().lastIndexOf('/') + 1).replace("-", "/"); User user = new User(); user.setUri(URI.create(activity.getActor())); - CommandResult result = commandsManager.processCommand(user, String.format("#%s %s", postId, note.getContent()), URI.create(note.getAttachment().getUrl())); + Map attachmentObj = (Map )((List) note.get("attachment")).get(0); + String attachment = attachmentObj != null ? (String)attachmentObj.get("url") : StringUtils.EMPTY; + CommandResult result = commandsManager.processCommand(user, String.format("#%s %s", postId, note.get("content")), URI.create(attachment)); logger.info(jsonMapper.writeValueAsString(result)); if (result.getNewMessage().isPresent()) { return new ResponseEntity<>(HttpStatus.OK); diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java index e3d7a380..c1132a99 100644 --- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java +++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java @@ -34,6 +34,7 @@ import com.juick.server.*; import com.juick.server.api.activity.model.Context; import com.juick.server.api.activity.model.Key; import com.juick.server.api.activity.model.Person; +import com.juick.server.api.activity.model.activities.Create; import com.juick.server.api.activity.model.activities.Follow; import com.juick.server.api.activity.model.activities.Undo; import com.juick.server.util.HttpUtils; @@ -1690,6 +1691,12 @@ public class ServerTests { String undoJsonStr = IOUtils.toString(URI.create("classpath:undo.json"), StandardCharsets.UTF_8); Undo undo = jsonMapper.readValue(undoJsonStr, Undo.class); String undoFollower = (String)((Map)undo.getObject()).get("object"); + String createJsonStr = IOUtils.toString(URI.create("classpath:create.json"), StandardCharsets.UTF_8); + Create create = jsonMapper.readValue(createJsonStr, Create.class); + Map note = (Map) create.getObject(); + Map attachmentObj = (Map )((List) note.get("attachment")).get(0); + String attachment = attachmentObj != null ? (String)attachmentObj.get("url") : StringUtils.EMPTY; + } @Test public void signingSpec() throws IOException { -- cgit v1.2.3